diff --git a/Session/Meta/AppDelegate.m b/Session/Meta/AppDelegate.m index 29e9e0cda..413f90059 100644 --- a/Session/Meta/AppDelegate.m +++ b/Session/Meta/AppDelegate.m @@ -194,8 +194,8 @@ static NSTimeInterval launchStartedAt; mainWindow.rootViewController = [LoadingViewController new]; [mainWindow makeKeyAndVisible]; - LKAppMode appMode = [self getAppModeOrSystemDefault]; - [self setCurrentAppMode:appMode]; + LKAppMode appMode = [self getCurrentAppMode]; + [self adaptAppMode:appMode]; if (@available(iOS 11, *)) { // This must happen in appDidFinishLaunching or earlier to ensure we don't @@ -246,7 +246,7 @@ static NSTimeInterval launchStartedAt; [self ensureRootViewController]; LKAppMode appMode = [self getCurrentAppMode]; - [self setCurrentAppMode:appMode]; + [self adaptAppMode:appMode]; [AppReadiness runNowOrWhenAppDidBecomeReady:^{ [self handleActivation]; @@ -709,16 +709,10 @@ static NSTimeInterval launchStartedAt; # pragma mark - App Mode -- (LKAppMode)getCurrentAppMode -{ - return [NSUserDefaults.standardUserDefaults integerForKey:@"appMode"]; -} - -- (void)setCurrentAppMode:(LKAppMode)appMode +- (void)adaptAppMode:(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, *)) { @@ -735,9 +729,34 @@ static NSTimeInterval launchStartedAt; break; } } + if (LKAppModeUtilities.isSystemDefault) { + if (@available(iOS 13.0, *)) { + window.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified; + } + } [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.appModeChanged object:nil]; } +- (LKAppMode)getCurrentAppMode +{ + LKAppMode appMode = [self getAppModeOrSystemDefault]; + UIWindow *window = UIApplication.sharedApplication.keyWindow; + return appMode; +} + +- (void)setCurrentAppMode:(LKAppMode)appMode +{ + [NSUserDefaults.standardUserDefaults setInteger:appMode forKey:@"appMode"]; + [self adaptAppMode:appMode]; +} + +- (void)setAppModeToSystemDefault +{ + [NSUserDefaults.standardUserDefaults removeObjectForKey:@"appMode"]; + LKAppMode appMode = [self getCurrentAppMode]; + [self adaptAppMode:appMode]; +} + # pragma mark - Other - (void)handleDataNukeRequested:(NSNotification *)notification diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/Contents.json b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/Contents.json index b61a86768..4d1bdc517 100644 --- a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/Contents.json +++ b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/Contents.json @@ -1,23 +1,12 @@ { "images" : [ { - "idiom" : "universal", - "filename" : "dark-theme-off-24@1x.png", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "dark-theme-off-24@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "dark-theme-off-24@3x.png", - "scale" : "3x" + "filename" : "moon.pdf", + "idiom" : "universal" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@1x.png b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@1x.png deleted file mode 100644 index 78d8d6869..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@1x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@2x.png b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@2x.png deleted file mode 100644 index f63cd9b30..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@2x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@3x.png b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@3x.png deleted file mode 100644 index 10824a121..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/dark-theme-off-24@3x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/moon.pdf b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/moon.pdf new file mode 100644 index 000000000..2e49f3144 Binary files /dev/null and b/Session/Meta/Images.xcassets/ic_dark_theme_off.imageset/moon.pdf differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/Contents.json b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/Contents.json index 419eeeb08..c64d93968 100644 --- a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/Contents.json +++ b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/Contents.json @@ -1,23 +1,12 @@ { "images" : [ { - "idiom" : "universal", - "filename" : "dark-theme-on-24@1x.png", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "dark-theme-on-24@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "dark-theme-on-24@3x.png", - "scale" : "3x" + "filename" : "moon_fill.pdf", + "idiom" : "universal" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@1x.png b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@1x.png deleted file mode 100644 index 1ff344e0a..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@1x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@2x.png b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@2x.png deleted file mode 100644 index fbdf614dd..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@2x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@3x.png b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@3x.png deleted file mode 100644 index a82283feb..000000000 Binary files a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/dark-theme-on-24@3x.png and /dev/null differ diff --git a/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/moon_fill.pdf b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/moon_fill.pdf new file mode 100644 index 000000000..a483dc690 Binary files /dev/null and b/Session/Meta/Images.xcassets/ic_dark_theme_on.imageset/moon_fill.pdf differ diff --git a/Session/Meta/Images.xcassets/ic_theme_auto.imageset/Contents.json b/Session/Meta/Images.xcassets/ic_theme_auto.imageset/Contents.json new file mode 100644 index 000000000..3c725dec9 --- /dev/null +++ b/Session/Meta/Images.xcassets/ic_theme_auto.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "moon_auto.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Session/Meta/Images.xcassets/ic_theme_auto.imageset/moon_auto.pdf b/Session/Meta/Images.xcassets/ic_theme_auto.imageset/moon_auto.pdf new file mode 100644 index 000000000..f2f6aae2e Binary files /dev/null and b/Session/Meta/Images.xcassets/ic_theme_auto.imageset/moon_auto.pdf differ diff --git a/Session/Meta/Translations/de.lproj/Localizable.strings b/Session/Meta/Translations/de.lproj/Localizable.strings index cdaf3eea8..8652ee572 100644 --- a/Session/Meta/Translations/de.lproj/Localizable.strings +++ b/Session/Meta/Translations/de.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 9105470ef..3e0abe961 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -573,3 +573,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/es.lproj/Localizable.strings b/Session/Meta/Translations/es.lproj/Localizable.strings index bf4beb691..96dcb37e1 100644 --- a/Session/Meta/Translations/es.lproj/Localizable.strings +++ b/Session/Meta/Translations/es.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/fa.lproj/Localizable.strings b/Session/Meta/Translations/fa.lproj/Localizable.strings index 219102403..365e59a13 100644 --- a/Session/Meta/Translations/fa.lproj/Localizable.strings +++ b/Session/Meta/Translations/fa.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/fi.lproj/Localizable.strings b/Session/Meta/Translations/fi.lproj/Localizable.strings index 8179cde64..e207a79c7 100644 --- a/Session/Meta/Translations/fi.lproj/Localizable.strings +++ b/Session/Meta/Translations/fi.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/fr.lproj/Localizable.strings b/Session/Meta/Translations/fr.lproj/Localizable.strings index d85aa7fe7..0d8755eab 100644 --- a/Session/Meta/Translations/fr.lproj/Localizable.strings +++ b/Session/Meta/Translations/fr.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/hi.lproj/Localizable.strings b/Session/Meta/Translations/hi.lproj/Localizable.strings index 90ee33318..acceed3b6 100644 --- a/Session/Meta/Translations/hi.lproj/Localizable.strings +++ b/Session/Meta/Translations/hi.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/hr.lproj/Localizable.strings b/Session/Meta/Translations/hr.lproj/Localizable.strings index ab4eb2907..56fb5a125 100644 --- a/Session/Meta/Translations/hr.lproj/Localizable.strings +++ b/Session/Meta/Translations/hr.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/id-ID.lproj/Localizable.strings b/Session/Meta/Translations/id-ID.lproj/Localizable.strings index 1a7953708..98a53450d 100644 --- a/Session/Meta/Translations/id-ID.lproj/Localizable.strings +++ b/Session/Meta/Translations/id-ID.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/it.lproj/Localizable.strings b/Session/Meta/Translations/it.lproj/Localizable.strings index 5f9d6c505..117f44ebb 100644 --- a/Session/Meta/Translations/it.lproj/Localizable.strings +++ b/Session/Meta/Translations/it.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/ja.lproj/Localizable.strings b/Session/Meta/Translations/ja.lproj/Localizable.strings index 695c75688..f70f9d905 100644 --- a/Session/Meta/Translations/ja.lproj/Localizable.strings +++ b/Session/Meta/Translations/ja.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/nl.lproj/Localizable.strings b/Session/Meta/Translations/nl.lproj/Localizable.strings index a3d3559cc..177d55e6a 100644 --- a/Session/Meta/Translations/nl.lproj/Localizable.strings +++ b/Session/Meta/Translations/nl.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/pl.lproj/Localizable.strings b/Session/Meta/Translations/pl.lproj/Localizable.strings index 258f4181f..bb96a0f00 100644 --- a/Session/Meta/Translations/pl.lproj/Localizable.strings +++ b/Session/Meta/Translations/pl.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings index a56203b17..55a396153 100644 --- a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings +++ b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/ru.lproj/Localizable.strings b/Session/Meta/Translations/ru.lproj/Localizable.strings index 4fba7626a..fa6bec9f5 100644 --- a/Session/Meta/Translations/ru.lproj/Localizable.strings +++ b/Session/Meta/Translations/ru.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/si.lproj/Localizable.strings b/Session/Meta/Translations/si.lproj/Localizable.strings index 9105470ef..3e0abe961 100644 --- a/Session/Meta/Translations/si.lproj/Localizable.strings +++ b/Session/Meta/Translations/si.lproj/Localizable.strings @@ -573,3 +573,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/sk.lproj/Localizable.strings b/Session/Meta/Translations/sk.lproj/Localizable.strings index aa54db09a..f3b6cf878 100644 --- a/Session/Meta/Translations/sk.lproj/Localizable.strings +++ b/Session/Meta/Translations/sk.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/sv.lproj/Localizable.strings b/Session/Meta/Translations/sv.lproj/Localizable.strings index 02dca9da7..ac958ab1e 100644 --- a/Session/Meta/Translations/sv.lproj/Localizable.strings +++ b/Session/Meta/Translations/sv.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/th.lproj/Localizable.strings b/Session/Meta/Translations/th.lproj/Localizable.strings index 77f56e9ba..a09a9c805 100644 --- a/Session/Meta/Translations/th.lproj/Localizable.strings +++ b/Session/Meta/Translations/th.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings index 8606a7101..5ff989a05 100644 --- a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings +++ b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings index 961fb881c..b44d5dc07 100644 --- a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings index 8d334a24c..baaa6937c 100644 --- a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings @@ -572,3 +572,6 @@ /* Button text which opens the settings app */ "OPEN_SETTINGS_BUTTON" = "Settings"; "APN_Message" = "You've got a new message"; +"system_mode_theme" = "System"; +"dark_mode_theme" = "Dark"; +"light_mode_theme" = "Light"; diff --git a/Session/Settings/SettingsVC.swift b/Session/Settings/SettingsVC.swift index 53febc939..64046bb71 100644 --- a/Session/Settings/SettingsVC.swift +++ b/Session/Settings/SettingsVC.swift @@ -303,7 +303,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { closeButton.isAccessibilityElement = true navigationItem.leftBarButtonItem = closeButton if #available(iOS 13, *) { // Pre iOS 13 the user can't switch actively but the app still responds to system changes - let appModeIcon = isDarkMode ? #imageLiteral(resourceName: "ic_dark_theme_on").withTintColor(.white) : #imageLiteral(resourceName: "ic_dark_theme_off").withTintColor(.black) + let appModeIcon: UIImage + if isSystemDefault { + appModeIcon = isDarkMode ? #imageLiteral(resourceName: "ic_theme_auto").withTintColor(.white) : #imageLiteral(resourceName: "ic_theme_auto").withTintColor(.black) + } else { + appModeIcon = isDarkMode ? #imageLiteral(resourceName: "ic_dark_theme_on").withTintColor(.white) : #imageLiteral(resourceName: "ic_dark_theme_off").withTintColor(.black) + } let appModeButton = UIButton() appModeButton.setImage(appModeIcon, for: UIControl.State.normal) appModeButton.tintColor = Colors.text @@ -404,8 +409,26 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { } @objc private func switchAppMode() { - let newAppMode: AppMode = isLightMode ? .dark : .light - AppModeManager.shared.setCurrentAppMode(to: newAppMode) + let alertVC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet) + let systemModeAction = UIAlertAction.init(title: NSLocalizedString("system_mode_theme", comment: ""), style: .default) { _ in + AppModeManager.shared.setAppModeToSystemDefault() + } + alertVC.addAction(systemModeAction) + + let darkModeAction = UIAlertAction.init(title: NSLocalizedString("dark_mode_theme", comment: ""), style: .default) { _ in + AppModeManager.shared.setCurrentAppMode(to: .dark) + } + alertVC.addAction(darkModeAction) + + let lightModeAction = UIAlertAction.init(title: NSLocalizedString("light_mode_theme", comment: ""), style: .default) { _ in + AppModeManager.shared.setCurrentAppMode(to: .light) + } + alertVC.addAction(lightModeAction) + + let cancelAction = UIAlertAction.init(title: NSLocalizedString("TXT_CANCEL_TITLE", comment: ""), style: .cancel) {_ in } + alertVC.addAction(cancelAction) + + self.presentAlert(alertVC) } @objc private func showQRCode() { diff --git a/Session/Shared/BaseVC.swift b/Session/Shared/BaseVC.swift index c13d8ca0b..ff53996b3 100644 --- a/Session/Shared/BaseVC.swift +++ b/Session/Shared/BaseVC.swift @@ -26,6 +26,16 @@ class BaseVC : UIViewController { setNeedsStatusBarAppearanceUpdate() NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil) } + + internal func ensureWindowBackground() { + let appMode = AppModeManager.shared.currentAppMode + switch appMode { + case .light: + UIApplication.shared.delegate?.window??.backgroundColor = .white + case .dark: + UIApplication.shared.delegate?.window??.backgroundColor = .black + } + } internal func setUpGradientBackground() { hasGradient = true @@ -80,12 +90,13 @@ class BaseVC : UIViewController { } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - // TODO: Post an appModeChanged notification? + NotificationCenter.default.post(name: .appModeChanged, object: nil) } @objc internal func handleAppModeChangedNotification(_ notification: Notification) { if hasGradient { setUpGradientBackground() // Re-do the gradient } + ensureWindowBackground() } } diff --git a/SessionShareExtension/ShareVC.swift b/SessionShareExtension/ShareVC.swift index 41cfa31a7..6de48c8d9 100644 --- a/SessionShareExtension/ShareVC.swift +++ b/SessionShareExtension/ShareVC.swift @@ -173,6 +173,10 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD return // Not applicable to share extensions } + public func setAppModeToSystemDefault() { + return // Not applicable to share extensions + } + // MARK: Updating private func showLockScreenOrMainContent() { if OWSScreenLock.shared.isScreenLockEnabled() { diff --git a/SessionUIKit/Style Guide/AppMode.swift b/SessionUIKit/Style Guide/AppMode.swift index 2da777c2d..01db04682 100644 --- a/SessionUIKit/Style Guide/AppMode.swift +++ b/SessionUIKit/Style Guide/AppMode.swift @@ -25,6 +25,10 @@ public final class AppModeManager : NSObject { public func setCurrentAppMode(to appMode: AppMode) { delegate.setCurrentAppMode(to: appMode) } + + public func setAppModeToSystemDefault() { + delegate.setAppModeToSystemDefault() + } } @objc(LKAppModeManagerDelegate) @@ -33,6 +37,7 @@ public protocol AppModeManagerDelegate { func getCurrentAppMode() -> AppMode @objc(setCurrentAppMode:) func setCurrentAppMode(to appMode: AppMode) + func setAppModeToSystemDefault() } @objc(LKAppMode) @@ -40,6 +45,10 @@ public enum AppMode : Int { case light, dark } +public var isSystemDefault: Bool { + return !UserDefaults.standard.dictionaryRepresentation().keys.contains("appMode") +} + public var isLightMode: Bool { return AppModeManager.shared.currentAppMode == .light } @@ -49,6 +58,10 @@ public var isDarkMode: Bool { } @objc public final class LKAppModeUtilities : NSObject { + + @objc public static var isSystemDefault: Bool { + return !UserDefaults.standard.dictionaryRepresentation().keys.contains("appMode") + } @objc public static var isLightMode: Bool { return AppModeManager.shared.currentAppMode == .light