pull/249/head
nielsandriesse 5 years ago
parent 9299883caa
commit f3f55d3aee

@ -254,6 +254,9 @@ static NSTimeInterval launchStartedAt;
mainWindow.rootViewController = [LoadingViewController new]; mainWindow.rootViewController = [LoadingViewController new];
[mainWindow makeKeyAndVisible]; [mainWindow makeKeyAndVisible];
LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"];
[self setCurrentAppMode:appMode];
if (@available(iOS 11, *)) { if (@available(iOS 11, *)) {
// This must happen in appDidFinishLaunching or earlier to ensure we don't // This must happen in appDidFinishLaunching or earlier to ensure we don't
// miss notifications. // miss notifications.
@ -308,6 +311,9 @@ static NSTimeInterval launchStartedAt;
[self ensureRootViewController]; [self ensureRootViewController];
LKAppMode appMode = [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"];
[self setCurrentAppMode:appMode];
[AppReadiness runNowOrWhenAppDidBecomeReady:^{ [AppReadiness runNowOrWhenAppDidBecomeReady:^{
[self handleActivation]; [self handleActivation];
}]; }];
@ -937,21 +943,24 @@ static NSTimeInterval launchStartedAt;
# pragma mark - App Mode # pragma mark - App Mode
- (LKAppMode)getCurrentAppMode { - (LKAppMode)getCurrentAppMode
{
UIWindow *window = UIApplication.sharedApplication.keyWindow; UIWindow *window = UIApplication.sharedApplication.keyWindow;
if (window == nil) { return LKAppModeLight; } if (window == nil) { return LKAppModeLight; }
UIUserInterfaceStyle userInterfaceStyle = window.traitCollection.userInterfaceStyle; UIUserInterfaceStyle userInterfaceStyle = window.traitCollection.userInterfaceStyle;
BOOL isLightMode = userInterfaceStyle == UIUserInterfaceStyleUnspecified || userInterfaceStyle == UIUserInterfaceStyleLight; BOOL isLightMode = userInterfaceStyle == UIUserInterfaceStyleLight || userInterfaceStyle == UIUserInterfaceStyleUnspecified;
return isLightMode ? LKAppModeLight : LKAppModeDark; return isLightMode ? LKAppModeLight : LKAppModeDark;
} }
- (void)setCurrentAppModeTo:(LKAppMode)appMode { - (void)setCurrentAppMode:(LKAppMode)appMode
{
UIWindow *window = UIApplication.sharedApplication.keyWindow; UIWindow *window = UIApplication.sharedApplication.keyWindow;
if (window == nil) { return; } if (window == nil) { return; }
[NSUserDefaults.standardUserDefaults setInteger:appMode forKey:@"appMode"];
switch (appMode) { switch (appMode) {
case LKAppModeLight: { case LKAppModeLight: {
if (@available(iOS 13.0, *)) { if (@available(iOS 13.0, *)) {
window.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified; window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
} }
break; break;
} }
@ -962,6 +971,7 @@ static NSTimeInterval launchStartedAt;
break; break;
} }
} }
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.appModeChanged object:nil];
} }
# pragma mark - Other # pragma mark - Other

@ -327,7 +327,6 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
@objc private func switchAppMode() { @objc private func switchAppMode() {
let newAppMode: AppMode = isLightMode ? .dark : .light let newAppMode: AppMode = isLightMode ? .dark : .light
AppModeManager.shared.setCurrentAppMode(to: newAppMode) AppModeManager.shared.setCurrentAppMode(to: newAppMode)
NotificationCenter.default.post(name: .appModeChanged, object: nil)
} }
@objc private func showQRCode() { @objc private func showQRCode() {

@ -30,6 +30,7 @@ public final class AppModeManager : NSObject {
public protocol AppModeManagerDelegate { public protocol AppModeManagerDelegate {
func getCurrentAppMode() -> AppMode func getCurrentAppMode() -> AppMode
@objc(setCurrentAppMode:)
func setCurrentAppMode(to appMode: AppMode) func setCurrentAppMode(to appMode: AppMode)
} }

@ -21,6 +21,10 @@ public enum LKUserDefaults {
case lastDeviceTokenUpload = "lastDeviceTokenUploadTime" case lastDeviceTokenUpload = "lastDeviceTokenUploadTime"
} }
public enum Int: Swift.String {
case appMode
}
public enum String { public enum String {
case slaveDeviceName(Swift.String) case slaveDeviceName(Swift.String)
case deviceToken case deviceToken
@ -54,6 +58,11 @@ public extension UserDefaults {
set { set(newValue, 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? { public subscript(string: LKUserDefaults.String) -> String? {
get { return self.string(forKey: string.key) } get { return self.string(forKey: string.key) }
set { set(newValue, forKey: string.key) } set { set(newValue, forKey: string.key) }

Loading…
Cancel
Save