Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

App: show a sidebar card when a newer Soju release is out (#82)

Mikek5cd954a24e22
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 7247059f277..5c190861ca3 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -20,5 +20,9 @@ jobs:
run: |
swiftc app/PurchaseLinks.swift tests/test_purchase_links.swift -o /tmp/soju-purchase-tests
/tmp/soju-purchase-tests
+ - name: Update check
+ run: |
+ swiftc app/UpdateCheck.swift tests/test_update_check.swift -o /tmp/soju-update-tests
+ /tmp/soju-update-tests
- name: Build and verify the native app
run: bash scripts/build-app.sh
diff --git a/app/Library.swift b/app/Library.swift
index 7a068539046..1aaf73cc710 100644
--- a/app/Library.swift
+++ b/app/Library.swift
@@ -311,6 +311,7 @@ struct LibraryView: View {
.font(.system(size: 11)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}.padding(13).frame(maxWidth: .infinity, alignment: .leading)
.background(green.opacity(0.07), in: RoundedRectangle(cornerRadius: 12))
+ UpdateCard(current: model.version)
SponsorCard()
HStack {
Text("v" + model.version).foregroundStyle(.secondary)
diff --git a/app/Update.swift b/app/Update.swift
new file mode 100644
index 00000000000..e78d7fa0e97
--- /dev/null
+++ b/app/Update.swift
@@ -0,0 +1,61 @@
+import SwiftUI
+
+/// Asks GitHub for the release list once per launch and remembers a newer version, if any.
+/// The request carries nothing about this Mac beyond what any download from GitHub does.
+@MainActor final class UpdateModel: ObservableObject {
+ @Published var available: String?
+ private var loaded = false
+
+ func load(current: String) {
+ guard !loaded else { return }
+ loaded = true
+ // SOJU_UPDATE_FILE points at a saved release list for checking the card without the network.
+ if let path = ProcessInfo.processInfo.environment["SOJU_UPDATE_FILE"],
+ let data = FileManager.default.contents(atPath: path) {
+ available = UpdateCheck.latest(from: data).flatMap { UpdateCheck.isNewer($0, than: current) ? $0 : nil }
+ return
+ }
+ var request = URLRequest(url: UpdateCheck.feed)
+ request.cachePolicy = .reloadIgnoringLocalCacheData
+ request.timeoutInterval = 15
+ request.setValue("application/vnd.github+json", forHTTPHeaderField: "Accept")
+ URLSession.shared.dataTask(with: request) { data, response, _ in
+ let latest = (response as? HTTPURLResponse)?.statusCode == 200 ? data.flatMap { UpdateCheck.latest(from: $0) } : nil
+ DispatchQueue.main.async {
+ self.available = latest.flatMap { UpdateCheck.isNewer($0, than: current) ? $0 : nil }
+ }
+ }.resume()
+ }
+}
+
+/// Sidebar card shown only when a newer release exists. It opens the release page; Soju does not replace itself.
+struct UpdateCard: View {
+ let current: String
+ @StateObject private var updates = UpdateModel()
+
+ var body: some View {
+ // An empty view never gets onAppear, so keep a zero-height placeholder until there is something to show.
+ VStack(spacing: 0) {
+ if let version = updates.available {
+ Link(destination: UpdateCheck.page(for: version)) {
+ VStack(alignment: .leading, spacing: 4) {
+ Label("Soju \(version) is out", systemImage: "arrow.down.circle.fill")
+ .font(.system(size: 12, weight: .semibold)).foregroundStyle(.primary)
+ Text("You have \(current). Open the download page.")
+ .font(.system(size: 11)).foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal, 13).padding(.vertical, 11)
+ .background(Color.green.opacity(0.16), in: RoundedRectangle(cornerRadius: 12))
+ .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color.green.opacity(0.45)))
+ }
+ .buttonStyle(.plain).help("Release notes and download for Soju \(version)")
+ .padding(.top, 10)
+ } else {
+ Color.clear.frame(height: 0)
+ }
+ }
+ .onAppear { updates.load(current: current) }
+ }
+}
diff --git a/app/UpdateCheck.swift b/app/UpdateCheck.swift
new file mode 100644
index 00000000000..c153e9ccd25
--- /dev/null
+++ b/app/UpdateCheck.swift
@@ -0,0 +1,39 @@
+import Foundation
+
+/// Finds the newest app release in GitHub's release list. scripts/update.sh applies the same rule:
+/// a vX.Y.Z tag that is not a prerelease and carries Soju-X.Y.Z-macos-arm64.zip.
+enum UpdateCheck {
+ static let feed = URL(string: "https://api.github.com/repos/BCD1210/soju/releases?per_page=30")!
+
+ static func numbers(_ version: String) -> [Int]? {
+ let parts = version.split(separator: ".", omittingEmptySubsequences: false).map { Int($0) }
+ guard parts.count == 3, !parts.contains(where: { $0 == nil || $0! < 0 }) else { return nil }
+ return parts.map { $0! }
+ }
+
+ /// False when either side is not three dotted numbers, so a dev build never shows the notice.
+ static func isNewer(_ candidate: String, than current: String) -> Bool {
+ guard let a = numbers(candidate), let b = numbers(current) else { return false }
+ return b.lexicographicallyPrecedes(a)
+ }
+
+ /// GitHub lists releases by creation date, not by version, so take the highest version.
+ static func latest(from data: Data) -> String? {
+ guard data.count <= 2 * 1024 * 1024,
+ let releases = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] else { return nil }
+ var best: String?
+ for release in releases {
+ guard let tag = release["tag_name"] as? String, tag.hasPrefix("v"),
+ release["prerelease"] as? Bool == false, release["draft"] as? Bool != true else { continue }
+ let version = String(tag.dropFirst())
+ guard numbers(version) != nil, let assets = release["assets"] as? [[String: Any]],
+ assets.contains(where: { $0["name"] as? String == "Soju-\(version)-macos-arm64.zip" }) else { continue }
+ if best == nil || isNewer(version, than: best!) { best = version }
+ }
+ return best
+ }
+
+ static func page(for version: String) -> URL {
+ URL(string: "https://github.com/BCD1210/soju/releases/tag/v" + version)!
+ }
+}
diff --git a/docs/privacy.html b/docs/privacy.html
index 65c8315cb43..64f912f4d96 100644
--- a/docs/privacy.html
+++ b/docs/privacy.html
@@ -26,7 +26,7 @@
<a href="sponsor.html">Advertise</a>
</div></nav>
<main id="main">
-<header class="hero"><h1>Privacy</h1><p class="lead">Soju is a Mac app made by Didim Labs. It keeps your game library on your Mac. This page lists everything that leaves it.</p></header><section id="signin" aria-labelledby="signin-title"><h2 id="signin-title">Signing in with Apple or Google</h2><ul><li>We ask Apple or Google only for your email address. We don&#x27;t ask for contacts, files or anything else.</li><li>We use that email once, to find games you bought from us through Polar, and hand the license keys back to your copy of Soju.</li><li>Our server keeps the result for at most 10 minutes, then deletes it. Soju keeps your email and keys on your Mac (keys in the macOS Keychain).</li><li>If you use Apple&#x27;s Hide My Email, we only see the relay address, so purchases made with your real email won&#x27;t be found.</li></ul></section><section id="purchases" aria-labelledby="purchases-title"><h2 id="purchases-title">Buying games</h2><p>Payments go through <a href="https://polar.sh/legal/privacy">Polar</a>, which acts as the seller of record and handles card details, receipts and taxes. We see your email, name, country and what you bought. We never see card numbers.</p></section><section id="app" aria-labelledby="app-title"><h2 id="app-title">What the Soju app sends</h2><ul><li>Soju downloads the store list and the sponsor card from didimlabs.com, and game files from Polar or GitHub.</li><li>Account connections you add (Steam, GOG and others) talk to those services directly from your Mac.</li><li>If you turn on TV &amp; iPad streaming, Soju installs Sunshine (open source, LizardByte) on your Mac. It streams only to devices you pair with a PIN on your own network, keeps its settings page on your Mac, and only contacts GitHub to check for new versions.</li><li>Soju has no analytics, ads tracking or crash reporting.</li></ul></section><section id="site" aria-labelledby="site-title"><h2 id="site-title">This website</h2><p>didimlabs.com runs on Cloudflare, which keeps standard request logs. The site sets no cookies. If you send the advertising form, we get what you type and reply by email.</p></section><section id="news" aria-labelledby="news-title"><h2 id="news-title">Release news emails</h2><p>If you type your email to hear about our next game, we keep that address only for that. We send an email when a new game comes out and nothing else. Write to [email protected] to be removed.</p></section><section id="contact" aria-labelledby="contact-title"><h2 id="contact-title">Questions or deletion</h2><p>Email <a href="mailto:[email protected]">[email protected]</a>. We can tell you what we hold and delete it, except records Polar must keep for tax law. To remove everything from your Mac, sign out in Soju and delete the app.</p></section><section id="ko" aria-labelledby="ko-title"><h2 id="ko-title">개인정보 처리 (요약)</h2><p>애플·구글 로그인은 이메일 주소만 받아, Polar에서 그 이메일로 산 게임의 라이선스 키를 찾는 데 한 번 씁니다. 서버에는 최대 10분만 남고 지워집니다. 결제 정보는 Polar가 처리하며 우리는 카드 번호를 보지 않습니다. 소주 앱에는 분석·추적 기능이 없습니다. 출시 알림을 신청한 이메일은 새 게임 소식에만 씁니다. 문의와 삭제 요청: [email protected]</p></section>
+<header class="hero"><h1>Privacy</h1><p class="lead">Soju is a Mac app made by Didim Labs. It keeps your game library on your Mac. This page lists everything that leaves it.</p></header><section id="signin" aria-labelledby="signin-title"><h2 id="signin-title">Signing in with Apple or Google</h2><ul><li>We ask Apple or Google only for your email address. We don&#x27;t ask for contacts, files or anything else.</li><li>We use that email once, to find games you bought from us through Polar, and hand the license keys back to your copy of Soju.</li><li>Our server keeps the result for at most 10 minutes, then deletes it. Soju keeps your email and keys on your Mac (keys in the macOS Keychain).</li><li>If you use Apple&#x27;s Hide My Email, we only see the relay address, so purchases made with your real email won&#x27;t be found.</li></ul></section><section id="purchases" aria-labelledby="purchases-title"><h2 id="purchases-title">Buying games</h2><p>Payments go through <a href="https://polar.sh/legal/privacy">Polar</a>, which acts as the seller of record and handles card details, receipts and taxes. We see your email, name, country and what you bought. We never see card numbers.</p></section><section id="app" aria-labelledby="app-title"><h2 id="app-title">What the Soju app sends</h2><ul><li>Soju downloads the store list and the sponsor card from didimlabs.com, and game files from Polar or GitHub.</li><li>When it opens, Soju asks GitHub for the list of Soju releases to tell you if a newer version is out. The request says nothing about you or your games.</li><li>Account connections you add (Steam, GOG and others) talk to those services directly from your Mac.</li><li>If you turn on TV &amp; iPad streaming, Soju installs Sunshine (open source, LizardByte) on your Mac. It streams only to devices you pair with a PIN on your own network, keeps its settings page on your Mac, and only contacts GitHub to check for new versions.</li><li>Soju has no analytics, ads tracking or crash reporting.</li></ul></section><section id="site" aria-labelledby="site-title"><h2 id="site-title">This website</h2><p>didimlabs.com runs on Cloudflare, which keeps standard request logs. The site sets no cookies. If you send the advertising form, we get what you type and reply by email.</p></section><section id="news" aria-labelledby="news-title"><h2 id="news-title">Release news emails</h2><p>If you type your email to hear about our next game, we keep that address only for that. We send an email when a new game comes out and nothing else. Write to [email protected] to be removed.</p></section><section id="contact" aria-labelledby="contact-title"><h2 id="contact-title">Questions or deletion</h2><p>Email <a href="mailto:[email protected]">[email protected]</a>. We can tell you what we hold and delete it, except records Polar must keep for tax law. To remove everything from your Mac, sign out in Soju and delete the app.</p></section><section id="ko" aria-labelledby="ko-title"><h2 id="ko-title">개인정보 처리 (요약)</h2><p>애플·구글 로그인은 이메일 주소만 받아, Polar에서 그 이메일로 산 게임의 라이선스 키를 찾는 데 한 번 씁니다. 서버에는 최대 10분만 남고 지워집니다. 결제 정보는 Polar가 처리하며 우리는 카드 번호를 보지 않습니다. 소주 앱에는 분석·추적 기능이 없습니다. 출시 알림을 신청한 이메일은 새 게임 소식에만 씁니다. 문의와 삭제 요청: [email protected]</p></section>
</main>
<footer><div class="inner">
<p><span>Didim Labs · <a href="mailto:[email protected]">[email protected]</a> · <a href="https://github.com/BCD1210/soju">GitHub</a></span></p>
diff --git a/scripts/build-app.sh b/scripts/build-app.sh
index 2ccffeffc21..a461854165a 100755
--- a/scripts/build-app.sh
+++ b/scripts/build-app.sh
@@ -10,7 +10,7 @@ trap 'rm -rf "$STAGE"' EXIT
APP="$STAGE/Soju.app"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources/soju"
swiftc -swift-version 5 -parse-as-library -O -target arm64-apple-macosx14.0 \
- "$ROOT/app/Soju.swift" "$ROOT/app/Library.swift" "$ROOT/app/Accounts.swift" "$ROOT/app/Discover.swift" "$ROOT/app/PurchaseLinks.swift" "$ROOT/app/SteamLogin.swift" "$ROOT/app/Store.swift" "$ROOT/app/Sponsor.swift" "$ROOT/app/Notify.swift" "$ROOT/app/TV.swift" -o "$APP/Contents/MacOS/Soju"
+ "$ROOT/app/Soju.swift" "$ROOT/app/Library.swift" "$ROOT/app/Accounts.swift" "$ROOT/app/Discover.swift" "$ROOT/app/PurchaseLinks.swift" "$ROOT/app/SteamLogin.swift" "$ROOT/app/Store.swift" "$ROOT/app/Sponsor.swift" "$ROOT/app/Notify.swift" "$ROOT/app/TV.swift" "$ROOT/app/UpdateCheck.swift" "$ROOT/app/Update.swift" -o "$APP/Contents/MacOS/Soju"
for dir in scripts tools patches third_party resources; do
ditto "$ROOT/$dir" "$APP/Contents/Resources/soju/$dir"
done
diff --git a/site/content/privacy.json b/site/content/privacy.json
index 94cc5463f9b..904763a98a4 100644
--- a/site/content/privacy.json
+++ b/site/content/privacy.json
@@ -78,6 +78,7 @@
"props": {
"items": [
"Soju downloads the store list and the sponsor card from didimlabs.com, and game files from Polar or GitHub.",
+ "When it opens, Soju asks GitHub for the list of Soju releases to tell you if a newer version is out. The request says nothing about you or your games.",
"Account connections you add (Steam, GOG and others) talk to those services directly from your Mac.",
"If you turn on TV & iPad streaming, Soju installs Sunshine (open source, LizardByte) on your Mac. It streams only to devices you pair with a PIN on your own network, keeps its settings page on your Mac, and only contacts GitHub to check for new versions.",
"Soju has no analytics, ads tracking or crash reporting."
diff --git a/tests/test_update_check.swift b/tests/test_update_check.swift
new file mode 100644
index 00000000000..33381bf329f
--- /dev/null
+++ b/tests/test_update_check.swift
@@ -0,0 +1,37 @@
+import Foundation
+
+@main struct UpdateCheckTests {
+ static func release(_ tag: String, zip: String?, prerelease: Bool = false, draft: Bool = false) -> [String: Any] {
+ ["tag_name": tag, "prerelease": prerelease, "draft": draft,
+ "assets": zip.map { [["name": $0], ["name": $0 + ".sha256"]] } ?? [[String: Any]]()]
+ }
+ static func main() throws {
+ assert(UpdateCheck.isNewer("1.10.12", than: "1.10.11"))
+ assert(UpdateCheck.isNewer("1.10.10", than: "1.9.9")) // numbers, not text
+ assert(UpdateCheck.isNewer("2.0.0", than: "1.99.99"))
+ assert(!UpdateCheck.isNewer("1.10.11", than: "1.10.11"))
+ assert(!UpdateCheck.isNewer("1.10.10", than: "1.10.11"))
+ assert(!UpdateCheck.isNewer("1.10.12", than: "dev")) // source builds never show the card
+ assert(!UpdateCheck.isNewer("1.10", than: "1.9.0"))
+ assert(!UpdateCheck.isNewer("1.10.x", than: "1.9.0"))
+
+ let list: [[String: Any]] = [
+ release("engine-v1.9", zip: "wine-engine-x86_64.tar.xz"), // not an app release
+ release("v1.10.11", zip: "Soju-1.10.11-macos-arm64.zip"),
+ release("v1.11.0", zip: "Soju-1.11.0-macos-arm64.zip", prerelease: true),
+ release("v1.10.12", zip: nil), // tagged, zip not uploaded yet
+ release("v1.10.9", zip: "Soju-1.10.9-macos-arm64.zip"),
+ release("v1.12.0", zip: "Soju-1.12.0-macos-arm64.zip", draft: true),
+ ]
+ let data = try JSONSerialization.data(withJSONObject: list)
+ assert(UpdateCheck.latest(from: data) == "1.10.11")
+ // Order in the feed does not matter.
+ let reversed = try JSONSerialization.data(withJSONObject: Array(list.reversed()))
+ assert(UpdateCheck.latest(from: reversed) == "1.10.11")
+ assert(UpdateCheck.latest(from: Data("not json".utf8)) == nil)
+ assert(UpdateCheck.latest(from: Data("{\"message\":\"rate limited\"}".utf8)) == nil)
+ assert(UpdateCheck.latest(from: Data("[]".utf8)) == nil)
+ assert(UpdateCheck.page(for: "1.10.12").absoluteString == "https://github.com/BCD1210/soju/releases/tag/v1.10.12")
+ print("update check: ok")
+ }
+}