Control PC playback through interactive Live Activity intents
This commit is contained in:
@@ -32,18 +32,21 @@ final class LiveActivityManager: ObservableObject {
|
||||
duration: max(0, state.endSeconds - state.startSeconds), updatedAt: now, connected: true)
|
||||
}
|
||||
|
||||
func start(_ state: MediaState) {
|
||||
func start(_ state: MediaState, connection: Connection) {
|
||||
guard !running, state.hasSession, UIApplication.shared.applicationState == .active else { return }
|
||||
guard ActivityAuthorizationInfo().areActivitiesEnabled else {
|
||||
error = "Разрешите Live Activities в настройках MusicBridge на iPhone."
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Migrate existing pairing so an explicit lock-screen action can read it after first unlock.
|
||||
try KeychainStore.save(connection)
|
||||
let value = Self.content(state)
|
||||
let new = try Activity.request(attributes: MusicActivityAttributes(),
|
||||
content: ActivityContent(state: value, staleDate: Date().addingTimeInterval(15)),
|
||||
pushType: nil)
|
||||
activity = new
|
||||
UserDefaults.standard.set(connection.fingerprint, forKey: LiveActivityCommands.bindingKey + new.id)
|
||||
last = value
|
||||
running = true
|
||||
error = nil
|
||||
@@ -72,6 +75,7 @@ final class LiveActivityManager: ObservableObject {
|
||||
|
||||
func end() {
|
||||
guard let activity else { return }
|
||||
UserDefaults.standard.removeObject(forKey: LiveActivityCommands.bindingKey + activity.id)
|
||||
self.activity = nil
|
||||
running = false
|
||||
last = nil
|
||||
|
||||
Reference in New Issue
Block a user