|
24 | 24 | (.then (fn [name] (js/console.log "Added Extension: " name)))
|
25 | 25 | (.catch (fn [err] (js/console.log "An error occurred: " err)))))
|
26 | 26 |
|
27 |
| -(defn send-to-renderer |
| 27 | +(defn send-to-renderer! |
28 | 28 | ([action]
|
29 |
| - (send-to-renderer action nil)) |
| 29 | + (send-to-renderer! action nil)) |
30 | 30 | ([action data]
|
31 | 31 | (-> (.-webContents ^js @main-window)
|
32 | 32 | (.send "fromMain" (clj->js {:action action
|
|
42 | 42 | [url]
|
43 | 43 | (contains? allowed-urls (.-host url)))
|
44 | 44 |
|
45 |
| -(defn open-external |
| 45 | +(defn open-external! |
46 | 46 | [url]
|
47 | 47 | (let [url-parsed (js/URL. url)]
|
48 | 48 | (when (and (= (.-protocol url-parsed) "https:") (allowed-url? url-parsed))
|
|
55 | 55 | "windowToggleMaximized" (if (.isMaximized ^js @main-window) (.unmaximize ^js @main-window) (.maximize ^js @main-window))
|
56 | 56 | "windowToggleFullscreen" (.setFullScreen ^js @main-window (not (.isFullScreen ^js @main-window)))
|
57 | 57 | "setThemeMode" (set! (.. nativeTheme -themeSource) (.-data args))
|
58 |
| - "openRemoteUrl" (open-external (.-data args)) |
| 58 | + "openRemoteUrl" (open-external! (.-data args)) |
59 | 59 | ;; https://www.electronjs.org/docs/api/clipboard#clipboardwritedata-type
|
60 | 60 | "writeToClipboard" (.write clipboard (.-data args))
|
61 | 61 | "openDirectory" (.showItemInFolder shell (.-data args))
|
62 |
| - "openDocument" (p/let [documents (file/open @main-window (.-data args))] (doseq [document documents] (send-to-renderer "fileLoaded" document))) |
63 |
| - "saveDocument" (p/let [document (file/save @main-window (.-data args))] (send-to-renderer "fileSaved" document)) |
64 |
| - "saveDocumentAs" (p/let [document (file/save-as @main-window (.-data args))] (send-to-renderer "fileSaved" document)) |
65 |
| - "export" (file/export @main-window (.-data args)))) |
| 62 | + "openDocument" (p/let [documents (file/open! @main-window (.-data args))] (doseq [document documents] (send-to-renderer! "fileLoaded" document))) |
| 63 | + "saveDocument" (p/let [document (file/save! @main-window (.-data args))] (send-to-renderer! "fileSaved" document)) |
| 64 | + "saveDocumentAs" (p/let [document (file/save-as! @main-window (.-data args))] (send-to-renderer! "fileSaved" document)) |
| 65 | + "export" (file/export! @main-window (.-data args)))) |
66 | 66 |
|
67 | 67 | (defn register-window-events!
|
68 | 68 | []
|
|
77 | 77 | ["leave-full-screen" "windowLeavedFullscreen"]
|
78 | 78 | ["minimize" "windowMinimized"]
|
79 | 79 | ["restore" "windowRestored"]]]
|
80 |
| - (.on ^js @main-window window-event #(send-to-renderer action)))) |
| 80 | + (.on ^js @main-window window-event #(send-to-renderer! action)))) |
81 | 81 |
|
82 | 82 | (defn register-web-contents-events!
|
83 | 83 | []
|
|
88 | 88 | (.on (.-webContents ^js @main-window) web-contents-event f))
|
89 | 89 | ;; Forward popups
|
90 | 90 | (.setWindowOpenHandler (.-webContents ^js @main-window) (fn [handler]
|
91 |
| - (open-external (.-url handler)) |
| 91 | + (open-external! (.-url handler)) |
92 | 92 | #js {:action "deny"})))
|
93 | 93 |
|
94 |
| -(defn init-main-window |
| 94 | +(defn init-main-window! |
95 | 95 | []
|
96 | 96 | (let [win-state (window-state-keeper #js {:defaultWidth 1920
|
97 | 97 | :defaultHeight 1080})]
|
|
115 | 115 | (fn []
|
116 | 116 | (.show ^js @main-window)
|
117 | 117 | (.manage win-state ^js @main-window)
|
118 |
| - (send-to-renderer (if (.isMaximized ^js @main-window) |
119 |
| - "windowMaximized" |
120 |
| - "windowUnmaximized")) |
121 |
| - (send-to-renderer (if (.isFullScreen ^js @main-window) |
122 |
| - "windowEnteredFullscreen" |
123 |
| - "windowLeavedFullscreen")) |
| 118 | + (send-to-renderer! (if (.isMaximized ^js @main-window) |
| 119 | + "windowMaximized" |
| 120 | + "windowUnmaximized")) |
| 121 | + (send-to-renderer! (if (.isFullScreen ^js @main-window) |
| 122 | + "windowEnteredFullscreen" |
| 123 | + "windowLeavedFullscreen")) |
124 | 124 | (.hide ^js @loading-window)
|
125 | 125 | (.close ^js @loading-window)))
|
126 | 126 |
|
|
138 | 138 |
|
139 | 139 | #_(.checkForUpdatesAndNotify updater)))
|
140 | 140 |
|
141 |
| -(defn init-loading-window [] |
| 141 | +(defn init-loading-window! [] |
142 | 142 | (set! (.-allowRendererProcessReuse app) false)
|
143 | 143 | (reset! loading-window
|
144 | 144 | (BrowserWindow.
|
|
148 | 148 | :icon (.join path js/__dirname "/public/img/icon.png")
|
149 | 149 | :show false
|
150 | 150 | :frame false}))
|
151 |
| - (.once ^js @loading-window "show" init-main-window) |
| 151 | + (.once ^js @loading-window "show" init-main-window!) |
152 | 152 | (.loadURL ^js @loading-window (.join path "file://" js/__dirname "/public/loading.html"))
|
153 | 153 | (.once ^js (.-webContents @loading-window) "did-finish-load" #(.show ^js @loading-window)))
|
154 | 154 |
|
|
157 | 157 | (.initialize log)
|
158 | 158 | (.on app "window-all-closed" #(when-not (= js/process.platform "darwin")
|
159 | 159 | (.quit app)))
|
160 |
| - (.on app "ready" init-loading-window)) |
| 160 | + (.on app "ready" init-loading-window!)) |
0 commit comments