fix: drag files to logseq can be stuck

This commit is contained in:
Tienson Qin
2021-05-22 14:45:06 +08:00
parent bf60e6b011
commit 04a6ec4658
6 changed files with 127 additions and 105 deletions

View File

@@ -106,9 +106,9 @@
(d/listen! conn :persistence
(fn [tx-report]
(when-not (util/electron?)
(let [tx-id (get-tx-id tx-report)]
(state/set-last-transact-time! repo (util/time-ms))
(persist-if-idle! repo)))
(let [tx-id (get-tx-id tx-report)]
(state/set-last-transact-time! repo (util/time-ms))
(persist-if-idle! repo)))
;; rebuild search indices
(let [data (:tx-data tx-report)

View File

@@ -23,7 +23,9 @@
(when-not (db/file-exists? repo path)
(let [_ (file-handler/alter-file repo path content {:re-render-root? true
:from-disk? true})]
(db/set-file-last-modified-at! repo path mtime)))
(db/set-file-last-modified-at! repo path mtime)
;; return nil, otherwise the entire db will be transfered by ipc
nil))
(and (= "change" type)
(not (db/file-exists? repo path)))
@@ -34,7 +36,8 @@
(> mtime last-modified-at)))
(let [_ (file-handler/alter-file repo path content {:re-render-root? true
:from-disk? true})]
(db/set-file-last-modified-at! repo path mtime))
(db/set-file-last-modified-at! repo path mtime)
nil)
(contains? #{"add" "change" "unlink"} type)
nil

View File

@@ -42,27 +42,29 @@
(defn- ->db-files
[electron? dir-name result]
(if electron?
(map (fn [{:keys [path stat content]}]
(let [{:keys [mtime size]} stat]
{:file/path path
:file/last-modified-at mtime
:file/size size
:file/content content}))
result)
(let [result (flatten (bean/->clj result))]
(map (fn [file]
(let [handle (gobj/get file "handle")
get-attr #(gobj/get file %)
path (-> (get-attr "webkitRelativePath")
(string/replace-first (str dir-name "/") ""))]
{:file/name (get-attr "name")
:file/path path
:file/last-modified-at (get-attr "lastModified")
:file/size (get-attr "size")
:file/type (get-attr "type")
:file/file file
:file/handle handle})) result))))
(->>
(if electron?
(map (fn [{:keys [path stat content]}]
(let [{:keys [mtime size]} stat]
{:file/path path
:file/last-modified-at mtime
:file/size size
:file/content content}))
result)
(let [result (flatten (bean/->clj result))]
(map (fn [file]
(let [handle (gobj/get file "handle")
get-attr #(gobj/get file %)
path (-> (get-attr "webkitRelativePath")
(string/replace-first (str dir-name "/") ""))]
{:file/name (get-attr "name")
:file/path path
:file/last-modified-at (get-attr "lastModified")
:file/size (get-attr "size")
:file/type (get-attr "type")
:file/file file
:file/handle handle})) result)))
(sort-by :file/path)))
(defn- filter-markup-and-built-in-files
[files]