Control PC playback through interactive Live Activity intents
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import AppIntents
|
||||
|
||||
enum MusicRemoteAction: String, AppEnum {
|
||||
case previous, toggle, next, refresh
|
||||
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Команда плеера"
|
||||
static var caseDisplayRepresentations: [Self: DisplayRepresentation] = [
|
||||
.previous: "Предыдущий трек", .toggle: "Воспроизведение / пауза", .next: "Следующий трек", .refresh: "Обновить"
|
||||
]
|
||||
}
|
||||
|
||||
struct MusicControlIntent: LiveActivityIntent {
|
||||
static var title: LocalizedStringResource = "Управлять музыкой на ПК"
|
||||
static var openAppWhenRun: Bool = false
|
||||
static var isDiscoverable: Bool = false
|
||||
static var authenticationPolicy: IntentAuthenticationPolicy = .alwaysAllowed
|
||||
@Parameter(title: "Команда") var action: MusicRemoteAction
|
||||
@Parameter(title: "Активность") var activityID: String
|
||||
|
||||
init() {}
|
||||
init(_ action: MusicRemoteAction, activityID: String) { self.action = action; self.activityID = activityID }
|
||||
|
||||
func perform() async throws -> some IntentResult {
|
||||
#if !MUSICBRIDGE_WIDGET
|
||||
await LiveActivityCommands.perform(action, activityID: activityID)
|
||||
#endif
|
||||
return .result()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user