Appearance based on system theme
This commit is contained in:
parent
1a669feb1a
commit
02932bca93
|
@ -194,8 +194,8 @@ static NSTimeInterval launchStartedAt;
|
||||||
mainWindow.rootViewController = [LoadingViewController new];
|
mainWindow.rootViewController = [LoadingViewController new];
|
||||||
[mainWindow makeKeyAndVisible];
|
[mainWindow makeKeyAndVisible];
|
||||||
|
|
||||||
LKAppMode appMode = [self getAppModeOrSystemDefault];
|
LKAppMode appMode = [self getCurrentAppMode];
|
||||||
[self setCurrentAppMode:appMode];
|
[self adaptAppMode: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
|
||||||
|
@ -246,7 +246,7 @@ static NSTimeInterval launchStartedAt;
|
||||||
[self ensureRootViewController];
|
[self ensureRootViewController];
|
||||||
|
|
||||||
LKAppMode appMode = [self getCurrentAppMode];
|
LKAppMode appMode = [self getCurrentAppMode];
|
||||||
[self setCurrentAppMode:appMode];
|
[self adaptAppMode:appMode];
|
||||||
|
|
||||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||||
[self handleActivation];
|
[self handleActivation];
|
||||||
|
@ -709,16 +709,10 @@ static NSTimeInterval launchStartedAt;
|
||||||
|
|
||||||
# pragma mark - App Mode
|
# pragma mark - App Mode
|
||||||
|
|
||||||
- (LKAppMode)getCurrentAppMode
|
- (void)adaptAppMode:(LKAppMode)appMode
|
||||||
{
|
|
||||||
return [NSUserDefaults.standardUserDefaults integerForKey:@"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, *)) {
|
||||||
|
@ -735,9 +729,34 @@ static NSTimeInterval launchStartedAt;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (LKAppModeUtilities.isSystemDefault) {
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
window.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
|
||||||
|
}
|
||||||
|
}
|
||||||
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.appModeChanged object:nil];
|
[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
|
# pragma mark - Other
|
||||||
|
|
||||||
- (void)handleDataNukeRequested:(NSNotification *)notification
|
- (void)handleDataNukeRequested:(NSNotification *)notification
|
||||||
|
|
|
@ -1,23 +1,12 @@
|
||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"filename" : "moon.pdf",
|
||||||
"filename" : "dark-theme-off-24@1x.png",
|
"idiom" : "universal"
|
||||||
"scale" : "1x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "universal",
|
|
||||||
"filename" : "dark-theme-off-24@2x.png",
|
|
||||||
"scale" : "2x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "universal",
|
|
||||||
"filename" : "dark-theme-off-24@3x.png",
|
|
||||||
"scale" : "3x"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
"version" : 1,
|
"author" : "xcode",
|
||||||
"author" : "xcode"
|
"version" : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 472 B |
Binary file not shown.
Before Width: | Height: | Size: 994 B |
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
@ -1,23 +1,12 @@
|
||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"filename" : "moon_fill.pdf",
|
||||||
"filename" : "dark-theme-on-24@1x.png",
|
"idiom" : "universal"
|
||||||
"scale" : "1x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "universal",
|
|
||||||
"filename" : "dark-theme-on-24@2x.png",
|
|
||||||
"scale" : "2x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "universal",
|
|
||||||
"filename" : "dark-theme-on-24@3x.png",
|
|
||||||
"scale" : "3x"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
"version" : 1,
|
"author" : "xcode",
|
||||||
"author" : "xcode"
|
"version" : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 390 B |
Binary file not shown.
Before Width: | Height: | Size: 704 B |
Binary file not shown.
Before Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "moon_auto.pdf",
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -573,3 +573,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -573,3 +573,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -572,3 +572,6 @@
|
||||||
/* Button text which opens the settings app */
|
/* Button text which opens the settings app */
|
||||||
"OPEN_SETTINGS_BUTTON" = "Settings";
|
"OPEN_SETTINGS_BUTTON" = "Settings";
|
||||||
"APN_Message" = "You've got a new message";
|
"APN_Message" = "You've got a new message";
|
||||||
|
"system_mode_theme" = "System";
|
||||||
|
"dark_mode_theme" = "Dark";
|
||||||
|
"light_mode_theme" = "Light";
|
||||||
|
|
|
@ -303,7 +303,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
|
||||||
closeButton.isAccessibilityElement = true
|
closeButton.isAccessibilityElement = true
|
||||||
navigationItem.leftBarButtonItem = closeButton
|
navigationItem.leftBarButtonItem = closeButton
|
||||||
if #available(iOS 13, *) { // Pre iOS 13 the user can't switch actively but the app still responds to system changes
|
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()
|
let appModeButton = UIButton()
|
||||||
appModeButton.setImage(appModeIcon, for: UIControl.State.normal)
|
appModeButton.setImage(appModeIcon, for: UIControl.State.normal)
|
||||||
appModeButton.tintColor = Colors.text
|
appModeButton.tintColor = Colors.text
|
||||||
|
@ -404,8 +409,26 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func switchAppMode() {
|
@objc private func switchAppMode() {
|
||||||
let newAppMode: AppMode = isLightMode ? .dark : .light
|
let alertVC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||||
AppModeManager.shared.setCurrentAppMode(to: newAppMode)
|
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() {
|
@objc private func showQRCode() {
|
||||||
|
|
|
@ -26,6 +26,16 @@ class BaseVC : UIViewController {
|
||||||
setNeedsStatusBarAppearanceUpdate()
|
setNeedsStatusBarAppearanceUpdate()
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil)
|
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() {
|
internal func setUpGradientBackground() {
|
||||||
hasGradient = true
|
hasGradient = true
|
||||||
|
@ -80,12 +90,13 @@ class BaseVC : UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||||
// TODO: Post an appModeChanged notification?
|
NotificationCenter.default.post(name: .appModeChanged, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc internal func handleAppModeChangedNotification(_ notification: Notification) {
|
@objc internal func handleAppModeChangedNotification(_ notification: Notification) {
|
||||||
if hasGradient {
|
if hasGradient {
|
||||||
setUpGradientBackground() // Re-do the gradient
|
setUpGradientBackground() // Re-do the gradient
|
||||||
}
|
}
|
||||||
|
ensureWindowBackground()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,10 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
|
||||||
return // Not applicable to share extensions
|
return // Not applicable to share extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func setAppModeToSystemDefault() {
|
||||||
|
return // Not applicable to share extensions
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
private func showLockScreenOrMainContent() {
|
private func showLockScreenOrMainContent() {
|
||||||
if OWSScreenLock.shared.isScreenLockEnabled() {
|
if OWSScreenLock.shared.isScreenLockEnabled() {
|
||||||
|
|
|
@ -25,6 +25,10 @@ public final class AppModeManager : NSObject {
|
||||||
public func setCurrentAppMode(to appMode: AppMode) {
|
public func setCurrentAppMode(to appMode: AppMode) {
|
||||||
delegate.setCurrentAppMode(to: appMode)
|
delegate.setCurrentAppMode(to: appMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func setAppModeToSystemDefault() {
|
||||||
|
delegate.setAppModeToSystemDefault()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(LKAppModeManagerDelegate)
|
@objc(LKAppModeManagerDelegate)
|
||||||
|
@ -33,6 +37,7 @@ public protocol AppModeManagerDelegate {
|
||||||
func getCurrentAppMode() -> AppMode
|
func getCurrentAppMode() -> AppMode
|
||||||
@objc(setCurrentAppMode:)
|
@objc(setCurrentAppMode:)
|
||||||
func setCurrentAppMode(to appMode: AppMode)
|
func setCurrentAppMode(to appMode: AppMode)
|
||||||
|
func setAppModeToSystemDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(LKAppMode)
|
@objc(LKAppMode)
|
||||||
|
@ -40,6 +45,10 @@ public enum AppMode : Int {
|
||||||
case light, dark
|
case light, dark
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var isSystemDefault: Bool {
|
||||||
|
return !UserDefaults.standard.dictionaryRepresentation().keys.contains("appMode")
|
||||||
|
}
|
||||||
|
|
||||||
public var isLightMode: Bool {
|
public var isLightMode: Bool {
|
||||||
return AppModeManager.shared.currentAppMode == .light
|
return AppModeManager.shared.currentAppMode == .light
|
||||||
}
|
}
|
||||||
|
@ -49,6 +58,10 @@ public var isDarkMode: Bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public final class LKAppModeUtilities : NSObject {
|
@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 {
|
@objc public static var isLightMode: Bool {
|
||||||
return AppModeManager.shared.currentAppMode == .light
|
return AppModeManager.shared.currentAppMode == .light
|
||||||
|
|
Loading…
Reference in New Issue