Skip to content

Commit

Permalink
use node fs promises to write file
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Nov 16, 2024
1 parent 8846a58 commit 8dc54ac
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/electron/file.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
(defn- write-file!
[file-path data]
(let [document (pr-str (dissoc data :path :id :title))]
(.writeFileSync fs file-path document "utf-8")
(-> (select-keys data [:id])
(serialize-document file-path)
(js/Promise.resolve))))
(-> (.writeFile fs/promises file-path document "utf-8")
(.then #(-> (select-keys data [:id])
(serialize-document file-path))))))

(defn- read!
[file-path]
Expand Down Expand Up @@ -85,10 +84,7 @@
(-> (save-dialog! export-options)
(.then (fn [file-path]
(when file-path
(.writeFile fs file-path data "utf-8" (fn [error]
(if error
(js/Promise.reject error)
(js/Promise.resolve data)))))))))
(.writeFile fs/promises file-path data "utf-8"))))))

(defn print!
[content]
Expand Down

0 comments on commit 8dc54ac

Please sign in to comment.