浏览代码

fix: keeping ask for permissions for nfs graphs

Also, simplify the code a bit.
Tienson Qin 4 年之前
父节点
当前提交
5c30e0b47e

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

@@ -137,8 +137,9 @@
                  (let [message (bean/->clj args-js)]
                    (bean/->js (handle window message)))
                  (catch js/Error e
-                   (println "IPC error: " {:event event
-                                           :args args-js}
-                            e)
+                   (when-not (contains? #{"mkdir" "stat"} (nth args-js 0))
+                     (println "IPC error: " {:event event
+                                            :args args-js}
+                             e))
                    e))))
     #(.removeHandler ipcMain main-channel)))

+ 3 - 2
src/main/frontend/db.cljs

@@ -50,10 +50,11 @@
   get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references
   get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
   journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
-  set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages page-empty? get-alias-source-page]
+  set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages page-empty? get-alias-source-page
+  set-file-content!]
 
  [frontend.db.react
-  get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value
+  get-current-marker get-current-page get-current-priority get-handler-keys set-key-value
   transact-react! remove-key! remove-q! remove-query-component! add-q! add-query-component! clear-query-state!
   clear-query-state-without-refs-and-embeds! get-block-blocks-cache-atom get-page-blocks-cache-atom kv q
   query-state query-components query-entity-in-component remove-custom-query! set-new-result! sub-key-value]

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

@@ -343,7 +343,7 @@
 (defn sort-blocks
   [blocks]
   (let [pages-ids (map (comp :db/id :block/page) blocks)
-        pages (db-utils/pull-many '[:db/id :page/last-modified-at :page/name :page/original-name] pages-ids)
+        pages (db-utils/pull-many '[:db/id :page/name :page/original-name] pages-ids)
         pages-map (reduce (fn [acc p] (assoc acc (:db/id p) p)) {} pages)
         blocks (map
                 (fn [block]
@@ -1189,3 +1189,17 @@
         tx-data (map (fn [page-id] [:db/retract page-id :page/alias]) page-ids)]
     (when (seq tx-data)
       (db-utils/transact! repo tx-data))))
+
+(defn set-file-content!
+  [repo path content]
+  (when (and repo path)
+    (let [tx-data {:file/path path
+                   :file/content content}
+          tx-data (if (config/local-db? repo)
+                    (dissoc tx-data :file/last-modified-at)
+                    tx-data)]
+      (react/transact-react!
+       repo
+       [tx-data]
+       {:key [:file/content path]
+        :files-db? true}))))

+ 0 - 17
src/main/frontend/db/react.cljs

@@ -339,20 +339,3 @@
      (-> (q repo-url [:kv key] {} key key)
          react
          key))))
-
-(defn set-file-content!
-  [repo path content]
-  (when (and repo path)
-    (let [tx-data {:file/path path
-                   :file/content content}
-          tx-data (if (config/local-db? repo)
-                    (dissoc tx-data :file/last-modified-at)
-                    tx-data)]
-      (transact-react!
-       repo
-       [tx-data]
-       {:key [:file/content path]
-        :files-db? true}))
-    (d/transact! (conn/get-conn repo false)
-                 [{:file/path path
-                   :file/last-modified-at (util/time-ms)}])))

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

@@ -35,8 +35,7 @@
 (defn group-by-page
   [blocks]
   (some->> blocks
-           (group-by :block/page)
-           (sort-by (fn [[p _blocks]] (:page/last-modified-at p)) >)))
+           (group-by :block/page)))
 
 (defn get-tx-id [tx-report]
   (get-in tx-report [:tempids :db/current-tx]))

+ 0 - 2
src/main/frontend/db_schema.cljs

@@ -49,8 +49,6 @@
                      :db/cardinality :db.cardinality/many}
    :page/journal?   {}
    :page/journal-day {}
-   :page/created-at {}
-   :page/last-modified-at {}
 
    ;; block
    :block/uuid   {:db/unique      :db.unique/identity}

+ 4 - 101
src/main/frontend/handler/dnd.cljs

@@ -277,22 +277,13 @@
                              bottom-area))
           after-blocks (->> (compute-after-blocks-in-same-file repo target-block to-block direction top? nested? target-child? target-file original-top-block-start-pos block-changes)
                             (remove nil?))
