From 8dc54ac856616d39167aa4fcff02d5a662800fbf Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Sat, 16 Nov 2024 11:08:38 +0200 Subject: [PATCH] use node fs promises to write file --- src/electron/file.cljs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/electron/file.cljs b/src/electron/file.cljs index 188749d0..8fd8f542 100644 --- a/src/electron/file.cljs +++ b/src/electron/file.cljs @@ -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] @@ -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]