Files
hapi/ios/Hapi/Features/LiveActivity/LiveActivityControlling.swift
T
b81c6be39b feat(ios): add lock-screen Live Activities for running sessions
Hub:
- add encrypted Live Activity token registry, registration API, and
  update/end pushes over direct APNs
- enable only for HAPI_IOS_PUSH=apns; relay reports remote:false
- keep content-state encrypted with the per-install push key and a
  domain-separated AAD

iOS:
- add ActivityKit coordinator, HapiWidgets extension, lock-screen and
  Dynamic Island UI, encrypted content-state, deep links, and settings toggle
- cap concurrent activities and reconcile across hub switches

Docs/tests:
- native contract, privacy, READMEs, localization catalogs
- cross-language cipher fixture and hub/iOS unit tests

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-06 19:18:09 +08:00

51 lines
1.6 KiB
Swift

import HapiClient
import HapiProtocol
/// The app-side seam for Live Activities. Declared unconditionally so
/// `AppModel` builds on Mac Catalyst too; the real coordinator is compiled
/// only for iOS (ActivityKit is unavailable on Catalyst).
@MainActor
protocol LiveActivityControlling: AnyObject {
var prefs: LiveActivityPrefs { get }
/// The active hub changed (initial build, switch). `detach()` must run
/// before the old hub is shut down so its activities can end and their
/// tokens can be unregistered while the API still works.
func attach(to hub: HubSession)
func detach()
func sessionsChanged(_ sessions: [SessionSummary])
func setEnabled(_ enabled: Bool)
func appDidBecomeActive()
func appDidBackground()
}
/// Catalyst / non-iOS placeholder. It still carries the shared prefs so the
/// Settings toggle behaves consistently.
@MainActor
final class NoopLiveActivityController: LiveActivityControlling {
let prefs: LiveActivityPrefs
init(prefs: LiveActivityPrefs) {
self.prefs = prefs
}
func attach(to hub: HubSession) {}
func detach() {}
func sessionsChanged(_ sessions: [SessionSummary]) {}
func setEnabled(_ enabled: Bool) { prefs.setEnabled(enabled) }
func appDidBecomeActive() {}
func appDidBackground() {}
}
enum LiveActivityControllerFactory {
@MainActor
static func make(prefs: LiveActivityPrefs) -> any LiveActivityControlling {
#if os(iOS) && !targetEnvironment(macCatalyst)
return LiveActivityCoordinator(prefs: prefs)
#else
return NoopLiveActivityController(prefs: prefs)
#endif
}
}