-          path (:file/path (db/entity repo (:db/id (:block/file to-block))))
-          modified-time (let [modified-at (tc/to-long (t/now))]
-                          (->
-                           [[:db/add (:db/id (:block/page target-block)) :page/last-modified-at modified-at]
-                            [:db/add (:db/id (:block/page to-block)) :page/last-modified-at modified-at]
-                            [:db/add (:db/id (:block/file target-block)) :file/last-modified-at modified-at]
-                            [:db/add (:db/id (:block/file to-block)) :file/last-modified-at modified-at]]
-                           distinct
-                           vec))]
+          path (:file/path (db/entity repo (:db/id (:block/file to-block))))]
       (profile
        "Move block in the same file: "
        (repo-handler/transact-react-and-alter-file!
         repo
         (concat
-         after-blocks
-         modified-time)
+         after-blocks)
         {:key :block/change
          :data block-changes}
         [[path new-file-content]]))
@@ -327,14 +318,6 @@
                                 (utf8/substring to-file-content 0 separate-pos)
                                 target-content
                                 (utf8/substring to-file-content separate-pos))))
-        modified-time (let [modified-at (tc/to-long (t/now))]
-                        (->
-                         [[:db/add (:db/id (:block/page target-block)) :page/last-modified-at modified-at]
-                          [:db/add (:db/id (:block/page to-block)) :page/last-modified-at modified-at]
-                          [:db/add (:db/id (:block/file target-block)) :file/last-modified-at modified-at]
-                          [:db/add (:db/id (:block/file to-block)) :file/last-modified-at modified-at]]
-                         distinct
-                         vec))
         target-after-blocks (rebuild-dnd-blocks repo target-file target-child?
                                                 (get-start-pos target-block)
                                                 block-changes nil {:delete? true})
@@ -363,92 +346,12 @@
       repo
       (concat
        target-after-blocks
-       to-after-blocks
-       modified-time)
+       to-after-blocks)
       {:key :block/change
        :data (conj block-changes target-block)}
       [[target-file-path new-target-file-content]
        [to-file-path new-to-file-content]]))))
 
