Save and load default font in UserDefaults

This commit is contained in:
Angelo Stavrow 2020-09-18 11:01:04 -04:00
parent 41eba71e39
commit 2f4d4b8e73
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 7 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class WriteFreelyModel: ObservableObject {
init() {
DispatchQueue.main.async {
self.preferences.appearance = self.defaults.integer(forKey: self.preferences.colorSchemeIntegerKey)
self.preferences.font = self.defaults.integer(forKey: self.preferences.defaultFontIntegerKey)
self.account.restoreState()
if self.account.isLoggedIn {
guard let serverURL = URL(string: self.account.server) else {

View File

@ -3,6 +3,7 @@ import SwiftUI
class PreferencesModel: ObservableObject {
private let defaults = UserDefaults.standard
let colorSchemeIntegerKey = "colorSchemeIntegerKey"
let defaultFontIntegerKey = "defaultFontIntegerKey"
/* We're stuck dropping into AppKit/UIKit to set light/dark schemes for now,
* because setting the .preferredColorScheme modifier on views in SwiftUI is
@ -56,4 +57,9 @@ class PreferencesModel: ObservableObject {
defaults.set(appearance, forKey: colorSchemeIntegerKey)
}
}
@Published var font: Int = 0 {
didSet {
defaults.set(font, forKey: defaultFontIntegerKey)
}
}
}