diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index eeb6fc4d9..7fc1ec39e 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -254,6 +254,9 @@ static NSTimeInterval launchStartedAt; mainWindow.rootViewController = [LoadingViewController new]; [mainWindow makeKeyAndVisible]; + LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"]; + [self setCurrentAppMode:appMode]; + if (@available(iOS 11, *)) { // This must happen in appDidFinishLaunching or earlier to ensure we don't // miss notifications. @@ -308,6 +311,9 @@ static NSTimeInterval launchStartedAt; [self ensureRootViewController]; + LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"]; + [self setCurrentAppMode:appMode]; + [AppReadiness runNowOrWhenAppDidBecomeReady:^{ [self handleActivation]; }]; @@ -937,21 +943,24 @@ static NSTimeInterval launchStartedAt; # pragma mark - App Mode -- (LKAppMode)getCurrentAppMode { +- (LKAppMode)getCurrentAppMode +{ UIWindow *window = UIApplication.sharedApplication.keyWindow; if (window == nil) { return LKAppModeLight; } UIUserInterfaceStyle userInterfaceStyle = window.traitCollection.userInterfaceStyle; - BOOL isLightMode = userInterfaceStyle == UIUserInterfaceStyleUnspecified || userInterfaceStyle == UIUserInterfaceStyleLight; + BOOL isLightMode = userInterfaceStyle == UIUserInterfaceStyleLight || userInterfaceStyle == UIUserInterfaceStyleUnspecified; return isLightMode ? LKAppModeLight : LKAppModeDark; } -- (void)setCurrentAppModeTo:(LKAppMode)appMode { +- (void)setCurrentAppMode:(LKAppMode)appMode +{ UIWindow *window = UIApplication.sharedApplication.keyWindow; if (window == nil) { return; } + [NSUserDefaults.standardUserDefaults setInteger:appMode forKey:@"appMode"]; switch (appMode) { case LKAppModeLight: { if (@available(iOS 13.0, *)) { - window.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified; + window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight; } break; } @@ -962,6 +971,7 @@ static NSTimeInterval launchStartedAt; break; } } + [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.appModeChanged object:nil]; } # pragma mark - Other diff --git a/Signal/src/Loki/View Controllers/SettingsVC.swift b/Signal/src/Loki/View Controllers/SettingsVC.swift index f2277f609..1203c262f 100644 --- a/Signal/src/Loki/View Controllers/SettingsVC.swift +++ b/Signal/src/Loki/View Controllers/SettingsVC.swift @@ -327,7 +327,6 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { @objc private func switchAppMode() { let newAppMode: AppMode = isLightMode ? .dark : .light AppModeManager.shared.setCurrentAppMode(to: newAppMode) - NotificationCenter.default.post(name: .appModeChanged, object: nil) } @objc private func showQRCode() { diff --git a/SignalMessaging/Loki/Redesign/Style Guide/AppMode.swift b/SignalMessaging/Loki/Redesign/Style Guide/AppMode.swift index aa507d26b..640a2129d 100644 --- a/SignalMessaging/Loki/Redesign/Style Guide/AppMode.swift +++ b/SignalMessaging/Loki/Redesign/Style Guide/AppMode.swift @@ -30,6 +30,7 @@ public final class AppModeManager : NSObject { public protocol AppModeManagerDelegate { func getCurrentAppMode() -> AppMode + @objc(setCurrentAppMode:) func setCurrentAppMode(to appMode: AppMode) } diff --git a/SignalServiceKit/src/Loki/Utilities/LKUserDefaults.swift b/SignalServiceKit/src/Loki/Utilities/LKUserDefaults.swift index 21ab9158d..9b8184df6 100644 --- a/SignalServiceKit/src/Loki/Utilities/LKUserDefaults.swift +++ b/SignalServiceKit/src/Loki/Utilities/LKUserDefaults.swift @@ -20,6 +20,10 @@ public enum LKUserDefaults { public enum Double : Swift.String { case lastDeviceTokenUpload = "lastDeviceTokenUploadTime" } + + public enum Int: Swift.String { + case appMode + } public enum String { case slaveDeviceName(Swift.String) @@ -53,6 +57,11 @@ public extension UserDefaults { get { return self.double(forKey: double.rawValue) } set { set(newValue, forKey: double.rawValue) } } + + public subscript(int: LKUserDefaults.Int) -> Int { + get { return self.integer(forKey: int.rawValue) } + set { set(newValue, forKey: int.rawValue) } + } public subscript(string: LKUserDefaults.String) -> String? { get { return self.string(forKey: string.key) }