-(defn- move-block-in-different-repos
-  [target-block-repo to-block-repo target-block to-block top-block bottom-block nested? top? target-child? direction target-content target-file original-top-block-start-pos block-changes]
-  (let [target-file (db/entity target-block-repo (:db/id (:block/file target-block)))
-        target-file-path (:file/path target-file)
-        target-file-content (db/get-file target-block-repo target-file-path)
-        to-file (db/entity to-block-repo (:db/id (:block/file to-block)))
-        to-file-path (:file/path to-file)
-        target-block-end-pos (block-handler/get-block-end-pos-rec target-block-repo target-block)
-        to-block-start-pos (get-start-pos to-block)
-        to-block-end-pos (block-handler/get-block-end-pos-rec to-block-repo to-block)
-        new-target-file-content (utf8/delete! target-file-content
-                                              (get-start-pos target-block)
-                                              target-block-end-pos)
-        to-file-content (utf8/encode (db/get-file to-block-repo to-file-path))
-        new-to-file-content (let [separate-pos (cond nested?
-                                                     (get-end-pos to-block)
-                                                     top?
-                                                     to-block-start-pos
-                                                     :else
-                                                     to-block-end-pos)]
-                              (string/trim
-                               (util/join-newline
-                                (utf8/substring to-file-content 0 separate-pos)
-                                target-content
-                                (utf8/substring to-file-content separate-pos))))
-        target-delete-tx (map (fn [id]
-                                [:db.fn/retractEntity [:block/uuid id]])
-                              (block-handler/get-block-ids target-block))
-        [target-modified-time to-modified-time]
-        (let [modified-at (tc/to-long (t/now))]
-          [[[:db/add (:db/id (:block/page target-block)) :page/last-modified-at modified-at]
-            [:db/add (:db/id (:block/file target-block)) :file/last-modified-at modified-at]]
-           [[:db/add (:db/id (:block/page to-block)) :page/last-modified-at modified-at]
-            [:db/add (:db/id (:block/file to-block)) :file/last-modified-at modified-at]]])
-        target-after-blocks (rebuild-dnd-blocks target-block-repo target-file target-child?
-                                                (get-start-pos target-block)
-                                                block-changes nil {:delete? true})
-        to-after-blocks (cond
-                          top?
-                          (rebuild-dnd-blocks to-block-repo to-file target-child?
-                                              (get-start-pos to-block)
-                                              block-changes
-                                              nil
-                                              {:same-file? false})
-
-                          :else
-                          (let [offset-block-id (if nested?
-                                                  (:block/uuid to-block)
-                                                  (last (block-handler/get-block-ids to-block)))
-                                offset-end-pos (get-end-pos
-                                                (db/entity to-block-repo [:block/uuid offset-block-id]))]
-                            (rebuild-dnd-blocks to-block-repo to-file target-child?
-                                                offset-end-pos
-                                                block-changes
-                                                nil
-                                                {:same-file? false})))]
-    (profile
-     "[Target file] Move block between different files: "
-     (repo-handler/transact-react-and-alter-file!
-      target-block-repo
-      (concat
-       target-delete-tx
-       target-after-blocks
-       target-modified-time)
-      {:key :block/change
-       :data [(dissoc target-block :block/children)]}
-      [[target-file-path new-target-file-content]]))
-
-    (profile
-     "[Destination file] Move block between different files: "
-     (repo-handler/transact-react-and-alter-file!
-      to-block-repo
-      (concat
-       to-after-blocks
-       to-modified-time)
-      {:key :block/change
-       :data [block-changes]}
-      [[to-file-path new-to-file-content]]))))
-
 (defn move-block
   "There can be at least 3 possible situations:
   1. Move a block in the same file (either top-to-bottom or bottom-to-top).
@@ -510,7 +413,7 @@
 
           ;; different repos
           :else
-          (move-block-in-different-repos target-block-repo to-block-repo target-block to-block top-block bottom-block nested? top? target-child? direction target-content target-file original-top-block-start-pos block-changes))
+          nil)
 
         (when (state/get-git-auto-push?)
           (doseq [repo (->> #{target-block-repo to-block-repo}

+ 0 - 1
src/main/frontend/handler/draw.cljs

@@ -72,7 +72,6 @@
                             :file/last-modified-at modified-at}
                            {:page/name file
                             :page/file path
-                            :page/last-modified-at (tc/to-long (t/now))
                             :page/journal? false}])))
          (p/catch (fn [error]
                     (prn "Write file failed, path: " path ", data: " data)

+ 6 - 23
src/main/frontend/handler/editor.cljs

@@ -53,12 +53,6 @@
 (defonce *image-uploading-process (atom 0))
 (defonce *selected-text (atom nil))
 
-(defn modified-time-tx
-  [page file]
-  (let [modified-at (tc/to-long (t/now))]
-    [[:db/add (:db/id page) :page/last-modified-at modified-at]
-     [:db/add (:db/id file) :file/last-modified-at modified-at]]))
-
 (defn- get-selection-and-format
   []
   (when-let [block (state/get-edit-block)]
@@ -556,9 +550,6 @@
                  [after-blocks block-children-content new-end-pos] (rebuild-after-blocks-indent-outdent repo file block (:end-pos (:block/meta block)) end-pos indent-left?)
                  retract-refs (compute-retract-refs (:db/id e) (first blocks) ref-pages ref-blocks)
                  page-id (:db/id page)
-                 modified-time (let [modified-at (tc/to-long (t/now))]
-                                 [[:db/add page-id :page/last-modified-at modified-at]
-                                  [:db/add (:db/id file) :file/last-modified-at modified-at]])
                  page-properties (when pre-block?
                                    (if (seq new-properties)
                                      [[:db/retract page-id :page/properties]
@@ -597,8 +588,7 @@
                 page-properties
                 page-tags
                 page-alias
-                after-blocks
-                modified-time)
+                after-blocks)
                {:key :block/change
                 :data (map (fn [block] (assoc block :block/page page)) blocks)}
                (let [new-content (new-file-content-indent-outdent block file-content value block-children-content new-end-pos indent-left?)]
@@ -1944,15 +1934,12 @@
                                                                 (concat hc2 hc1)])]
                   (when (and start-pos end-pos)
                     (let [new-file-content (utf8/insert! old-file-content start-pos end-pos new-content)
-                          modified-time (modified-time-tx page file)
                           blocks-meta (rebuild-blocks-meta start-pos blocks)]
                       (profile
                        (str "Move block " (if up? "up: " "down: "))
                        (repo-handler/transact-react-and-alter-file!
                         repo
-                        (concat
-                         blocks-meta
-                         modified-time)
+                        blocks-meta
                         {:key :block/change
                          :data (map (fn [block] (assoc block :block/page page)) blocks)}
                         [[file-path new-file-content]])))))))))))))
@@ -2029,16 +2016,14 @@
                 ;;         :last-start-pos @last-start-pos})
                 file-path (:file/path file)
                 file-content (db/get-file file-path)
-                new-content (utf8/insert! file-content start-pos old-end-pos (apply str (map :block/content blocks)))
-                modified-time (modified-time-tx page file)]
+                new-content (utf8/insert! file-content start-pos old-end-pos (apply str (map :block/content blocks)))]
             (profile
              "Indent/outdent: "
              (repo-handler/transact-react-and-alter-file!
               repo
               (concat
                blocks
-               after-blocks
-               modified-time)
+               after-blocks)
               {:key :block/change
                :data (map (fn [block] (assoc block :block/page page)) blocks)}
               [[file-path new-content]])))
