Skip to content

Commit

Permalink
Enhance (UX): Electron loading (logseq#10049)
Browse files Browse the repository at this point in the history
* hide window until theme is loaded

* show window on db-restored

* move manage call to handle maximized state

* hook on theme load
  • Loading branch information
sprocketc authored Sep 6, 2023
1 parent a6ace12 commit 12642f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
["buffer" :as buffer]
["diff-match-patch" :as google-diff]
["electron" :refer [app autoUpdater dialog ipcMain shell]]
["electron-window-state" :as windowStateKeeper]
["fs" :as fs]
["fs-extra" :as fs-extra]
["os" :as os]
Expand Down Expand Up @@ -618,6 +619,10 @@
(defmethod handle :window-close [^js win]
(.close win))

(defmethod handle :theme-loaded [^js win]
(.manage (windowStateKeeper) win)
(.show win))

;;;;;;;;;;;;;;;;;;;;;;;
;; file-sync-rs-apis ;;
;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion src/electron/electron/window.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
:titleBarStyle "hiddenInset"
:trafficLightPosition {:x 16 :y 16}
:autoHideMenuBar (not mac?)
:show false
:webPreferences
{:plugins true ; pdf
:nodeIntegration false
Expand All @@ -55,7 +56,6 @@
linux?
(assoc :icon (node-path/join js/__dirname "icons/logseq.png")))
win (BrowserWindow. (clj->js win-opts))]
(.manage win-state win)
(.onBeforeSendHeaders (.. session -defaultSession -webRequest)
(clj->js {:urls (array "*://*.youtube.com/*")})
(fn [^js details callback]
Expand Down
6 changes: 4 additions & 2 deletions src/main/frontend/components/theme.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns frontend.components.theme
(:require [frontend.extensions.pdf.core :as pdf]
(:require [electron.ipc :as ipc]
[frontend.extensions.pdf.core :as pdf]
[frontend.config :as config]
[frontend.handler.plugin :as plugin-handler]
[frontend.handler.plugin-config :as plugin-config-handler]
Expand Down Expand Up @@ -33,7 +34,8 @@

(rum/use-effect!
#(let [doc js/document.documentElement]
(.setAttribute doc "lang" preferred-language)))
(.setAttribute doc "lang" preferred-language)
(js/setTimeout (fn [] (ipc/ipc "theme-loaded")) 100))) ; Wait for the theme to be applied

(rum/use-effect!
#(when (and restored-sidebar?
Expand Down

0 comments on commit 12642f5

Please sign in to comment.