47 lines
2.3 KiB
Swift
47 lines
2.3 KiB
Swift
import ActivityKit
|
|
import SwiftUI
|
|
import WidgetKit
|
|
|
|
@main
|
|
struct MusicBridgeWidgets: WidgetBundle {
|
|
var body: some Widget { MusicBridgeLiveActivity() }
|
|
}
|
|
|
|
struct MusicBridgeLiveActivity: Widget {
|
|
var body: some WidgetConfiguration {
|
|
ActivityConfiguration(for: MusicActivityAttributes.self) { context in
|
|
MusicActivityCard(state: context.state, stale: context.isStale)
|
|
.activityBackgroundTint(Color(.secondarySystemBackground))
|
|
.activitySystemActionForegroundColor(.indigo)
|
|
.widgetURL(URL(string: "musicbridge://player"))
|
|
} dynamicIsland: { context in
|
|
DynamicIsland {
|
|
DynamicIslandExpandedRegion(.leading) {
|
|
Image(systemName: "waveform").foregroundStyle(.cyan).padding(.leading, 4)
|
|
}
|
|
DynamicIslandExpandedRegion(.trailing) {
|
|
Image(systemName: context.isStale || !context.state.connected ? "arrow.clockwise" : context.state.playing ? "play.fill" : "pause.fill")
|
|
}
|
|
DynamicIslandExpandedRegion(.bottom) {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
TrackLabels(state: context.state)
|
|
ProgressView(value: context.state.progress).tint(.cyan)
|
|
ActivityStatus(state: context.state, stale: context.isStale)
|
|
Link("Открыть плеер", destination: URL(string: "musicbridge://player")!)
|
|
.font(.caption.weight(.semibold)).foregroundStyle(.cyan)
|
|
}.padding(.bottom, 4)
|
|
}
|
|
} compactLeading: {
|
|
Image(systemName: "waveform").foregroundStyle(.cyan)
|
|
} compactTrailing: {
|
|
Image(systemName: context.isStale || !context.state.connected ? "arrow.clockwise" : context.state.playing ? "play.fill" : "pause.fill")
|
|
.accessibilityLabel(context.isStale || !context.state.connected ? "Откройте MusicBridge для обновления" : "Музыка на ПК")
|
|
} minimal: {
|
|
Image(systemName: context.isStale || !context.state.connected ? "arrow.clockwise" : "waveform").foregroundStyle(.cyan)
|
|
}
|
|
.widgetURL(URL(string: "musicbridge://player"))
|
|
.keylineTint(.cyan)
|
|
}
|
|
}
|
|
}
|