commit 60341428a21b266c074bb5753bdc16234961387e
parent 4fcc40cc30b3e6f30eef6db55fb24752c2fe5a6c
Author: Michael Camilleri <[email protected]>
Date: Mon, 4 May 2026 08:54:43 +0900
Tweak behaviour regarding shared games
Diffstat:
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/Crossmate/CrossmateApp.swift b/Crossmate/CrossmateApp.swift
@@ -307,19 +307,32 @@ private struct PuzzleDisplayView: View {
.navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
.task(id: sharedID) {
- guard let session, sharedID != nil, preferences.isICloudSyncEnabled else { return }
- await activateSharing(for: session)
+ guard sharedID != nil else { return }
await pollOpenSharedPuzzle()
}
.task(id: gameID) {
NotificationState.setActivePuzzleID(gameID)
do {
let (game, mutator) = try store.loadGame(id: gameID)
- session = PlayerSession(game: game, mutator: mutator)
+ let newSession = PlayerSession(game: game, mutator: mutator)
+ session = newSession
+ if mutator.isShared && preferences.isICloudSyncEnabled {
+ await activateSharing(for: newSession)
+ }
} catch {
loadError = String(describing: error)
}
}
+ .onChange(of: session?.mutator.isShared) { oldValue, newValue in
+ // Fire only on a definite `false → true` transition — that's the
+ // mid-session share-create case. Initial loads of an already-shared
+ // game go `nil → true` and are handled inline in `task(id: gameID)`.
+ guard oldValue == false, newValue == true,
+ let session,
+ preferences.isICloudSyncEnabled
+ else { return }
+ Task { await activateSharing(for: session) }
+ }
.onDisappear {
NotificationState.setActivePuzzleID(nil)
let presence = services.presencePublisher