From 5c5117102dcf7803abf3f0b6ba8659be5be41842 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Fri, 16 Jul 2021 15:18:30 -0400 Subject: [PATCH] Fix #3936: Set the correct theme based on PBO on launch (#3937) --- .../Application/Delegates/AppDelegate.swift | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Client/Application/Delegates/AppDelegate.swift b/Client/Application/Delegates/AppDelegate.swift index ce2efdd79cb..57ecd2f2b01 100644 --- a/Client/Application/Delegates/AppDelegate.swift +++ b/Client/Application/Delegates/AppDelegate.swift @@ -233,15 +233,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati private var cancellables: Set = [] - private func updateTheme() { - guard let window = window, - let themeOverride = DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.userInterfaceStyleOverride else { - return - } + private var expectedThemeOverride: UIUserInterfaceStyle { + let themeOverride = DefaultTheme( + rawValue: Preferences.General.themeNormalMode.value + )?.userInterfaceStyleOverride ?? .unspecified let isPrivateBrowsing = PrivateBrowsingManager.shared.isPrivateBrowsing - let override: UIUserInterfaceStyle = isPrivateBrowsing ? .dark : themeOverride + return isPrivateBrowsing ? .dark : themeOverride + } + + private func updateTheme() { + guard let window = window else { return } UIView.transition(with: window, duration: 0.15, options: [.transitionCrossDissolve], animations: { - window.overrideUserInterfaceStyle = override + window.overrideUserInterfaceStyle = self.expectedThemeOverride }, completion: nil) } @@ -288,9 +291,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati } .store(in: &cancellables) - if let themeOverride = DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.userInterfaceStyleOverride { - window?.overrideUserInterfaceStyle = themeOverride - } + window?.overrideUserInterfaceStyle = expectedThemeOverride window?.tintColor = UIColor { if $0.userInterfaceStyle == .dark { return .braveLighterBlurple