mirror of
https://github.com/jellyfin/Swiftfin.git
synced 2024-12-04 20:26:44 +00:00
Set appearance on app launch
This commit is contained in:
parent
4bc06ef23c
commit
477d011201
@ -7,6 +7,7 @@
|
||||
|
||||
import SwiftUI
|
||||
import MessageUI
|
||||
import Defaults
|
||||
|
||||
// The notification we'll send when a shake gesture happens.
|
||||
extension UIDevice {
|
||||
@ -210,6 +211,7 @@ class EmailHelper: NSObject, MFMailComposeViewControllerDelegate {
|
||||
@main
|
||||
struct JellyfinPlayerApp: App {
|
||||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
@Default(.appAppearance) var appAppearance
|
||||
|
||||
let persistenceController = PersistenceController.shared
|
||||
|
||||
@ -217,6 +219,9 @@ struct JellyfinPlayerApp: App {
|
||||
WindowGroup {
|
||||
SplashView()
|
||||
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
||||
.onAppear(perform: {
|
||||
setupAppearance()
|
||||
})
|
||||
.withHostingWindow { window in
|
||||
window?.rootViewController = PreferenceUIHostingController(wrappedView: SplashView().environment(\.managedObjectContext, persistenceController.container.viewContext))
|
||||
}
|
||||
@ -225,6 +230,11 @@ struct JellyfinPlayerApp: App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func setupAppearance() {
|
||||
guard let storedAppearance = AppAppearance(rawValue: appAppearance) else { return }
|
||||
UIApplication.shared.windows.first?.overrideUserInterfaceStyle = storedAppearance.style
|
||||
}
|
||||
}
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
|
@ -67,9 +67,8 @@ struct SettingsView: View {
|
||||
Text(appearance.localizedName).tag(appearance.rawValue)
|
||||
}
|
||||
}.onChange(of: appAppearance, perform: { value in
|
||||
guard let window = UIApplication.shared.windows.first else { return }
|
||||
guard let appearance = AppAppearance(rawValue: value) else { return }
|
||||
window.overrideUserInterfaceStyle = appearance.style
|
||||
UIApplication.shared.windows.first?.overrideUserInterfaceStyle = appearance.style
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user