enhance: don't overwrite logseq's file if changes from journal file

is empty or the default template content.

To prevent overwritten when using iCloud/OneDrive/GDrive.
pull/2830/head 0.3.9
Tienson Qin 2021-09-15 21:47:05 +08:00
parent f5cdfaa2f1
commit f59f59b9ae
3 changed files with 21 additions and 18 deletions

View File

@ -9,7 +9,8 @@
[frontend.handler.file :as file-handler]
[lambdaisland.glogi :as log]
[electron.ipc :as ipc]
[promesa.core :as p]))
[promesa.core :as p]
[frontend.state :as state]))
(defn- set-missing-block-ids!
[content]
@ -46,17 +47,24 @@
(and (= "change" type)
(not= (string/trim content) (string/trim db-content))
(not (string/includes? path "logseq/pages-metadata.edn")))
(p/let [
;; save the previous content in Logseq first and commit it to avoid
;; any data-loss.
_ (file-handler/alter-file repo path db-content {:re-render-root? false
:reset? false
:skip-compare? true})
_ (ipc/ipc "gitCommitAll" "Save the file from Logseq's database")
_ (file-handler/alter-file repo path content {:re-render-root? true
:skip-compare? true})]
(set-missing-block-ids! content)
(db/set-file-last-modified-at! repo path mtime))
(when-not (and
(string/includes? path (str "/" (config/get-journals-directory) "/"))
(or
(= (string/trim content)
(string/trim (or (state/get-default-journal-template) "")))
(= (string/trim content) "-")
(= (string/trim content) "*")))
(p/let [
;; save the previous content in Logseq first and commit it to avoid
;; any data-loss.
_ (file-handler/alter-file repo path db-content {:re-render-root? false
:reset? false
:skip-compare? true})
_ (ipc/ipc "gitCommitAll" "Save the file from Logseq's database")
_ (file-handler/alter-file repo path content {:re-render-root? true
:skip-compare? true})]
(set-missing-block-ids! content)
(db/set-file-last-modified-at! repo path mtime)))
(contains? #{"add" "change" "unlink"} type)
nil

View File

@ -100,7 +100,7 @@
title (date/today)
file-name (date/journal-title->default title)
default-content (util/default-content-with-title format)
template (state/get-journal-template)
template (state/get-default-journal-template)
template (when (and template
(not (string/blank? template)))
template)

View File

@ -969,11 +969,6 @@
([path]
(get-in @state [:ui/paths-scroll-positions path] 0)))
(defn get-journal-template
[]
(when-let [repo (get-current-repo)]
(get-in @state [:config repo :default-templates :journals])))
(defn set-today!
[value]
(set-state! :today value))