Add PreferencesModel for setting app preferences

This commit is contained in:
Angelo Stavrow 2020-08-11 14:06:10 -04:00
parent 4fe7d2fee9
commit fceadda878
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import SwiftUI
class PreferencesModel: ObservableObject {
@Environment(\.colorScheme) var currentColorScheme
@Published var preferredColorScheme: ColorScheme = .light
@Published var appearance: Int = 0 {
didSet {
switch appearance {
case 0:
preferredColorScheme = currentColorScheme
case 1:
preferredColorScheme = .light
case 2:
preferredColorScheme = .dark
default:
print("Unknown option selected, failing gracefully...")
}
}
}
}

View File

@ -37,6 +37,8 @@
17A5388C24DDC83F00DEFF9A /* AccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388B24DDC83F00DEFF9A /* AccountModel.swift */; };
17A5388F24DDEC7400DEFF9A /* AccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388D24DDEC7400DEFF9A /* AccountView.swift */; };
17A5389324DDED0000DEFF9A /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5389124DDED0000DEFF9A /* PreferencesView.swift */; };
17D435E824E3128F0036B539 /* PreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D435E724E3128F0036B539 /* PreferencesModel.swift */; };
17D435E924E3128F0036B539 /* PreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D435E724E3128F0036B539 /* PreferencesModel.swift */; };
17DF329D24C87D3500BCE2E3 /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF329C24C87D3500BCE2E3 /* Tests_iOS.swift */; };
17DF32A824C87D3500BCE2E3 /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF32A724C87D3500BCE2E3 /* Tests_macOS.swift */; };
17DF32AA24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */; };
@ -86,6 +88,7 @@
17A5388B24DDC83F00DEFF9A /* AccountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountModel.swift; sourceTree = "<group>"; };
17A5388D24DDEC7400DEFF9A /* AccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountView.swift; sourceTree = "<group>"; };
17A5389124DDED0000DEFF9A /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
17D435E724E3128F0036B539 /* PreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesModel.swift; sourceTree = "<group>"; };
17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteFreely_MultiPlatformApp.swift; sourceTree = "<group>"; };
17DF328224C87D3300BCE2E3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
17DF328324C87D3500BCE2E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -163,6 +166,7 @@
isa = PBXGroup;
children = (
17A5389124DDED0000DEFF9A /* PreferencesView.swift */,
17D435E724E3128F0036B539 /* PreferencesModel.swift */,
);
path = Preferences;
sourceTree = "<group>";
@ -518,6 +522,7 @@
17120DB224E1E19C002B9F6C /* SettingsHeaderView.swift in Sources */,
1756AE7724CB2EDD00FD7257 /* PostEditor.swift in Sources */,
17DF32D524C8CA3400BCE2E3 /* PostStatusBadge.swift in Sources */,
17D435E824E3128F0036B539 /* PreferencesModel.swift in Sources */,
1765F62A24E18EA200C9EBF0 /* SidebarView.swift in Sources */,
1756AE7A24CB65DF00FD7257 /* PostList.swift in Sources */,
171BFDF724D49FD400888236 /* PostCollection.swift in Sources */,
@ -540,6 +545,7 @@
17DF32AD24C87D3500BCE2E3 /* ContentView.swift in Sources */,
1765F62B24E18EA200C9EBF0 /* SidebarView.swift in Sources */,
1756AE7824CB2EDD00FD7257 /* PostEditor.swift in Sources */,
17D435E924E3128F0036B539 /* PreferencesModel.swift in Sources */,
17120DAA24E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */,
17DF32D624C8CA3400BCE2E3 /* PostStatusBadge.swift in Sources */,
17120DAD24E1B99F002B9F6C /* AccountLoginView.swift in Sources */,