55 lines
2.2 KiB
Swift
55 lines
2.2 KiB
Swift
import UIKit
|
|
import SwiftUI
|
|
import Combine
|
|
|
|
// MARK: - Scene Delegate
|
|
// Takes ownership of window creation so we can use NavidromeHostingController.
|
|
// When AppDelegate.application(_:configurationForConnecting:options:) returns a
|
|
// UISceneConfiguration with delegateClass = NavidromeSceneDelegate.self, SwiftUI's
|
|
// default window-bridging delegate is replaced — our delegate creates the window.
|
|
// WindowGroup in App.body becomes a scene declaration that's never bridged to a
|
|
// UIWindow, which is harmless.
|
|
|
|
final class NavidromeSceneDelegate: NSObject, UIWindowSceneDelegate {
|
|
var window: UIWindow?
|
|
private var cancellable: AnyCancellable?
|
|
|
|
func scene(_ scene: UIScene,
|
|
willConnectTo session: UISceneSession,
|
|
options connectionOptions: UIScene.ConnectionOptions) {
|
|
guard let windowScene = scene as? UIWindowScene else { return }
|
|
|
|
let rootContent = AnyView(
|
|
RootView()
|
|
.environmentObject(ServerManager.shared)
|
|
.environmentObject(AudioPlayer.shared)
|
|
.environmentObject(OfflineManager.shared)
|
|
.tint(Color(red: 1.0, green: 0.176, blue: 0.333))
|
|
)
|
|
|
|
let hostingController = NavidromeHostingController(rootView: rootContent)
|
|
|
|
let window = UIWindow(windowScene: windowScene)
|
|
window.rootViewController = hostingController
|
|
window.makeKeyAndVisible()
|
|
self.window = window
|
|
|
|
// Re-trigger status bar appearance whenever album brightness changes
|
|
cancellable = AlbumColorExtractor.shared.$preferredStatusBarStyle
|
|
.receive(on: DispatchQueue.main)
|
|
.sink { [weak hostingController] _ in
|
|
hostingController?.setNeedsStatusBarAppearanceUpdate()
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Custom Hosting Controller
|
|
// Overrides preferredStatusBarStyle independently of the SwiftUI colorScheme.
|
|
// NowPlayingView keeps .preferredColorScheme(.dark) so all SwiftUI views stay
|
|
// visually dark. This override controls ONLY the status bar icon colour.
|
|
|
|
final class NavidromeHostingController: UIHostingController<AnyView> {
|
|
override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
AlbumColorExtractor.shared.preferredStatusBarStyle
|
|
}
|
|
}
|