mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
- Carry the last-seen watermark into the App Group widget snapshot as isUnread; the app refreshes the widget when read state changes. - Mark push-updated sessions unread in the NSE snapshot path. - Show a blue dot and blue timestamp for unread widget rows. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
import HapiClient
|
|
import HapiProtocol
|
|
|
|
/// Cross-platform seam for the home-screen widget snapshot writer. The real
|
|
/// writer is iOS-only (WidgetKit); Catalyst gets a no-op.
|
|
@MainActor
|
|
protocol WidgetSnapshotControlling: AnyObject {
|
|
func update(_ sessions: [SessionSummary], unreadSessionIds: Set<String>, hubUrl: String)
|
|
func flush()
|
|
/// Background tasks must wait for the App Group write before they report
|
|
/// completion; iOS may suspend the process immediately afterwards.
|
|
func flushAndWait() async
|
|
func clear()
|
|
}
|
|
|
|
@MainActor
|
|
final class NoopWidgetSnapshotController: WidgetSnapshotControlling {
|
|
func update(_ sessions: [SessionSummary], unreadSessionIds: Set<String>, hubUrl: String) {}
|
|
func flush() {}
|
|
func flushAndWait() async {}
|
|
func clear() {}
|
|
}
|
|
|
|
enum WidgetSnapshotControllerFactory {
|
|
@MainActor
|
|
static func make() -> any WidgetSnapshotControlling {
|
|
#if os(iOS) && !targetEnvironment(macCatalyst)
|
|
return WidgetSnapshotUpdater()
|
|
#else
|
|
return NoopWidgetSnapshotController()
|
|
#endif
|
|
}
|
|
}
|