Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13779613
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
View Options
diff --git a/Shared/Preferences/PreferencesModel.swift b/Shared/Preferences/PreferencesModel.swift
index 39e9c24..c4ac721 100644
--- a/Shared/Preferences/PreferencesModel.swift
+++ b/Shared/Preferences/PreferencesModel.swift
@@ -1,54 +1,59 @@
import SwiftUI
class PreferencesModel: ObservableObject {
+ private let defaults = UserDefaults.standard
+ let colorSchemeIntegerKey = "colorSchemeIntegerKey"
+
/* We're stuck dropping into AppKit/UIKit to set light/dark schemes for now,
* because setting the .preferredColorScheme modifier on views in SwiftUI is
* currently unreliable.
*
* Feedback submitted to Apple:
*
* FB8382883: "On macOS 11β4, preferredColorScheme modifier does not respect .light ColorScheme"
* FB8383053: "On iOS 14β4/macOS 11β4, it is not possible to unset preferredColorScheme after setting
* it to either .light or .dark"
*/
#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
}
return window
}
#endif
@Published var selectedColorScheme: ColorScheme?
@Published var appearance: Int = 0 {
didSet {
switch appearance {
case 1:
// selectedColorScheme = .light
#if os(macOS)
NSApp.appearance = NSAppearance(named: .aqua)
#else
window?.overrideUserInterfaceStyle = .light
#endif
case 2:
// selectedColorScheme = .dark
#if os(macOS)
NSApp.appearance = NSAppearance(named: .darkAqua)
#else
window?.overrideUserInterfaceStyle = .dark
#endif
default:
// selectedColorScheme = .none
#if os(macOS)
NSApp.appearance = nil
#else
window?.overrideUserInterfaceStyle = .unspecified
#endif
}
+
+ defaults.set(appearance, forKey: colorSchemeIntegerKey)
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Jan 30, 4:45 AM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3610172
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment