|
9 | 9 | [renderer.dialog.handlers :as dialog.h]
|
10 | 10 | [renderer.dialog.views :as dialog.v]
|
11 | 11 | [renderer.document.db :as db]
|
| 12 | + [renderer.document.effects :as-alias fx] |
12 | 13 | [renderer.document.handlers :as h]
|
13 | 14 | [renderer.element.handlers :as element.h]
|
14 | 15 | [renderer.history.handlers :as history.h]
|
| 16 | + [renderer.notification.events :as notification.e] |
15 | 17 | [renderer.notification.handlers :as notification.h]
|
16 | 18 | [renderer.notification.views :as notification.v]
|
17 | 19 | [renderer.snap.handlers :as snap.h]
|
|
169 | 171 | (if system/electron?
|
170 | 172 | {::window.fx/ipc-invoke {:channel "open-documents"
|
171 | 173 | :data file-path
|
172 |
| - :on-resolution ::load-multiple |
| 174 | + :on-success [::load-multiple] |
| 175 | + :on-error [::notification.e/exception] |
173 | 176 | :formatter #(mapv edn/read-string %)}}
|
174 |
| - {::app.fx/open {:options file-picker-options |
175 |
| - :on-resolution ::load |
176 |
| - :formatter #(-> (edn/read-string %) |
177 |
| - (assoc :title (.-name %) |
178 |
| - :path (.-path %)))}}))) |
| 177 | + {::app.fx/file-open {:options file-picker-options |
| 178 | + :on-success [::file-read] |
| 179 | + :on-error [::file-error]}}))) |
| 180 | + |
| 181 | +(rf/reg-event-fx |
| 182 | + ::file-read |
| 183 | + (fn [_ [_ file]] |
| 184 | + {::fx/read file})) |
| 185 | + |
| 186 | +(rf/reg-event-fx |
| 187 | + ::file-error |
| 188 | + (fn [{:keys [db]} [_ ^js/Error error]] |
| 189 | + (cond-> db |
| 190 | + (not= (.-name error) "AbortError") |
| 191 | + (notification.h/add (notification.v/exception error))))) |
179 | 192 |
|
180 | 193 | (rf/reg-event-fx
|
181 | 194 | ::open-directory
|
|
212 | 225 | (if system/electron?
|
213 | 226 | {::window.fx/ipc-invoke {:channel "save-document"
|
214 | 227 | :data (pr-str document)
|
215 |
| - :on-resolution ::saved |
| 228 | + :on-success [::saved] |
| 229 | + :on-error [::notification.e/exception] |
216 | 230 | :formatter edn/read-string}}
|
217 |
| - {::app.fx/save {:data (h/save-format document) |
218 |
| - :options file-picker-options |
219 |
| - :formatter (fn [file] {:id (:id document) |
220 |
| - :title (.-name file)}) |
221 |
| - :on-resolution ::saved}})))) |
| 231 | + {::app.fx/file-save {:data (h/save-format document) |
| 232 | + :options file-picker-options |
| 233 | + :formatter (fn [file] {:id (:id document) |
| 234 | + :title (.-name file)}) |
| 235 | + :on-success [::saved] |
| 236 | + :on-error [::file-error]}})))) |
222 | 237 |
|
223 | 238 | (rf/reg-event-fx
|
224 | 239 | ::download
|
|
234 | 249 | (if system/electron?
|
235 | 250 | {::window.fx/ipc-invoke {:channel "save-document"
|
236 | 251 | :data (pr-str document)
|
237 |
| - :on-resolution ::close-saved |
| 252 | + :on-success [::close-saved] |
| 253 | + :on-error [::notification.e/exception] |
238 | 254 | :formatter edn/read-string}}
|
239 |
| - {::app.fx/save {:data (h/save-format document) |
240 |
| - :options file-picker-options |
241 |
| - :formatter (fn [file] {:id id |
242 |
| - :title (.-name file)}) |
243 |
| - :on-resolution ::close-saved}})))) |
| 255 | + {::app.fx/file-save {:data (h/save-format document) |
| 256 | + :options file-picker-options |
| 257 | + :formatter (fn [file] {:id id |
| 258 | + :title (.-name file)}) |
| 259 | + :on-success [::close-saved] |
| 260 | + :on-error [::file-error]}})))) |
244 | 261 |
|
245 | 262 | (rf/reg-event-fx
|
246 | 263 | ::save-as
|
|
249 | 266 | (if system/electron?
|
250 | 267 | {::window.fx/ipc-invoke {:channel "save-document-as"
|
251 | 268 | :data (pr-str document)
|
252 |
| - :on-resolution ::saved |
| 269 | + :on-success [::saved] |
| 270 | + :on-error [::notification.e/exception] |
253 | 271 | :formatter edn/read-string}}
|
254 |
| - {::app.fx/save {:data (h/save-format document) |
255 |
| - :options file-picker-options |
256 |
| - :formatter (fn [file] {:id (:id document) |
257 |
| - :title (.-name file)}) |
258 |
| - :on-resolution ::saved}})))) |
| 272 | + {::app.fx/file-save {:data (h/save-format document) |
| 273 | + :options file-picker-options |
| 274 | + :formatter (fn [file] {:id (:id document) |
| 275 | + :title (.-name file)}) |
| 276 | + :on-success [::saved] |
| 277 | + :on-error [::file-error]}})))) |
259 | 278 |
|
260 | 279 | (rf/reg-event-db
|
261 | 280 | ::saved
|
|
291 | 310 | (-> db
|
292 | 311 | (h/set-active id)
|
293 | 312 | (h/center))))
|
| 313 | + |
0 commit comments