| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import AppIntents
- import Foundation
- enum RecordingLiveActivityCommand: String, Sendable {
- case togglePause
- case stop
- }
- extension Notification.Name {
- static let recordingLiveActivityCommand = Notification.Name(
- "com.celestia.trace.recording-live-activity-command"
- )
- }
- private enum RecordingLiveActivityIntentDispatcher {
- @MainActor
- static func post(_ command: RecordingLiveActivityCommand, sessionID: String) {
- NotificationCenter.default.post(
- name: .recordingLiveActivityCommand,
- object: nil,
- userInfo: [
- "sessionID": sessionID,
- "command": command.rawValue
- ]
- )
- }
- }
- struct TogglePauseRecordingIntent: LiveActivityIntent {
- static var title: LocalizedStringResource = "暂停或继续录音"
- static var description = IntentDescription("在锁屏或灵动岛上静默切换当前录音的暂停状态。")
- static var openAppWhenRun = false
- @Parameter(title: "记录 ID")
- var sessionID: String
- init() {}
- init(sessionID: UUID) {
- self.sessionID = sessionID.uuidString
- }
- func perform() async throws -> some IntentResult {
- await RecordingLiveActivityIntentDispatcher.post(
- .togglePause,
- sessionID: sessionID
- )
- return .result()
- }
- }
- struct StopRecordingIntent: LiveActivityIntent {
- static var title: LocalizedStringResource = "结束录音"
- static var description = IntentDescription("在锁屏或灵动岛上静默结束当前录音。")
- static var openAppWhenRun = false
- @Parameter(title: "记录 ID")
- var sessionID: String
- init() {}
- init(sessionID: UUID) {
- self.sessionID = sessionID.uuidString
- }
- func perform() async throws -> some IntentResult {
- await RecordingLiveActivityIntentDispatcher.post(
- .stop,
- sessionID: sessionID
- )
- return .result()
- }
- }
|