Merge pull request #1805 from penpot/hirunatan-set-html-theme

Hirunatan set html theme
This commit is contained in:
Andrey Antukh 2022-04-20 09:20:46 +02:00 committed by GitHub
commit 506f63317a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 1 deletions

View file

@ -6,6 +6,7 @@
(ns app.main.ui.dashboard
(:require
[app.common.colors :as clr]
[app.common.spec :as us]
[app.main.data.dashboard :as dd]
[app.main.data.dashboard.shortcuts :as sc]
@ -22,6 +23,7 @@
[app.main.ui.dashboard.sidebar :refer [sidebar]]
[app.main.ui.dashboard.team :refer [team-settings-page team-members-page team-invitations-page]]
[app.main.ui.hooks :as hooks]
[app.util.dom :as dom]
[app.util.keyboard :as kbd]
[goog.events :as events]
[rumext.alpha :as mf])
@ -103,6 +105,7 @@
(mf/use-effect
(fn []
(dom/set-html-theme-color clr/white "light")
(let [events [(events/listen goog/global EventType.KEYDOWN
(fn [event]
(when (kbd/enter? event)

View file

@ -6,6 +6,7 @@
(ns app.main.ui.viewer
(:require
[app.common.colors :as clr]
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
@ -142,6 +143,7 @@
(mf/use-effect
(fn []
(dom/set-html-theme-color clr/gray-50 "dark")
(let [key1 (events/listen js/window "click" on-click)]
(fn []
(events/unlistenByKey key1)))))

View file

@ -6,6 +6,7 @@
(ns app.main.ui.workspace
(:require
[app.common.colors :as clr]
[app.common.data.macros :as dm]
[app.main.data.messages :as msg]
[app.main.data.workspace :as dw]
@ -130,8 +131,9 @@
(st/emit! ::dwp/force-persist
(dw/finalize-file project-id file-id))))
;; Close any non-modal dialog that may be still open
;; Set html theme color and close any non-modal dialog that may be still open
(mf/with-effect
(dom/set-html-theme-color clr/gray-50 "dark")
(st/emit! msg/hide))
;; Set properly the page title

View file

@ -43,6 +43,12 @@
[^string title]
(set! (.-title globals/document) title))
(defn set-html-theme-color
[^string color scheme]
(let [meta-node (.querySelector js/document "meta[name='theme-color']")]
(.setAttribute meta-node "content" color)
(.setAttribute meta-node "media" (str/format "(prefers-color-scheme: %s)" scheme))))
(defn set-page-style!
[styles]
(let [node (first (get-elements-by-tag globals/document "head"))