浏览代码

feat(electron): fix fs watcher ignored

Also, use rfe for links
Tienson Qin 4 年之前
父节点
当前提交
df7ca4995e

+ 3 - 1
src/electron/electron/handler.cljs

@@ -80,7 +80,9 @@
   [win dir]
   (let [watcher (.watch watcher dir
                         (clj->js
-                         {:ignored #"^\.|/assets/" ; FIXME read .gitignore and other ignore paths
+                         {:ignored (fn [path]
+                                     (some #(string/starts-with? path (str dir "/" %))
+                                           ["." "assets" "node_modules"]))
                           ;; :ignoreInitial true
                           :persistent true
                           :awaitWriteFinish true}))]

+ 1 - 1
src/main/frontend/components/file.cljs

@@ -71,7 +71,7 @@
   (let [path (get-path state)
         format (format/get-format path)
         page (db/get-file-page path)
-        config? (= path (str config/app-name "/" config/config-file))]
+        config? (= path (config/get-config-path))]
     (rum/with-context [[tongue] i18n/*tongue-context*]
       [:div.file {:id (str "file-" path)}
        [:h1.title

+ 1 - 1
src/main/frontend/components/page.cljs

@@ -202,7 +202,7 @@
          [:ul.mt-2
           (for [[original-name name] pages]
             [:li {:key (str "tagged-page-" name)}
-             [:a {:href (str "/page/" (util/encode-str name))}
+             [:a {:href (rfe/href :page {:name name})}
               original-name]])])]])))
 
 (defonce last-route (atom :home))

+ 1 - 1
src/main/frontend/components/right_sidebar.cljs

@@ -143,7 +143,7 @@
                                                        :slide? true
                                                        :sidebar? true
                                                        :page-name page-name})]
-      [[:a {:href (str "/page/" (util/url-encode page-name))}
+      [[:a {:href {:href (rfe/href :page {:name page-name})}}
         (db-model/get-page-original-name page-name)]
        [:div.ml-2.slide.mt-2
         (slide/slide sections)]])

+ 3 - 2
src/main/frontend/components/settings.cljs

@@ -15,7 +15,8 @@
             [frontend.dicts :as dicts]
             [clojure.string :as string]
             [goog.object :as gobj]
-            [frontend.context.i18n :as i18n]))
+            [frontend.context.i18n :as i18n]
+            [reitit.frontend.easy :as rfe]))
 
 (rum/defcs set-email < (rum/local "" ::email)
   [state]
@@ -176,7 +177,7 @@
        [:div.pl-1
                         ;; config.edn
         (when current-repo
-          [:a {:href (str "/file/" (util/url-encode (str config/app-name "/" config/config-file)))}
+          [:a {:href (rfe/href :file {:path (config/get-config-path)})}
            (t :settings-page/edit-config-edn)])
 
         [:hr]

+ 21 - 0
src/main/frontend/config.cljs

@@ -319,3 +319,24 @@
   (if (and (util/electron?) (local-db? repo-url))
     path
     (str (get-repo-dir repo-url) "/" path)))
+
+(defn get-file-path
+  [repo-url relative-path]
+  (if (and (util/electron?) (local-db? repo-url))
+    (str (get-repo-dir repo-url) "/" relative-path)
+    relative-path))
+
+(defn get-config-path
+  ([]
+   (get-config-path (state/get-current-repo)))
+  ([repo]
+   (when repo
+     (get-file-path repo (str app-name "/" config-file)))))
+
+(defn get-custom-css-path
+  ([]
+   (get-custom-css-path (state/get-current-repo)))
+  ([repo]
+   (when repo
+     (get-file-path repo
+                    (str app-name "/" custom-css-file)))))

+ 2 - 1
src/main/frontend/db/model.cljs

@@ -258,7 +258,8 @@
 
 (defn get-custom-css
   []
-  (get-file "logseq/custom.css"))
+  (when-let [repo (state/get-current-repo)]
+    (get-file (config/get-file-path repo "logseq/custom.css"))))
 
 (defn get-file-no-sub
   ([path]

+ 2 - 2
src/main/frontend/fs.cljs

@@ -105,8 +105,8 @@
   (let [record (if (util/electron?) node-record nfs-record)]
     (p/let [result (protocol/get-files record path-or-handle ok-handler)]
       (if (util/electron?)
-        (let [[dir & paths] (bean/->clj result)]
-          [(:path dir) paths])
+        (let [result (bean/->clj result)]
+          (rest result))
         result))))
 
 (defn watch-dir!

+ 1 - 1
src/main/frontend/handler/common.cljs

@@ -72,7 +72,7 @@
 
 (defn get-config
   [repo-url]
-  (db/get-file repo-url (str config/app-name "/" config/config-file)))
+  (db/get-file repo-url (config/get-config-path)))
 
 (defn reset-config!
   [repo-url content]

+ 1 - 1
src/main/frontend/handler/config.cljs

@@ -9,7 +9,7 @@
 (defn set-config!
   [k v]
   (when-let [repo (state/get-current-repo)]
-    (let [path (str config/app-name "/" config/config-file)]
+    (let [path (config/get-config-path)]
       (when-let [config (db/get-file-no-sub path)]
         (let [config (try
                        (rewrite/parse-string config)

+ 4 - 3
src/main/frontend/handler/file.cljs

@@ -99,7 +99,8 @@
   (state/set-loading-files! true)
   (p/let [files (git/list-files repo-url)
           files (bean/->clj files)
-          config-content (load-file repo-url (str config/app-name "/" config/config-file))
+          config-content (load-file repo-url
+                                    (config/get-config-path repo-url))
           files (if config-content
                   (let [config (restore-config! repo-url config-content true)]
                     (if-let [patterns (seq (:hidden config))]
@@ -173,9 +174,9 @@
                                                                    :last-modified-at (db/get-file-last-modified-at repo path)})
      (fn [_]
        (git-handler/git-add repo path update-status?)
-       (when (= path (str config/app-name "/" config/config-file))
+       (when (= path (config/get-config-path repo))
          (restore-config! repo true))
-       (when (= path (str config/app-name "/" config/custom-css-file))
+       (when (= path (config/get-custom-css-path repo))
          (ui-handler/add-style-if-exists!))
        (when re-render-root? (ui-handler/re-render-root!))
        (when add-history?

+ 3 - 3
src/main/frontend/handler/repo.cljs

@@ -87,7 +87,7 @@
   [repo-url]
   (spec/validate :repos/url repo-url)
   (let [repo-dir (config/get-repo-dir repo-url)
-        path (str config/app-name "/" config/custom-css-file)
+        path (config/get-custom-css-path)
         file-path (str "/" path)
         default-content ""]
     (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" config/app-name))
@@ -153,7 +153,7 @@
     (when (or (db/cloned? repo)
               (and (config/local-db? repo)
                    ;; config file exists
-                   (let [path (str config/app-name "/" config/config-file)
+                   (let [path (config/get-config-path)
                          path (if (and (util/electron?) (config/local-db? repo))
                                 (str (config/get-repo-dir repo) "/" path)
                                 path)]
@@ -193,7 +193,7 @@
                        (extract-handler/extract-all-blocks-pages repo-url parsed-files)
                        [])]
     (reset-contents-and-blocks! repo-url files blocks-pages delete-files delete-blocks)
-    (let [config-file (str config/app-name "/" config/config-file)]
+    (let [config-file (config/get-config-path)]
       (if (contains? (set file-paths) config-file)
         (when-let [content (some #(when (= (:file/path %) config-file)
                                     (:file/content %)) files)]

+ 38 - 38
src/main/frontend/handler/web/nfs.cljs

@@ -25,13 +25,13 @@
 (defn remove-ignore-files
   [files]
   (let [files (remove (fn [f]
-                        (string/starts-with? (:file/path f) ".git/"))
+                        (or (string/starts-with? (:file/path f) ".git/")
+                            (string/includes? (:file/path f) ".git/")))
                       files)]
     (if-let [ignore-file (some #(when (= (:file/name %) ".gitignore")
                                   %) files)]
       (if-let [file (:file/file ignore-file)]
         (p/let [content (.text file)]
-
           (when content
             (let [paths (set (file-handler/ignore-files content (map :file/path files)))]
               (when (seq paths)
@@ -48,20 +48,20 @@
               :file/last-modified-at mtime
               :file/size             size
               :file/content content}))
-      result)
+         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))))
+             (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))))
 
 (defn- filter-markup-and-built-in-files
   [files]
@@ -124,19 +124,19 @@
                        remove-ignore-files)
              _ (when nfs?
                  (let [file-paths (set (map :file/path files))]
-                  (swap! path-handles (fn [handles]
-                                        (->> handles
-                                             (filter (fn [[path _handle]]
-                                                       (or
-                                                        (contains? file-paths
-                                                                   (string/replace-first path (str dir-name "/") ""))
-                                                        (let [last-part (last (string/split path "/"))]
-                                                          (contains? #{config/app-name
-                                                                       config/default-draw-directory
-                                                                       config/default-journals-directory
-                                                                       config/default-pages-directory}
-                                                                     last-part)))))
-                                             (into {})))))
+                   (swap! path-handles (fn [handles]
+                                         (->> handles
+                                              (filter (fn [[path _handle]]
+                                                        (or
+                                                         (contains? file-paths
+                                                                    (string/replace-first path (str dir-name "/") ""))
+                                                         (let [last-part (last (string/split path "/"))]
+                                                           (contains? #{config/app-name
+                                                                        config/default-draw-directory
+                                                                        config/default-journals-directory
+                                                                        config/default-pages-directory}
+                                                                      last-part)))))
+                                              (into {})))))
 
                  (set-files! @path-handles))
              markup-files (filter-markup-and-built-in-files files)]
@@ -177,10 +177,10 @@
         "Grant native filesystem permission for directory: "
         [:b (config/get-local-dir repo)]]
        (ui/button
-         "Grant"
-         :on-click (fn []
-                     (nfs/check-directory-permission! repo)
-                     (close-fn)))])))
+        "Grant"
+        :on-click (fn []
+                    (nfs/check-directory-permission! repo)
+                    (close-fn)))])))
 
 (defn ask-permission-if-local? []
   (when-let [repo (get-local-repo)]
@@ -276,16 +276,16 @@
                                                (fn [path handle]
                                                  (when nfs?
                                                    (swap! path-handles assoc path handle))))
-                    new-files (-> (->db-files electron? dir-name (second files-result))
+                    new-files (-> (->db-files electron? dir-name files-result)
                                   remove-ignore-files)
                     _ (when nfs?
                         (let [file-paths (set (map :file/path new-files))]
-                         (swap! path-handles (fn [handles]
-                                               (->> handles
-                                                    (filter (fn [[path _handle]]
-                                                              (contains? file-paths
-                                                                         (string/replace-first path (str dir-name "/") ""))))
-                                                    (into {})))))
+                          (swap! path-handles (fn [handles]
+                                                (->> handles
+                                                     (filter (fn [[path _handle]]
+                                                               (contains? file-paths
+                                                                          (string/replace-first path (str dir-name "/") ""))))
+                                                     (into {})))))
                         (set-files! @path-handles))]
               (handle-diffs! repo nfs? old-files new-files handle-path path-handles re-index?))))
         (p/catch (fn [error]