Jelajahi Sumber

Merge remote-tracking branch 'upstream/master' into whiteboards

Peng Xiao 3 tahun lalu
induk
melakukan
734d9fcdb1

+ 5 - 3
.github/workflows/build-desktop-release.yml

@@ -122,9 +122,10 @@ jobs:
 
       - name: Set Build Environment Variables (only when workflow_dispath)
         if: ${{ github.event_name == 'workflow_dispatch' }}
+        # if scheduled, use default settings
         run: |
-          echo "ENABLE_PLUGINS=${{ github.event.inputs.enable-plugins }}" >> $GITHUB_ENV
-          echo "ENABLE_FILE_SYNC_PRODUCTION=${{ github.event.inputs.enable-file-sync-production }}" >> $GITHUB_ENV
+          echo "ENABLE_PLUGINS=${{ github.event_name == 'schedule' || github.event.inputs.enable-plugins == 'true' }}" >> $GITHUB_ENV
+          echo "ENABLE_FILE_SYNC_PRODUCTION=${{ github.event_name == 'schedule' || github.event.inputs.enable-file-sync-production == 'true' }}" >> $GITHUB_ENV
 
       - name: Compile CLJS
         run: yarn install && gulp build && yarn cljs:release-electron
@@ -426,7 +427,8 @@ jobs:
     if: ${{ github.event_name == 'schedule' || github.event.inputs.build-android == 'true' }}
     with:
       build-target: "${{ github.event.inputs.build-target }}"
-      enable-file-sync-production: "${{ github.event.inputs.enable-file-sync-production == 'true' }}"
+      # if scheduled, use production mode
+      enable-file-sync-production: "${{ github.event_name == 'schedule' || github.event.inputs.enable-file-sync-production == 'true' }}"
     secrets:
       ANDROID_KEYSTORE: "${{ secrets.ANDROID_KEYSTORE }}"
       ANDROID_KEYSTORE_PASSWORD: "${{ secrets.ANDROID_KEYSTORE_PASSWORD }}"

+ 6 - 5
src/electron/electron/url.cljs

@@ -8,16 +8,17 @@
 
 ;; Keep same as main/frontend.util.url
 (def decode js/decodeURI)
