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.

refactor: consolidate init into AppDelegate, add PrimarySessionManager

libokai7681310f1dda
diff --git a/Codync-iOS/App/AppDelegate.swift b/Codync-iOS/App/AppDelegate.swift
index e42b10d4..a2f2dfea 100644
--- a/Codync-iOS/App/AppDelegate.swift
+++ b/Codync-iOS/App/AppDelegate.swift
@@ -6,17 +6,27 @@ import os
private let logger = Logger(subsystem: "com.pokai.Codync.ios", category: "AppDelegate")
final class AppDelegate: NSObject, UIApplicationDelegate {
- // AppDelegate OWNS these objects so they exist before any push can arrive.
- // Previously they were weak refs assigned from .task{}, creating a race condition
- // where push could arrive before wiring completed.
let receiver = CloudKitReceiver()
let liveActivityManager = LiveActivityManager()
+ let primarySessionManager = PrimarySessionManager()
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
application.registerForRemoteNotifications()
+ Task {
+ async let startReceiver: () = receiver.start()
+ async let loadPins: () = liveActivityManager.loadPinnedSessions()
+ async let loadPrimary: () = primarySessionManager.load()
+ _ = await (startReceiver, loadPins, loadPrimary)
+
+ liveActivityManager.updateSessions(receiver.sessions)
+ primarySessionManager.autoSelect(from: receiver.sessions)
+
+ let center = UNUserNotificationCenter.current()
+ try? await center.requestAuthorization(options: [.alert, .sound, .badge])
+ }
return true
}
@@ -52,6 +62,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
let statuses = receiver.sessions.map { "\($0.projectName):\($0.status.rawValue)" }.joined(separator: ", ")
logger.info("[\(ts)] → \(statuses)")
liveActivityManager.updateSessions(receiver.sessions)
+ primarySessionManager.autoSelect(from: receiver.sessions)
return .newData
}
}
diff --git a/Codync-iOS/App/CodyncIOSApp.swift b/Codync-iOS/App/CodyncIOSApp.swift
index f9ac2ebf..5b59e2e9 100644
--- a/Codync-iOS/App/CodyncIOSApp.swift
+++ b/Codync-iOS/App/CodyncIOSApp.swift
@@ -4,21 +4,24 @@ import CodyncShared
@main
struct CodyncIOSApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
+ @Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
- // AppDelegate owns receiver & liveActivityManager — no race condition
- IOSRootView(receiver: appDelegate.receiver, liveActivityManager: appDelegate.liveActivityManager)
- .task {
- await appDelegate.receiver.start()
- }
- .task {
- let center = UNUserNotificationCenter.current()
- try? await center.requestAuthorization(options: [.alert, .sound, .badge])
- }
- .task {
- await appDelegate.liveActivityManager.loadPinnedSessions()
+ IOSRootView(
+ receiver: appDelegate.receiver,
+ liveActivityManager: appDelegate.liveActivityManager,
+ primarySessionManager: appDelegate.primarySessionManager
+ )
+ }
+ .onChange(of: scenePhase) { _, phase in
+ if phase == .active {
+ Task {
+ await appDelegate.receiver.fetch(source: "foreground-return")
+ appDelegate.liveActivityManager.updateSessions(appDelegate.receiver.sessions)
+ appDelegate.primarySessionManager.autoSelect(from: appDelegate.receiver.sessions)
}
+ }
}
}
}