diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index d02baf1375..73c6c0dd18 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -1255,8 +1255,11 @@ Will return a value that matches this schema: {:type ::tokens-lib :pred valid-tokens-lib? :type-properties - {:encode/json export-dtcg-json - :decode/json parse-multi-set-dtcg-json}})) + ;; NOTE: we can't assign statically at eval time the value of a + ;; function that is declared but not defined; so we need to pass + ;; an anonymous function and delegate the resolution to runtime + {:encode/json #(export-dtcg-json %) + :decode/json #(parse-multi-set-dtcg-json %)}})) (defn duplicate-set [set-name lib & {:keys [suffix]}] (let [sets (get-sets lib) diff --git a/frontend/src/app/main/data/profile.cljs b/frontend/src/app/main/data/profile.cljs index c0d1e29f53..aa0595703b 100644 --- a/frontend/src/app/main/data/profile.cljs +++ b/frontend/src/app/main/data/profile.cljs @@ -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 _] diff --git a/frontend/src/app/util/theme.cljs b/frontend/src/app/util/theme.cljs index eb5723b85c..3c07f7ab68 100644 --- a/frontend/src/app/util/theme.cljs +++ b/frontend/src/app/util/theme.cljs @@ -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 []