From 906d4c8b4378458b4d50acfef9fa82a65cfc337f Mon Sep 17 00:00:00 2001
From: Harlan Haskins <harlan@harlanhaskins.com>
Date: Tue, 18 Mar 2025 05:30:57 +0000
Subject: [PATCH] Use platform-appropriate semantic colors on visionOS

---
 Sources/About/AboutController.swift          |  5 ++-
 Sources/Settings/Model/SettingsSection.swift | 10 +++--
 Sources/UI Elements/PresentationTheme.swift  | 47 +++++++++++++++++++-
 3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/Sources/About/AboutController.swift b/Sources/About/AboutController.swift
index 5c2df1a0c..1ba209bd6 100644
--- a/Sources/About/AboutController.swift
+++ b/Sources/About/AboutController.swift
@@ -97,9 +97,10 @@ class AboutController: UIViewController, MFMailComposeViewControllerDelegate, UI
     }
 
     private func loadWebsite() {
+        let webTheme = PresentationTheme.current.webEquivalentTheme
         let mainBundle = Bundle.main
-        let textColor = PresentationTheme.current.colors.cellTextColor.toHex ?? "#000000"
-        let backgroundColor = PresentationTheme.current.colors.background.toHex ?? "#FFFFFF"
+        let textColor = webTheme.colors.cellTextColor.toHex ?? "#000000"
+        let backgroundColor = webTheme.colors.background.toHex ?? "#FFFFFF"
         guard let bundleShortVersionString = mainBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else {
             return
         }
diff --git a/Sources/Settings/Model/SettingsSection.swift b/Sources/Settings/Model/SettingsSection.swift
index a7b6ffbe5..5897ba3c2 100644
--- a/Sources/Settings/Model/SettingsSection.swift
+++ b/Sources/Settings/Model/SettingsSection.swift
@@ -177,10 +177,12 @@ enum MainOptions {
     }
 
     static func section() -> SettingsSection? {
-        .init(title: nil, items: [
-            privacy,
-            appearance,
-        ])
+        var items = [privacy]
+        #if !os(visionOS)
+        // visionOS uses a standard system appearance and doesn't have light/dark mode.
+        items.append(appearance)
+        #endif
+        return .init(title: nil, items: items)
     }
 }
 
diff --git a/Sources/UI Elements/PresentationTheme.swift b/Sources/UI Elements/PresentationTheme.swift
index 10585824d..ff4738304 100644
--- a/Sources/UI Elements/PresentationTheme.swift	
+++ b/Sources/UI Elements/PresentationTheme.swift	
@@ -112,10 +112,24 @@ enum PresentationThemeType: Int {
     static let darkTheme = PresentationTheme(colors: darkPalette)
     static let blackTheme = PresentationTheme(colors: blackPalette)
 
+    #if os(visionOS)
+    static let visionTheme = PresentationTheme(colors: visionPalette)
+    #endif
+
     var isDark: Bool {
         return colors.isDark
     }
 
+    var webEquivalentTheme: PresentationTheme {
+        #if os(visionOS)
+        // Since visionOS uses semantic colors for many of these, there will not be equivalent
+        // web hex colors. Fault back to the dark theme
+        return .darkTheme
+        #else
+        return self
+        #endif
+    }
+
     var isBlack: Bool {
         return UserDefaults.standard.bool(forKey: kVLCSettingAppThemeBlack)
     }
@@ -150,6 +164,9 @@ enum PresentationThemeType: Int {
     }
 
     static func respectiveTheme(for theme: PresentationThemeType?, excludingBlackTheme: Bool = false) -> PresentationTheme {
+#if os(visionOS)
+        return .visionTheme
+#else
         guard let theme = theme else {
             return PresentationTheme.brightTheme
         }
@@ -173,9 +190,10 @@ enum PresentationThemeType: Int {
             }
 #else
             presentationTheme = darkTheme
-#endif
+#endif // os(iOS)
         }
         return presentationTheme
+#endif // os(visionOS)
     }
 
     let colors: ColorPalette
@@ -188,7 +206,7 @@ enum PresentationThemeType: Int {
         let r = CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0
         let g = CGFloat((rgbValue & 0xFF00) >> 8) / 255.0
         let b = CGFloat(rgbValue & 0xFF) / 255.0
-        self.init(red: r, green: g, blue: b, alpha: 1.0)
+        self.init(red: r, green: g, blue: b, alpha: alpha)
     }
 
     private func toHex(alpha: Bool = false) -> String? {
@@ -286,6 +304,31 @@ let blackPalette = ColorPalette(isDark: true,
                                 textfieldPlaceholderColor: UIColor(0x737373),
                                 thumbnailBackgroundColor: UIColor(0x1C1E21))
 
+#if os(visionOS)
+let visionPalette = ColorPalette(isDark: true,
+                                 name: "visionOS",
+                                 statusBarStyle: .lightContent,
+                                 navigationbarColor: .clear,
+                                 navigationbarTextColor: .label,
+                                 background: .clear,
+                                 cellBackgroundA: .clear,
+                                 cellBackgroundB: UIColor(0x494B4D, 0.2),
+                                 cellDetailTextColor: .tertiaryLabel,
+                                 cellTextColor: .label,
+                                 lightTextColor: .secondaryLabel,
+                                 sectionHeaderTextColor: .secondaryLabel,
+                                 separatorColor: .tertiarySystemFill,
+                                 mediaCategorySeparatorColor: .tertiarySystemFill,
+                                 tabBarColor: .clear,
+                                 orangeUI: UIColor(0xFF8800),
+                                 orangeDarkAccent: UIColor(0xD57200),
+                                 toolBarStyle: UIBarStyle.black,
+                                 blurStyle: .dark,
+                                 textfieldBorderColor: UIColor(0x84929C),
+                                 textfieldPlaceholderColor: UIColor(0x737373),
+                                 thumbnailBackgroundColor: UIColor(0x1C1E21))
+#endif
+
 let defaultFont = Typography(tableHeaderFont: UIFont.systemFont(ofSize: 24, weight: .semibold))
 
 // MARK: - UIStatusBarStyle - autoDarkContent
-- 
GitLab