Skip to content

Commit d6ecdc6

Browse files
committed
guard window.api
1 parent 04bf18a commit d6ecdc6

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

src/renderer/core.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115

116116
(rf/dispatch-sync [::app.e/initialize-db])
117117
(rf/dispatch-sync [::app.e/set-lang system/language])
118+
(rf/dispatch-sync [::app.e/load-system-fonts])
118119
(rf/dispatch-sync [::app.e/load-local-db])
119120
(rf/dispatch-sync [::document.e/init])
120121
(rf/dispatch-sync [::theme.e/set-native-mode (theme.fx/native-mode! theme.fx/native-query!)])
@@ -126,8 +127,7 @@
126127
(.setup paper)
127128

128129
(if system/electron?
129-
(do (register-ipc-on-events!)
130-
(rf/dispatch [::app.e/load-system-fonts]))
130+
(register-ipc-on-events!)
131131
(add-listeners!))
132132

133133
(mount-root!))

src/renderer/element/impl/text.cljs

+15-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[renderer.utils.bounds :as bounds]
1414
[renderer.utils.dom :as dom]
1515
[renderer.utils.element :as element]
16+
[renderer.utils.system :as system]
1617
[renderer.utils.units :as units]))
1718

1819
(derive :text ::hierarchy/shape)
@@ -109,15 +110,17 @@
109110
(str (units/unit->px font-size) "px"))
110111
:font-weight (if (empty? font-weight) "inherit" font-weight)}}]]))
111112

112-
(defmethod hierarchy/path :text
113-
[{:keys [attrs content]}]
114-
(let [font-descriptor #js {:family (:font-family attrs)
115-
:weight (js/parseInt (:font-weight attrs))
116-
:italic (= (:font-style attrs) "italic")}]
117-
(.textToPath
118-
js/window.api
119-
content
120-
#js {:font-url (.-path (.findFont js/window.api font-descriptor))
121-
:x (js/parseFloat (:x attrs))
122-
:y (js/parseFloat (:y attrs))
123-
:font-size (js/parseFloat (or (:font-size attrs) 16))}))) ; FIXME
113+
(when system/electron?
114+
(defmethod hierarchy/path :text
115+
[{:keys [attrs content]}]
116+
117+
(let [font-descriptor #js {:family (:font-family attrs)
118+
:weight (js/parseInt (:font-weight attrs))
119+
:italic (= (:font-style attrs) "italic")}]
120+
(.textToPath
121+
js/window.api
122+
content
123+
#js {:font-url (.-path (.findFont js/window.api font-descriptor))
124+
:x (js/parseFloat (:x attrs))
125+
:y (js/parseFloat (:y attrs))
126+
:font-size (js/parseFloat (or (:font-size attrs) 16))})))) ; FIXME

src/renderer/window/effects.cljs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns renderer.window.effects
22
(:require
33
[re-frame.core :as rf]
4-
[renderer.notification.events :as-alias notification.e]))
4+
[renderer.notification.events :as-alias notification.e]
5+
[renderer.utils.system :as system]))
56

67
(rf/reg-fx
78
::close
@@ -28,11 +29,13 @@
2829
(rf/reg-fx
2930
::ipc-send
3031
(fn [[channel data]]
31-
(js/window.api.send channel (clj->js data))))
32+
(when system/electron?
33+
(js/window.api.send channel (clj->js data)))))
3234

3335
(rf/reg-fx
3436
::ipc-invoke
3537
(fn [{:keys [channel data formatter on-success on-error]}]
36-
(-> (js/window.api.invoke channel (clj->js data))
37-
(.then #(when on-success (rf/dispatch (conj on-success (cond-> % formatter formatter)))))
38-
(.catch #(when on-error (rf/dispatch (conj on-error %)))))))
38+
(when system/electron?
39+
(-> (js/window.api.invoke channel (clj->js data))
40+
(.then #(when on-success (rf/dispatch (conj on-success (cond-> % formatter formatter)))))
41+
(.catch #(when on-error (rf/dispatch (conj on-error %))))))))

0 commit comments

Comments
 (0)