Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

test(ios): cover turning the old push switch into each computer's switch

leepokaid1698a7c68fe
diff --git a/apps/ios/App/CodyncApp.swift b/apps/ios/App/CodyncApp.swift
index c3450996..fcb656eb 100644
--- a/apps/ios/App/CodyncApp.swift
+++ b/apps/ios/App/CodyncApp.swift
@@ -143,7 +143,9 @@ final class AppStore {
}
CrashReports.shared.start()
contextID = storage.id
- Self.splitPushSwitch(contexts: [nil, storage.accountID] + session.accounts.map(\.id))
+ // Accounts Clerk hasn't restored by launch keep their computers' push on.
+ SharedStore.Context.splitPushSwitch(from: .standard,
+ into: Set([nil, storage.accountID] + session.accounts.map(\.id)).map { SharedStore.Context(accountID: $0) })
(accounts, cloud) = Self.makeAccounts(storage, session: session)
}
@@ -332,18 +334,6 @@ final class AppStore {
if let store = accounts.store(for: id) { PushRegistrar.shared.syncDevice(with: store) }
Analytics.shared.capture(.settingChanged(.push, on: on))
}
-
- /// 2.28.0 had one push switch for every computer; switched off, it becomes each saved computer's own switch.
- /// Accounts Clerk hasn't restored by launch keep theirs on.
- private static func splitPushSwitch(contexts ids: [String?]) {
- let key = "notificationsEnabled"
- defer { UserDefaults.standard.removeObject(forKey: key) }
- guard UserDefaults.standard.object(forKey: key) as? Bool == false else { return }
- for id in Set(ids) {
- let context = SharedStore.Context(accountID: id)
- context.computers = context.computers.map { var computer = $0; computer.notifications = false; return computer }
- }
- }
}
final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
diff --git a/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift b/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
index 4e465b07..fd32cb4f 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
+++ b/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
@@ -123,4 +123,15 @@ public extension SharedStore.Context {
for report in usage.values { for provider in report.providers { names[provider.id] = provider.name } }
return names.map { (id: $0.key, name: $0.value) }.sorted { $0.name < $1.name }
}
+
+ /// 2.28.0 kept one push switch for every computer (`notificationsEnabled` in `defaults`). Switched off, it
+ /// becomes the switch of every computer saved in `contexts`; the old key goes either way, so this runs once.
+ static func splitPushSwitch(from defaults: UserDefaults, into contexts: [Self]) {
+ let key = "notificationsEnabled"
+ defer { defaults.removeObject(forKey: key) }
+ guard defaults.object(forKey: key) as? Bool == false else { return }
+ for context in contexts {
+ context.computers = context.computers.map { var computer = $0; computer.notifications = false; return computer }
+ }
+ }
}
diff --git a/apps/ios/Kit/Tests/CodyncKitTests/PushSwitchUpgradeTests.swift b/apps/ios/Kit/Tests/CodyncKitTests/PushSwitchUpgradeTests.swift
new file mode 100644
index 00000000..5aeeca6a
--- /dev/null
+++ b/apps/ios/Kit/Tests/CodyncKitTests/PushSwitchUpgradeTests.swift
@@ -0,0 +1,44 @@
+import Foundation
+import Testing
+@testable import CodyncKit
+
+/// 2.28.0's one push switch becomes each saved computer's own switch, once.
+struct PushSwitchUpgradeTests {
+ private let suite = "CodyncKitTests.\(UUID().uuidString)"
+ private var defaults: UserDefaults { UserDefaults(suiteName: suite)! }
+
+ private func context(_ accountID: String?) -> SharedStore.Context {
+ let context = SharedStore.Context(accountID: accountID, suite: suite)
+ context.computers = [Computer(id: "\(accountID ?? "local")-desk", name: "Desk", signKey: "key")]
+ return context
+ }
+
+ @Test func anOldSwitchTurnedOffTurnsOffEveryComputerAndIsRemoved() {
+ defer { defaults.removePersistentDomain(forName: suite) }
+ let contexts = [context(nil), context("user_a")]
+ defaults.set(false, forKey: "notificationsEnabled")
+ SharedStore.Context.splitPushSwitch(from: defaults, into: contexts)
+ #expect(contexts.allSatisfy { $0.computers.allSatisfy { $0.notifications == false } })
+ #expect(defaults.object(forKey: "notificationsEnabled") == nil)
+ }
+
+ @Test func anOldSwitchLeftOnOrNeverSetChangesNothing() {
+ defer { defaults.removePersistentDomain(forName: suite) }
+ let contexts = [context(nil)]
+ defaults.set(true, forKey: "notificationsEnabled")
+ SharedStore.Context.splitPushSwitch(from: defaults, into: contexts)
+ SharedStore.Context.splitPushSwitch(from: defaults, into: contexts)
+ #expect(contexts[0].computers.first?.notifications == nil)
+ #expect(defaults.object(forKey: "notificationsEnabled") == nil)
+ }
+
+ @Test func aLaterLaunchKeepsWhatThePhoneChoseSince() {
+ defer { defaults.removePersistentDomain(forName: suite) }
+ let contexts = [context(nil)]
+ defaults.set(false, forKey: "notificationsEnabled")
+ SharedStore.Context.splitPushSwitch(from: defaults, into: contexts)
+ contexts[0].computers = contexts[0].computers.map { var computer = $0; computer.notifications = nil; return computer }
+ SharedStore.Context.splitPushSwitch(from: defaults, into: contexts)
+ #expect(contexts[0].computers.first?.notifications == nil)
+ }
+}