2020-08-11 18:06:10 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2023-10-23 21:15:41 +00:00
|
|
|
enum Appearance: Int {
|
|
|
|
case system = 0
|
|
|
|
case light = 1
|
|
|
|
case dark = 2
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:06:10 +00:00
|
|
|
class PreferencesModel: ObservableObject {
|
2021-11-05 18:18:36 +00:00
|
|
|
private let defaults = UserDefaults.shared
|
2020-08-24 14:11:58 +00:00
|
|
|
|
2023-10-23 21:15:41 +00:00
|
|
|
@Published var selectedColorScheme: ColorScheme?
|
|
|
|
@Published var appearance: Int = 0
|
|
|
|
@Published var font: Int = 0 {
|
|
|
|
didSet {
|
|
|
|
defaults.set(font, forKey: WFDefaults.defaultFontIntegerKey)
|
2020-08-13 18:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-19 20:41:54 +00:00
|
|
|
|
|
|
|
@available(iOSApplicationExtension, unavailable)
|
2023-10-23 21:15:41 +00:00
|
|
|
func updateAppearance(to appearance: Appearance) {
|
|
|
|
#if os(iOS)
|
|
|
|
var window: UIWindow? {
|
|
|
|
guard let scene = UIApplication.shared.connectedScenes.first,
|
|
|
|
let windowSceneDelegate = scene.delegate as? UIWindowSceneDelegate,
|
|
|
|
let window = windowSceneDelegate.window else {
|
|
|
|
return nil
|
2020-08-11 18:06:10 +00:00
|
|
|
}
|
2023-10-23 21:15:41 +00:00
|
|
|
return window
|
2020-08-11 18:06:10 +00:00
|
|
|
}
|
2023-10-23 21:15:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch appearance {
|
|
|
|
case .light:
|
|
|
|
#if os(macOS)
|
|
|
|
NSApp.appearance = NSAppearance(named: .aqua)
|
|
|
|
#else
|
|
|
|
window?.overrideUserInterfaceStyle = .light
|
|
|
|
#endif
|
|
|
|
case .dark:
|
|
|
|
#if os(macOS)
|
|
|
|
NSApp.appearance = NSAppearance(named: .darkAqua)
|
|
|
|
#else
|
|
|
|
window?.overrideUserInterfaceStyle = .dark
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
#if os(macOS)
|
|
|
|
NSApp.appearance = nil
|
|
|
|
#else
|
|
|
|
window?.overrideUserInterfaceStyle = .unspecified
|
|
|
|
#endif
|
2020-09-18 15:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-11 18:06:10 +00:00
|
|
|
}
|