|
|
@@ -1,4 +1,5 @@
|
|
|
import ActivityKit
|
|
|
+import AppIntents
|
|
|
import SwiftUI
|
|
|
import WidgetKit
|
|
|
|
|
|
@@ -31,15 +32,19 @@ struct RecordingLiveActivityWidget: Widget {
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
|
|
HStack(spacing: 8) {
|
|
|
- islandAction(
|
|
|
+ islandIntentAction(
|
|
|
label: context.state.isPaused ? "继续" : "暂停",
|
|
|
systemImage: context.state.isPaused ? "play.fill" : "pause.fill",
|
|
|
- url: actionURL("toggle-pause", context.attributes)
|
|
|
+ intent: TogglePauseRecordingIntent(
|
|
|
+ sessionID: context.attributes.sessionID
|
|
|
+ )
|
|
|
)
|
|
|
- islandAction(
|
|
|
+ islandIntentAction(
|
|
|
label: "结束",
|
|
|
systemImage: "stop.fill",
|
|
|
- url: actionURL("stop", context.attributes),
|
|
|
+ intent: StopRecordingIntent(
|
|
|
+ sessionID: context.attributes.sessionID
|
|
|
+ ),
|
|
|
tint: .red
|
|
|
)
|
|
|
islandAction(
|
|
|
@@ -101,15 +106,19 @@ struct RecordingLiveActivityWidget: Widget {
|
|
|
|
|
|
VStack(spacing: 8) {
|
|
|
HStack(spacing: 10) {
|
|
|
- quickAction(
|
|
|
+ quickIntentAction(
|
|
|
title: context.state.isPaused ? "继续" : "暂停",
|
|
|
systemImage: context.state.isPaused ? "play.fill" : "pause.fill",
|
|
|
- url: actionURL("toggle-pause", context.attributes)
|
|
|
+ intent: TogglePauseRecordingIntent(
|
|
|
+ sessionID: context.attributes.sessionID
|
|
|
+ )
|
|
|
)
|
|
|
- quickAction(
|
|
|
+ quickIntentAction(
|
|
|
title: "结束",
|
|
|
systemImage: "stop.fill",
|
|
|
- url: actionURL("stop", context.attributes),
|
|
|
+ intent: StopRecordingIntent(
|
|
|
+ sessionID: context.attributes.sessionID
|
|
|
+ ),
|
|
|
tint: .red
|
|
|
)
|
|
|
}
|
|
|
@@ -162,6 +171,23 @@ struct RecordingLiveActivityWidget: Widget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func quickIntentAction<Intent: AppIntent>(
|
|
|
+ title: String,
|
|
|
+ systemImage: String,
|
|
|
+ intent: Intent,
|
|
|
+ tint: Color = .white
|
|
|
+ ) -> some View {
|
|
|
+ Button(intent: intent) {
|
|
|
+ Label(title, systemImage: systemImage)
|
|
|
+ .font(.caption.weight(.semibold))
|
|
|
+ .foregroundStyle(tint)
|
|
|
+ .frame(maxWidth: .infinity)
|
|
|
+ .padding(.vertical, 8)
|
|
|
+ .background(.white.opacity(0.12), in: RoundedRectangle(cornerRadius: 8))
|
|
|
+ }
|
|
|
+ .buttonStyle(.plain)
|
|
|
+ }
|
|
|
+
|
|
|
private func islandAction(
|
|
|
label: String,
|
|
|
systemImage: String,
|
|
|
@@ -179,6 +205,24 @@ struct RecordingLiveActivityWidget: Widget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func islandIntentAction<Intent: AppIntent>(
|
|
|
+ label: String,
|
|
|
+ systemImage: String,
|
|
|
+ intent: Intent,
|
|
|
+ tint: Color = .white
|
|
|
+ ) -> some View {
|
|
|
+ Button(intent: intent) {
|
|
|
+ Image(systemName: systemImage)
|
|
|
+ .font(.caption.weight(.semibold))
|
|
|
+ .foregroundStyle(tint)
|
|
|
+ .frame(maxWidth: .infinity)
|
|
|
+ .padding(.vertical, 7)
|
|
|
+ .background(.white.opacity(0.12), in: RoundedRectangle(cornerRadius: 7))
|
|
|
+ .accessibilityLabel(label)
|
|
|
+ }
|
|
|
+ .buttonStyle(.plain)
|
|
|
+ }
|
|
|
+
|
|
|
private func recordingURL(_ attributes: RecordingActivityAttributes) -> URL {
|
|
|
URL(string: "celestiatrace://recording/\(attributes.sessionID.uuidString)")!
|
|
|
}
|