From b128256cd39ea17adcfb0fbc0cc79a2b65d25244 Mon Sep 17 00:00:00 2001 From: Andrew Blakeslee Moore Date: Mon, 6 Jul 2026 12:40:34 -0700 Subject: [PATCH] iOS Live Activity Updates Nucleic-Session: 665980BA-E8A5-4E84-9DF4-1757CF792353 Co-authored-by: Nucleic --- .../NucleicRemote/LiveActivityManager.swift | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) 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) + } } }