Skip to content

Commit 8606375

Browse files
committed
refactor main
1 parent 94d64a5 commit 8606375

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/electron/main.cljs

+18-17
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
["closed" #(reset! main-window nil)]]]
9393
(.on (.-webContents ^js @main-window) web-contents-event f)))
9494

95+
(defn handle-on-ready-to-show!
96+
[^js window]
97+
(doseq
98+
[action
99+
[(if (.isMaximized window) "window-maximized" "window-unmaximized")
100+
(if (.isFullScreen window) "window-entered-fullscreen" "window-leaved-fullscreen")
101+
(if (.isFocused window) "window-focused" "window-blurred")
102+
"window-loaded"]]
103+
(send-to-renderer! action)))
104+
95105
(defn init-main-window!
96106
[]
97107
(let [win-state (window-state-keeper #js {:defaultWidth 1920
@@ -112,29 +122,20 @@
112122
#js {:sandbox false
113123
:preload (.join path js/__dirname "preload.js")}}))
114124

115-
(.once ^js @main-window "ready-to-show"
125+
(.once ^js @main-window
126+
"ready-to-show"
116127
(fn []
117128
(.show ^js @main-window)
118129
(.manage win-state ^js @main-window)
119130
(.hide ^js @loading-window)
120131
(.close ^js @loading-window)))
121132

122-
(.on ^js @main-window "ready-to-show"
123-
(fn []
124-
(send-to-renderer! (if (.isMaximized ^js @main-window)
125-
"window-maximized"
126-
"window-unmaximized"))
127-
(send-to-renderer! (if (.isFullScreen ^js @main-window)
128-
"window-entered-fullscreen"
129-
"window-leaved-fullscreen"))
130-
(send-to-renderer! (if (.isFocused ^js @main-window)
131-
"window-focused"
132-
"window-blurred"))
133-
(send-to-renderer! "window-loaded")))
134-
135-
(.loadURL ^js @main-window (if config/debug?
136-
"http://localhost:8080"
137-
(.join path "file://" js/__dirname "/public/index.html")))
133+
(.on ^js @main-window "ready-to-show" #(handle-on-ready-to-show! @main-window))
134+
135+
(.loadURL ^js @main-window
136+
(if config/debug?
137+
"http://localhost:8080"
138+
(.join path "file://" js/__dirname "/public/index.html")))
138139

139140
(register-web-contents-events!)
140141
(register-ipc-on-events!)

0 commit comments

Comments
 (0)