Kaynağa Gözat

fix: delete page if its file was deleted

close #2962
Tienson Qin 4 yıl önce
ebeveyn
işleme
45af02ee2a

+ 5 - 5
src/electron/electron/fs_watcher.cljs

@@ -50,11 +50,11 @@
                                   :path (utils/fix-win-path! path)
                                   :content (utils/read-file path)
                                   :stat (fs/statSync path)})))
-      ;; (.on watcher "unlink"
-      ;;      (fn [path]
-      ;;        (send-file-watcher! win "unlink"
-      ;;                            {:dir (utils/fix-win-path! dir)
-      ;;                             :path (utils/fix-win-path! path)})))
+      (.on watcher "unlink"
+           (fn [path]
+             (send-file-watcher! win "unlink"
+                                 {:dir (utils/fix-win-path! dir)
+                                  :path (utils/fix-win-path! path)})))
       (.on watcher "error"
            (fn [path]
              (println "Watch error happened: "

+ 8 - 1
src/main/frontend/fs/watcher_handler.cljs

@@ -7,6 +7,7 @@
             [frontend.handler.editor :as editor]
             [frontend.handler.extract :as extract]
             [frontend.handler.file :as file-handler]
+            [frontend.handler.page :as page-handler]
             [lambdaisland.glogi :as log]
             [electron.ipc :as ipc]
             [promesa.core :as p]
@@ -30,7 +31,7 @@
     (let [repo (config/get-local-repo dir)
           {:keys [mtime]} stat
           db-content (or (db/get-file repo path) "")]
-      (when (and content
+      (when (and (or content (= type "unlink"))
                  (not (encrypt/content-encrypted? content))
                  (not (:encryption/graph-parsing? @state/state)))
         (cond
@@ -64,6 +65,12 @@
               (set-missing-block-ids! content)
               (db/set-file-last-modified-at! repo path mtime)))
 
+          (and (= "unlink" type)
+               (db/file-exists? repo path))
+          (when-let [page-name (db/get-file-page path)]
+            (println "Delete page: " page-name ", file path: " path ".")
+            (page-handler/delete! page-name #()))
+
           (contains? #{"add" "change" "unlink"} type)
           nil