39 lines
2.0 KiB
Swift
39 lines
2.0 KiB
Swift
import SwiftUI
|
|
|
|
@main
|
|
struct MusicBridgeApp: App {
|
|
@StateObject private var store = PreviewSupport.makeStore()
|
|
@StateObject private var liveActivity = LiveActivityManager()
|
|
@StateObject private var systemPlayer = SystemPlayerManager()
|
|
@Environment(\.scenePhase) private var phase
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
Group {
|
|
if PreviewSupport.liveCard, let state = store.state {
|
|
ScrollView {
|
|
VStack(spacing: 24) {
|
|
Text("Live Activity · предпросмотр").font(.headline)
|
|
MusicActivityCard(state: LiveActivityManager.content(state), stale: false)
|
|
.background(Color(.secondarySystemBackground), in: RoundedRectangle(cornerRadius: 24))
|
|
MusicActivityCard(state: LiveActivityManager.content(state), stale: true)
|
|
.background(Color(.secondarySystemBackground), in: RoundedRectangle(cornerRadius: 24))
|
|
}.padding()
|
|
}
|
|
} else {
|
|
ContentView(store: store, liveActivity: liveActivity, systemPlayer: systemPlayer)
|
|
}
|
|
}
|
|
.dynamicTypeSize(PreviewSupport.largeText ? DynamicTypeSize.accessibility2...DynamicTypeSize.accessibility2 : DynamicTypeSize.xSmall...DynamicTypeSize.accessibility5)
|
|
.onOpenURL { if $0.absoluteString != "musicbridge://player" { store.importInvitation($0.absoluteString) } }
|
|
.task {
|
|
store.liveActivity = liveActivity
|
|
store.systemPlayer = systemPlayer
|
|
if !PreviewSupport.enabled { await systemPlayer.restore(connection: store.connection) }
|
|
if !PreviewSupport.enabled { store.setActive(phase == .active) }
|
|
}
|
|
.onChange(of: phase) { _, value in if !PreviewSupport.enabled { store.setActive(value == .active) } }
|
|
}
|
|
}
|
|
}
|