From a8796e7c2e6c50ea4d164b6031c25af2bc2f5036 Mon Sep 17 00:00:00 2001 From: Rokas Ambrazevicius <2559446+rokas-ambrazevicius@users.noreply.github.com> Date: Mon, 14 Oct 2024 18:28:24 +0300 Subject: [PATCH] APPLE: fix system appearance not working on iOS (#1305) --- .../Services/AppSettings/AppSettings.swift | 26 ++++++++++--------- .../AppSettings/Settings/AppSetting.swift | 3 --- .../Services/Modifiers/AppearanceUpdate.swift | 5 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nym-vpn-apple/Services/Sources/Services/AppSettings/AppSettings.swift b/nym-vpn-apple/Services/Sources/Services/AppSettings/AppSettings.swift index 000f14319e..d59fc287b9 100644 --- a/nym-vpn-apple/Services/Sources/Services/AppSettings/AppSettings.swift +++ b/nym-vpn-apple/Services/Sources/Services/AppSettings/AppSettings.swift @@ -8,8 +8,8 @@ public final class AppSettings: ObservableObject { @AppStorage(AppSettingKey.currentAppearance.rawValue) public var currentAppearance: AppSetting.Appearance = .automatic { didSet { -// guard let keyWindow = AppSettings.keyWindow else { return } -// keyWindow.rootViewController?.overrideUserInterfaceStyle = currentAppearance.userInterfaceStyle + guard let keyWindow = AppSettings.keyWindow else { return } + keyWindow.rootViewController?.overrideUserInterfaceStyle = currentAppearance.userInterfaceStyle } } #else @@ -75,18 +75,20 @@ public final class AppSettings: ObservableObject { } } +#if os(iOS) private extension AppSettings { -// static var keyWindow: UIWindow? { -// guard let window = UIApplication.shared.connectedScenes -// .compactMap({ $0 as? UIWindowScene }) -// .flatMap({ $0.windows }) -// .first(where: { $0.isKeyWindow }) -// else { -// return nil -// } -// return window -// } + static var keyWindow: UIWindow? { + guard let window = UIApplication.shared.connectedScenes + .compactMap({ $0 as? UIWindowScene }) + .flatMap({ $0.windows }) + .first(where: { $0.isKeyWindow }) + else { + return nil + } + return window + } } +#endif enum AppSettingKey: String { case currentAppearance diff --git a/nym-vpn-apple/Services/Sources/Services/AppSettings/Settings/AppSetting.swift b/nym-vpn-apple/Services/Sources/Services/AppSettings/Settings/AppSetting.swift index 3a576d6510..95910e7797 100644 --- a/nym-vpn-apple/Services/Sources/Services/AppSettings/Settings/AppSetting.swift +++ b/nym-vpn-apple/Services/Sources/Services/AppSettings/Settings/AppSetting.swift @@ -11,14 +11,11 @@ public struct AppSetting { public var colorScheme: ColorScheme? { switch self { case .light: - print("light") return .light case .dark: - print("dark") return .dark #if os(iOS) case .automatic: - print("system") return nil #endif } diff --git a/nym-vpn-apple/Services/Sources/Services/Modifiers/AppearanceUpdate.swift b/nym-vpn-apple/Services/Sources/Services/Modifiers/AppearanceUpdate.swift index 5420e13c24..77beb36075 100644 --- a/nym-vpn-apple/Services/Sources/Services/Modifiers/AppearanceUpdate.swift +++ b/nym-vpn-apple/Services/Sources/Services/Modifiers/AppearanceUpdate.swift @@ -6,8 +6,9 @@ public struct AppearanceUpdate: ViewModifier { public func body(content: Content) -> some View { content -// .preferredColorScheme(appSettings.currentAppearance.colorScheme) -// .environment(\.colorScheme, appSettings.currentAppearance.colorScheme) +#if os(macOS) + .preferredColorScheme(appSettings.currentAppearance.colorScheme) +#endif } }