Made app default to system-defined dark/light mode on first launch

This commit is contained in:
Mark Feaver 2021-08-07 18:56:59 +10:00
parent 67e8191c2c
commit 9a27e5d7bb
2 changed files with 18 additions and 2 deletions

View File

@ -194,7 +194,7 @@ static NSTimeInterval launchStartedAt;
mainWindow.rootViewController = [LoadingViewController new];
[mainWindow makeKeyAndVisible];
LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"];
LKAppMode appMode = [self getAppModeOrSystemDefault];
[self setCurrentAppMode:appMode];
if (@available(iOS 11, *)) {
@ -245,7 +245,7 @@ static NSTimeInterval launchStartedAt;
[self ensureRootViewController];
LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"];
LKAppMode appMode = [self getCurrentAppMode];
[self setCurrentAppMode:appMode];
[AppReadiness runNowOrWhenAppDidBecomeReady:^{

View File

@ -40,4 +40,20 @@ extension AppDelegate {
@objc func stopClosedGroupPoller() {
ClosedGroupPoller.shared.stop()
}
@objc func getAppModeOrSystemDefault() -> AppMode {
let userDefaults = UserDefaults.standard
guard userDefaults.dictionaryRepresentation().keys.contains("appMode") else {
if #available(iOS 13.0, *) {
return UITraitCollection.current.userInterfaceStyle == .dark ? .dark : .light
} else {
return .light
}
}
let mode = userDefaults.integer(forKey: "appMode")
return AppMode(rawValue: mode) ?? .light
}
}