-(def decode-param js/decodeURIComponent)
 
 (defn get-URL-decoded-params
   "Get decoded URL parameters from parsed js/URL.
-   `nil` for non-existing keys."
-  [^js parsed-url keys]
+   `nil` for non-existing keys.
+   URL.searchParams are already decoded:
+   https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams"
+  [^js/URL parsed-url keys]
   (let [params (.-searchParams parsed-url)]
     (map (fn [key]
            (when-let [value (.get params key)]
-             (decode-param value)))
+             value))
          keys)))
 
 (defn graph-identifier-error-handler
@@ -59,7 +60,7 @@
 
 (defn- x-callback-url-handler
   "win - a window used for fallback (main window is prefered)"
-  [^js win parsed-url]
+  [^js win ^js/URL parsed-url]
   (let [action (.-pathname parsed-url)]
     (cond
       (= action "/quickCapture")

+ 23 - 35
src/main/frontend/fs/sync.cljs

@@ -37,7 +37,6 @@
 ;; - logseq/version-files
 ;;   downloaded version-files
 ;; files included by `get-ignored-files` will not be synchronized.
-;; files in these `get-monitored-dirs` dirs will be synchronized.
 ;;
 ;; sync strategy:
 ;; - when toggle file-sync on,
@@ -153,23 +152,22 @@
 
 ;;; ### configs in config.edn
 ;; - :file-sync/ignore-files
-;; - :file-sync/monitor-dirs
 
 (defn- get-ignored-files
   []
   (into #{#"logseq/graphs-txid.edn$"
-          #"logseq/\.recycle/.*"
-          #"logseq/version-files/.*"
-          #"logseq/bak/.*"}
+          #"logseq/version-files/"
+          #"logseq/bak/"
+          #"node_modules/"
+          ;; path starts with `.` in the root directory, e.g. .gitignore
+          #"^\.[^.]+"
+          ;; path includes `/.`, e.g. .git, .DS_store
+          #"/\."
+          ;; Emacs/Vim backup files end with `~` by default
+          #"~$"}
         (map re-pattern)
         (:file-sync/ignore-files (state/get-config))))
 
-(defn- get-monitor-dirs
-  []
-  (into #{#"^assets/" #"^journals/" #"^logseq/" #"^pages/" #"^draws/" #"^whiteboards/"}
-        (map #(re-pattern (str "^" % "/")))
-        (:file-sync/monitor-dirs (state/get-config))))
-
 ;;; ### configs ends
 
 (def ws-addr config/WS-URL)
@@ -354,9 +352,6 @@
                "\" (updated? " updated? ", renamed? " (.renamed? coll) ", deleted? " deleted?
                ", txid " txid ", checksum " checksum ")]")))
 
-(defn- contains-path? [regexps path]
-  (reduce #(when (re-find %2 path) (reduced true)) false regexps))
-
 (defn- assert-filetxns
   [filetxns]
   (every? true?
@@ -441,16 +436,16 @@
             (map list ts))))
    cat))
 
-(defn- filter-filetxns-by-config
-  "return transducer.
-  filter filetxns by `get-ignored-files` and `get-monitored-dirs`"
-  []
-  (let [ignored-files (get-ignored-files)
-        monitored-dirs (get-monitor-dirs)]
-    (filter
-     #(let [path (relative-path %)]
-        (and (contains-path? monitored-dirs path)
-             (not (contains-path? ignored-files path)))))))
+(defn- contains-path? [regexps path]
+  (reduce #(when (re-find %2 path) (reduced true)) false regexps))
+
+(defn ignored?
+  "Whether file is ignored when syncing."
+  [path]
+  (->
+   (get-ignored-files)
+   (contains-path? (relative-path path))
+   (boolean)))
 
 (defn- diffs->partitioned-filetxns
   "transducer.
@@ -465,7 +460,7 @@
   (comp
    (map diff->filetxns)
    cat
-   (filter-filetxns-by-config)
+   (remove ignored?)
    distinct-update-filetxns-xf
    remove-deleted-filetxns-xf
    (partition-filetxns n)))
@@ -2172,8 +2167,7 @@
                    true)
                  (or (string/starts-with? (.-dir e) base-path)
                      (string/starts-with? (str "file://" (.-dir e)) base-path)) ; valid path prefix
-                 (not (contains-path? (get-ignored-files) (relative-path e))) ;not ignored
-                 (contains-path? (get-monitor-dirs) (relative-path e)) ; dir is monitored
+                 (not (ignored? e)) ;not ignored
                  ;; download files will also trigger file-change-events, ignore them
                  (let [r (not (contains? (:recent-remote->local-files @*sync-state)
                                          (<! (<file-change-event=>recent-remote->local-file-item e))))]
@@ -2220,10 +2214,9 @@
       (if (empty? es)
         (go {:succ true})
         (let [type          (.-type ^FileChangeEvent (first es))
-              ignored-files (get-ignored-files)
               es->paths-xf  (comp
                              (map #(relative-path %))
-                             (filter #(not (contains-path? ignored-files %))))]
+                             (remove ignored?))]
           (go
             (let [es*   (<! (<filter-checksum-not-consistent es))
                   _     (when (not= (count es*) (count es))
@@ -2295,18 +2288,13 @@
             (let [remote-all-files-meta remote-all-files-meta-or-exp
                   local-all-files-meta  (<! local-all-files-meta-c)
                   diff-local-files      (diff-file-metadata-sets local-all-files-meta remote-all-files-meta)
-                  monitored-dirs        (get-monitor-dirs)
-                  ignored-files         (get-ignored-files)
                   change-events
                   (sequence
                    (comp
                     ;; convert to FileChangeEvent
                     (map #(->FileChangeEvent "change" base-path (.get-normalized-path ^FileMetadata %)
                                              {:size (:size %)} (:etag %)))
-                    ;; filter ignore-files & monitored-dirs
-                    (filter #(let [path (relative-path %)]
-                               (and (not (contains-path? ignored-files path))
-                                    (contains-path? monitored-dirs path)))))
+                    (remove ignored?))
                    diff-local-files)
                   change-events-partitions
                   (sequence

+ 22 - 0
src/test/frontend/fs/sync_test.cljs

@@ -0,0 +1,22 @@
+(ns frontend.fs.sync-test
+  (:require [frontend.fs.sync :as sync]
+            [clojure.test :refer [deftest are]]))
+
+(deftest ignored?
+  []
+  (are [x y] (= y (sync/ignored? x))
+    ".git" true
+    ".gitignore" true
+    ".DS_store" true
+    "foo/.DS_store" true
+    "logseq/graphs-txid.edn" true
+    "logseq/version-files/1.md" true
+    "logseq/bak/1.md" true
+    "node_modules/test" true
+    "foo/node_modules/" true
+    "backup~" true
+    "foo/backup~" true
+    "foo/.test.md" true
+    "pages/test.md" false
+    "journals/2022_01_01.md" false
+    ))

+ 1 - 9
templates/config.edn

@@ -272,16 +272,8 @@
  ;;  :media "[[quick capture]] **{time}**: {url}"}
 
  ;; File sync options
-
- ;; In addition to those directories created by Logseq,
- ;; files specified in the `:file-sync/monitor-dirs` directories will be synchronized too.
- ;;
- ;; Directories created by Logseq include:
- ;; ["assets" "journals" "logseq" "pages" "draws"].
- :file-sync/monitor-dirs []
-
  ;; Ignore these files when syncing, regexp is supported.
- :file-sync/ignore-files [".DS_Store$"]
+ ;; :file-sync/ignore-files []
 
  ;; dwim (do what I mean) for Enter key when editing.
  ;; Context-awareness of Enter key makes editing more easily