Make theme toggle skip "system" theme

This commit is contained in:
Andrey Antukh
2025-06-03 16:29:06 +02:00
parent d6e0001ac4
commit d2d39aad30
2 changed files with 14 additions and 6 deletions

View File

@@ -21,6 +21,7 @@
[app.plugins.register :as plugins.register]
[app.util.i18n :as i18n :refer [tr]]
[app.util.storage :as storage]
[app.util.theme :as theme]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
@@ -160,11 +161,12 @@
(update [_ state]
(update-in state [:profile :theme]
(fn [current]
(case current
"dark" "light"
"light" "system"
"system" "dark"
"default"))))
(let [current (if (= current "system")
(theme/get-system-theme)
current)]
(case current
"dark" "light"
"light" "dark")))))
ptk/WatchEvent
(watch [it state _]

View File

@@ -16,6 +16,12 @@
(def ^:const default "dark")
(defn get-system-theme
[]
(if ^boolean (.-matches color-scheme-media-query)
"dark"
"light"))
(defn- set-color-scheme
[^string color]
@@ -26,7 +32,7 @@
(defn use-initialize
[{profile-theme :theme}]
(let [system-theme* (mf/use-state #(if (.-matches color-scheme-media-query) "dark" "light"))
(let [system-theme* (mf/use-state get-system-theme)
system-theme (deref system-theme*)]
(mf/with-effect []