@@ -2095,16 +2080,14 @@
               after-blocks (rebuild-after-blocks repo file old-end-pos @last-start-pos)
               file-path (:file/path file)
               file-content (db/get-file file-path)
-              new-content (utf8/insert! file-content start-pos old-end-pos (apply str (map :block/content blocks)))
-              modified-time (modified-time-tx page file)]
+              new-content (utf8/insert! file-content start-pos old-end-pos (apply str (map :block/content blocks)))]
           (profile
            "Indent/outdent: "
            (repo-handler/transact-react-and-alter-file!
             repo
             (concat
              blocks
-             after-blocks
-             modified-time)
+             after-blocks)
             {:key :block/change
              :data (map (fn [block] (assoc block :block/page page)) blocks)}
             [[file-path new-content]])))

+ 1 - 3
src/main/frontend/handler/extract.cljs

@@ -70,9 +70,7 @@
                          :page/journal? journal?
                          :page/journal-day (if journal?
                                              (date/journal-title->int (string/capitalize page))
-                                             0)
-                         :page/created-at journal-date-long
-                         :page/last-modified-at journal-date-long})
+                                             0)})
                         (seq properties)
                         (assoc :page/properties properties)
 

+ 1 - 2
src/main/frontend/handler/file.cljs

@@ -228,8 +228,7 @@
           (db/set-file-content! repo path content))))
 
     (when-let [chan (state/get-file-write-chan)]
-      (let [chan-callback
-            (:chan-callback opts)]
+      (let [chan-callback (:chan-callback opts)]
         (async/put! chan [repo files opts file->content])
         (when chan-callback
           (chan-callback))))))

+ 11 - 14
src/main/frontend/handler/repo.cljs

@@ -173,7 +173,7 @@
 (defn- reset-contents-and-blocks!
   [repo-url files blocks-pages delete-files delete-blocks]
   (db/transact-files-db! repo-url files)
-  (let [files (map #(select-keys % [:file/path]) files)
+  (let [files (map #(select-keys % [:file/path :file/last-modified-at]) files)
         all-data (-> (concat delete-files delete-blocks files blocks-pages)
                      (util/remove-nils))]
     (db/transact! repo-url all-data)))
@@ -328,6 +328,9 @@
                                                     :idx idx
                                                     :container (gobj/get container "id")})))
 
+     (when (seq files)
+       (file-handler/alter-files repo files opts))
+
      (db/transact-react!
       repo
       tx
@@ -335,9 +338,7 @@
      (when (seq pages)
        (let [children-tx (mapcat #(rebuild-page-blocks-children repo %) pages)]
          (when (seq children-tx)
-           (db/transact! repo children-tx))))
-     (when (seq files)
-       (file-handler/alter-files repo files opts)))))
+           (db/transact! repo children-tx)))))))
 
 (declare push)
 
@@ -625,16 +626,12 @@
     (do
       (doseq [{:keys [id url]} (:repos me)]
         (let [repo url]
-          (p/let [config-exists? (fs/file-exists?
-                                  (config/get-repo-dir url)
-                                  ".git/config")]
-            (if (and config-exists?
-                     (db/cloned? repo))
-              (p/do!
-               (git-handler/git-set-username-email! repo me)
-               (pull repo nil))
-              (p/do!
-               (clone-and-load-db repo))))))
+          (if (db/cloned? repo)
+            (p/do!
+             (git-handler/git-set-username-email! repo me)
+             (pull repo nil))
+            (p/do!
+             (clone-and-load-db repo)))))
 
       (periodically-pull-current-repo)
       (periodically-push-current-repo))

+ 6 - 2
src/main/frontend/handler/web/nfs.cljs

@@ -209,10 +209,14 @@
 
 (defn- handle-diffs!
   [repo nfs? old-files new-files handle-path path-handles re-index?]
-  (let [get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
+  (let [get-last-modified-at (fn [path] (some (fn [file]
+                                                (when (= path (:file/path file))
+                                                  (:file/last-modified-at file)))
+                                              new-files))
+        get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
         {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files)
         ;; Use the same labels as isomorphic-git
-        rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file}) col))
+        rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file :last-modified-at (get-last-modified-at file)}) col))
         _ (when (and nfs? (seq deleted))
             (let [deleted (doall
                            (-> (map (fn [path] (if (= "/" (first path))