diff --git a/src/main/frontend/fs/watcher_handler.cljs b/src/main/frontend/fs/watcher_handler.cljs index 83e1d53fce..84e3f41231 100644 --- a/src/main/frontend/fs/watcher_handler.cljs +++ b/src/main/frontend/fs/watcher_handler.cljs @@ -13,7 +13,8 @@ [frontend.encrypt :as encrypt] [frontend.db.model :as model] [frontend.handler.editor :as editor] - [frontend.handler.extract :as extract])) + [frontend.handler.extract :as extract] + [promesa.core :as p])) (defn- set-missing-block-ids! [content] @@ -36,8 +37,8 @@ (cond (= "add" type) (when-not (db/file-exists? repo path) - (let [_ (file-handler/alter-file repo path content {:re-render-root? true - :from-disk? true})] + (p/let [_ (file-handler/alter-file repo path content {:re-render-root? true + :from-disk? true})] (set-missing-block-ids! content) (db/set-file-last-modified-at! repo path mtime) ;; return nil, otherwise the entire db will be transfered by ipc @@ -50,8 +51,8 @@ (and (= "change" type) (when-let [last-modified-at (db/get-file-last-modified-at repo path)] (> mtime last-modified-at))) - (let [_ (file-handler/alter-file repo path content {:re-render-root? true - :from-disk? true})] + (p/let [_ (file-handler/alter-file repo path content {:re-render-root? true + :from-disk? true})] (set-missing-block-ids! content) (db/set-file-last-modified-at! repo path mtime) nil) diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 013b50458b..3b13f6c08f 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -169,27 +169,27 @@ write-file! (if from-disk? #(p/resolved nil) #(fs/write-file! repo (config/get-repo-dir repo) path content (when original-content {:old-content original-content})))] - (if reset? - (do - (when-let [page-id (db/get-file-page-id path)] - (db/transact! repo - [[:db/retract page-id :block/alias] - [:db/retract page-id :block/tags]])) - (reset-file! repo path content)) - (db/set-file-content! repo path content)) - (util/p-handle (write-file!) - (fn [_] - (when (= path (config/get-config-path repo)) - (restore-config! repo true)) - (when (= path (config/get-custom-css-path repo)) - (ui-handler/add-style-if-exists!)) - (when re-render-root? (ui-handler/re-render-root!)) - ;; (when (and add-history? original-content) - ;; (history/add-history! repo [[path original-content content]])) - ) - (fn [error] - (println "Write file failed, path: " path ", content: " content) - (log/error :write/failed error))))) + (p/let [_ (if reset? + (do + (when-let [page-id (db/get-file-page-id path)] + (db/transact! repo + [[:db/retract page-id :block/alias] + [:db/retract page-id :block/tags]])) + (reset-file! repo path content)) + (db/set-file-content! repo path content))] + (util/p-handle (write-file!) + (fn [_] + (when (= path (config/get-config-path repo)) + (restore-config! repo true)) + (when (= path (config/get-custom-css-path repo)) + (ui-handler/add-style-if-exists!)) + (when re-render-root? (ui-handler/re-render-root!)) + ;; (when (and add-history? original-content) + ;; (history/add-history! repo [[path original-content content]])) + ) + (fn [error] + (println "Write file failed, path: " path ", content: " content) + (log/error :write/failed error)))))) (defn set-file-content! [repo path new-content]