import AVFoundation import Intents import SwiftUI import UIKit final class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio) MainActor.assumeIsolated { _ = AppGraph.shared } return true } /// Phone windows go to SwiftUI; CarPlay gets its own scene delegate. func application(_ application: UIApplication, configurationForConnecting session: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { if session.role == .carTemplateApplication { let c = UISceneConfiguration(name: "CarPlay", sessionRole: session.role) c.delegateClass = CarPlayScene.self return c } return UISceneConfiguration(name: "Phone", sessionRole: session.role) } /// Siri: "Play on Stemify". func application(_ application: UIApplication, handlerFor intent: INIntent) -> Any? { intent is INPlayMediaIntent ? PlayMediaHandler() : nil } } @main struct StemifyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var delegate @Environment(\.scenePhase) private var phase var body: some Scene { WindowGroup { RootView() } .onChange(of: phase) { _, p in AppActivity.setPhone(p != .background) guard p == .active else { return } AppGraph.shared.eq.refreshRoute() // Keep downloaded playlists in step with the server, like Plexamp. Task { await AppGraph.shared.downloads.refresh() } } } }