diff --git a/NucleicRemote/NucleicRemote/LiveActivityManager.swift b/NucleicRemote/NucleicRemote/LiveActivityManager.swift index ee99985..7831ce0 100644 --- a/NucleicRemote/NucleicRemote/LiveActivityManager.swift +++ b/NucleicRemote/NucleicRemote/LiveActivityManager.swift @@ -143,13 +143,31 @@ final class LiveActivityManager { tokenObservation = nil pendingState = nil lastState = nil - guard let activity else { return } + let tracked = activity self.activity = nil - onActivityEnded?(activity.id) // let the Macs stop pushing to this token + if let tracked { onActivityEnded?(tracked.id) } // let the Macs stop pushing to this token + // Dismiss the tracked Activity *and any strays*: ending only the one we track would leave an + // orphan (from a prior launch killed before `end()`) rendering a stale "needs attention" + // glance in the Dynamic Island after the work it described has finished. Clear them all so + // "everything idle" can't get stuck on screen. Task { - await activity.end( - ActivityContent(state: activity.content.state, staleDate: nil), - dismissalPolicy: .immediate) + for activity in Activity.activities { + await activity.end( + ActivityContent(state: activity.content.state, staleDate: nil), + dismissalPolicy: .immediate) + } + } + } + + /// Dismiss every live Activity except `keep` — collapses accidental duplicates down to one so + /// iOS can't render a stale orphan alongside the tracked glance. + private func endStrays(keeping keep: String) { + for stray in Activity.activities where stray.id != keep { + Task { + await stray.end( + ActivityContent(state: stray.content.state, staleDate: nil), + dismissalPolicy: .immediate) + } } }