mirror of https://github.com/logseq/logseq
fix: close file watcher when exit the app
parent
10e7a9fbd6
commit
e0baf4b05c
|
@ -7,6 +7,7 @@
|
|||
[clojure.string :as string]
|
||||
[promesa.core :as p]
|
||||
[cljs-bean.core :as bean]
|
||||
[electron.fs-watcher :as fs-watcher]
|
||||
["fs-extra" :as fs]
|
||||
["path" :as path]
|
||||
["os" :as os]
|
||||
|
@ -245,6 +246,7 @@
|
|||
|
||||
(.on app "window-all-closed" (fn []
|
||||
(try
|
||||
(fs-watcher/close-watcher!)
|
||||
(search/close!)
|
||||
(catch js/Error e
|
||||
(js/console.error e)))
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
;; 1. https://github.com/Axosoft/nsfw
|
||||
|
||||
(defonce polling-interval 5000)
|
||||
(defonce file-watcher (atom nil))
|
||||
|
||||
(defonce file-watcher-chan "file-watcher")
|
||||
(defn send-file-watcher! [^js win type payload]
|
||||
|
@ -31,8 +32,9 @@
|
|||
:binaryInterval polling-interval
|
||||
:persistent true
|
||||
:disableGlobbing true
|
||||
|
||||
:usePolling false
|
||||
:awaitWriteFinish true}))]
|
||||
(reset! file-watcher watcher)
|
||||
;; TODO: batch sender
|
||||
(.on watcher "add"
|
||||
(fn [path]
|
||||
|
@ -61,3 +63,8 @@
|
|||
(.on app "quit" #(.close watcher))
|
||||
|
||||
true)))
|
||||
|
||||
(defn close-watcher!
|
||||
[]
|
||||
(when-let [watcher @file-watcher]
|
||||
(.close watcher)))
|
||||
|
|
|
@ -49,10 +49,7 @@
|
|||
(js/console.warn "Can't get file in the db: " path)
|
||||
|
||||
(and (= "change" type)
|
||||
;; ignore truncate
|
||||
(not (string/blank? content))
|
||||
(not= (string/trim content)
|
||||
(string/trim (or (db/get-file repo path) ""))))
|
||||
(not= (string/trim content) (string/trim db-content)))
|
||||
(p/let [_ (file-handler/alter-file repo path content {:re-render-root? true
|
||||
:from-disk? true})]
|
||||
(set-missing-block-ids! content)
|
||||
|
|
Loading…
Reference in New Issue