Prechádzať zdrojové kódy

remove git, chokidar, rsapi

Tienson Qin 4 dní pred
rodič
commit
f1de1ea163

+ 0 - 3
resources/package.json

@@ -23,14 +23,11 @@
   },
   "dependencies": {
     "@fastify/cors": "11.0.1",
-    "@logseq/rsapi": "0.0.92",
     "@modelcontextprotocol/sdk": "^1.17.5",
     "@sentry/electron": "2.5.1",
     "abort-controller": "3.0.0",
-    "chokidar": "^3.5.1",
     "command-exists": "1.2.9",
     "diff-match-patch": "1.0.5",
-    "dugite": "2.7.1",
     "electron-deeplink": "1.0.10",
     "electron-dl": "4.0.0",
     "electron-log": "4.3.1",

+ 1 - 10
src/electron/electron/core.cljs

@@ -8,8 +8,6 @@
             [clojure.string :as string]
             [electron.db :as db]
             [electron.exceptions :as exceptions]
-            [electron.fs-watcher :as fs-watcher]
-            [electron.git :as git]
             [electron.handler :as handler]
             [electron.logger :as logger]
             [electron.server :as server]
@@ -257,8 +255,6 @@
 
            (db/ensure-graphs-dir!)
 
-           (git/configure-auto-commit!)
-
            (vreset! *setup-fn
                     (fn []
                       (let [t1 (setup-updater! win)
@@ -276,7 +272,6 @@
 
            ;; main window events
            (.on win "close" (fn [e]
-                              (git/before-graph-close-hook!)
                               (when @*quit-dirty? ;; when not updating
                                 (.preventDefault e)
 
@@ -286,7 +281,7 @@
                                   (cond
                                     (or multiple-windows? (not mac?) @win/*quitting?)
                                     (when window
-                                      (win/close-handler win handler/close-watcher-when-orphaned! e)
+                                      (win/close-handler win e)
                                       (reset! *win nil))
 
                                     (and mac? (not multiple-windows?))
@@ -331,10 +326,6 @@
 
       (.on app "window-all-closed" (fn []
                                      (logger/debug "window-all-closed" "Quitting...")
-                                     (try
-                                       (fs-watcher/close-watcher!)
-                                       (catch :default e
-                                         (logger/error "window-all-closed" e)))
                                      (.quit app)))
       (on-app-ready! app))))
 

+ 0 - 74
src/electron/electron/file_sync_rsapi.cljs

@@ -1,74 +0,0 @@
-(ns electron.file-sync-rsapi
-  (:require ["@logseq/rsapi" :as rsapi]
-            [electron.window :as window]
-            [electron.logger :as logger]
-            [cljs-bean.core :as bean]))
-
-(defn- init-logger [log-fn] (rsapi/initLogger log-fn))
-
-(defn key-gen [] (rsapi/keygen))
-
-(defn set-env [graph-uuid env private-key public-key]
-  (rsapi/setEnv graph-uuid env private-key public-key))
-
-(defn set-progress-callback [callback]
-  (rsapi/setProgressCallback callback))
-
-(defn get-local-files-meta [graph-uuid base-path file-paths]
-  (rsapi/getLocalFilesMeta graph-uuid base-path (clj->js file-paths)))
-
-(defn get-local-all-files-meta [graph-uuid base-path]
-  (rsapi/getLocalAllFilesMeta graph-uuid base-path))
-
-(defn rename-local-file [graph-uuid base-path from to]
-  (rsapi/renameLocalFile graph-uuid base-path from to))
-
-(defn delete-local-files [graph-uuid base-path file-paths]
-  (rsapi/deleteLocalFiles graph-uuid base-path (clj->js file-paths)))
-
-(defn fetch-remote-files [graph-uuid base-path file-paths token]
-  (rsapi/fetchRemoteFiles graph-uuid base-path (clj->js file-paths) token))
-
-(defn update-local-files [graph-uuid base-path file-paths token]
-  (rsapi/updateLocalFiles graph-uuid base-path (clj->js file-paths) token))
-
-(defn download-version-files [graph-uuid base-path file-paths token]
-  (rsapi/updateLocalVersionFiles graph-uuid base-path (clj->js file-paths) token))
-
-(defn delete-remote-files [graph-uuid base-path file-paths txid token]
-  (rsapi/deleteRemoteFiles graph-uuid base-path (clj->js file-paths) txid token))
-
-(defn update-remote-files [graph-uuid base-path file-paths txid token]
-  (rsapi/updateRemoteFiles graph-uuid base-path (clj->js file-paths) txid token))
-
-(defn encrypt-fnames [graph-uuid fnames]
-  (rsapi/encryptFnames graph-uuid (clj->js fnames)))
-
-(defn decrypt-fnames [graph-uuid fnames]
-  (rsapi/decryptFnames graph-uuid (clj->js fnames)))
-
-(defn encrypt-with-passphrase [passphrase data]
-  (rsapi/ageEncryptWithPassphrase passphrase data))
-
-(defn decrypt-with-passphrase [passphrase data]
-  (rsapi/ageDecryptWithPassphrase passphrase data))
-
-(defn cancel-all-requests []
-  (rsapi/cancelAllRequests))
-
-(defonce progress-notify-chan "file-sync-progress")
-(set-progress-callback (fn [error progress-info]
-                         (when-not error
-                           (doseq [^js win (window/get-all-windows)]
-                             (when-not (.isDestroyed win)
-                               (.. win -webContents
-                                   (send progress-notify-chan (bean/->js progress-info))))))))
-
-(init-logger (fn [_error record]
-               (let [[level message] record]
-                 (case level
-                   "ERROR" (logger/error message)
-                   "WARN" (logger/warn message)
-                   "INFO" (logger/info message)
-                   "DEBUG" (logger/debug message)
-                   (logger/debug message)))))

+ 0 - 166
src/electron/electron/fs_watcher.cljs

@@ -1,166 +0,0 @@
-(ns electron.fs-watcher
-  "This ns is a wrapper around the chokidar file watcher,
-  https://www.npmjs.com/package/chokidar. File watcher events are sent to the
-  `file-watcher` ipc channel"
-  (:require ["chokidar" :as watcher]
-            ["electron" :refer [app]]
-            ["fs" :as fs]
-            [cljs-bean.core :as bean]
-            [electron.logger :as logger]
-            [electron.utils :as utils]
-            [electron.window :as window]
-            [logseq.common.graph :as common-graph]))
-
-;; TODO: explore different solutions for different platforms
-;; 1. https://github.com/Axosoft/nsfw
-
-(defonce polling-interval 10000)
-;; dir -> Watcher
-(defonce *file-watcher (atom {})) ;; val: [watcher watcher-del-f]
-
-(defonce file-watcher-chan "file-watcher")
-(defn- send-file-watcher! [dir type payload]
-  (let [send-fn (fn [^js win]
-                  (when-not (.isDestroyed win)
-                    (.. win -webContents
-                        (send file-watcher-chan
-                              (bean/->js {:type type :payload payload})))
-                    true))
-        wins (if (:global-dir payload)
-               (window/get-all-windows)
-               (window/get-graph-all-windows dir))]
-    (if (or (contains? #{"unlinkDir" "addDir"} type)
-            ;; Only change events to a global dir are emitted to all windows.
-            ;; Add* events are not emitted to all since each client adds
-            ;; files at different times.
-            (and (:global-dir payload) (= "change" type)))
-      ;; notify every windows
-      (doseq [win wins] (send-fn win))
-
-      ;; Should only send to one window
-      ;; If no window is on this graph, just ignore
-      (let [sent? (some send-fn wins)]
-        (when-not sent? (logger/warn ::send
-                                     "unhandled file event will cause uncatched file modifications!. target:" dir))))))
-
-(defn- publish-file-event!
-  [dir path event options]
-  (let [dir-path? (= dir path)
-        content (when (and (not= event "unlink")
-                           (not dir-path?)
-                           (utils/should-read-content? path))
-                  (utils/read-file path))
-        stat (when (and (not= event "unlink")
-                        (not dir-path?))
-               (utils/fs-stat->clj path))]
-    (send-file-watcher! dir event (merge {:dir (utils/fix-win-path! dir)
-                                          :path (utils/fix-win-path! path)
-                                          :content content
-                                          :stat stat}
-                                         (select-keys options [:global-dir])))))
-(defn- create-dir-watcher
-  [dir options]
-  (let [watcher-opts (clj->js
-                      {:ignored (fn [path]
-                                  (common-graph/ignored-path? dir path))
-                       :ignoreInitial true
-                       :ignorePermissionErrors true
-                       :interval polling-interval
-                       :binaryInterval polling-interval
-                       :persistent true
-                       :disableGlobbing true
-                       :usePolling false
-                       :awaitWriteFinish true})
-        dir-watcher (.watch watcher dir watcher-opts)]
-    ;; TODO: batch sender
-    (.on dir-watcher "unlinkDir"
-         (fn [path]
-           (logger/warn ::on-unlink-dir {:path path})
-           (when (= dir path)
-             (publish-file-event! dir dir "unlinkDir" options))))
-    (.on dir-watcher "addDir"
-         (fn [path]
-           (when (= dir path)
-             (publish-file-event! dir dir "addDir" options))))
-    (.on dir-watcher "add"
-         (fn [path]
-           (publish-file-event! dir path "add" options)))
-    (.on dir-watcher "change"
-         (fn [path]
-           (publish-file-event! dir path "change" options)))
-    (.on dir-watcher "unlink"
-         ;; delay 500ms for syncing disks
-         (fn [path]
-           (logger/debug ::on-unlink {:path path})
-           (js/setTimeout #(when (not (fs/existsSync path))
-                             (publish-file-event! dir path "unlink" options))
-                          500)))
-    (.on dir-watcher "error"
-         (fn [path]
-           (logger/warn ::on-error "Watch error happened:" {:path path})))
-
-    dir-watcher))
-
-(defn- seed-client-with-initial-global-dir-data
-  "Ensures that secondary clients initialize their databases efficiently and in
-  the same way as the primary client. This fn achieves this by creating a
-  temporary watcher whose sole purpose is to seed the db and then close  when
-  its done seeding a.k.a. ready event fires."
-  [dir options]
-  (let [dir-watcher (create-dir-watcher dir options)]
-    (.on dir-watcher "ready" (fn []
-                               (.close dir-watcher)))))
-
-(defn- create-and-save-watcher
-  [dir options]
-  (let [dir-watcher (create-dir-watcher dir options)
-        watcher-del-f #(.close dir-watcher)]
-    (swap! *file-watcher assoc dir [dir-watcher watcher-del-f])
-    ;; electron app extends `EventEmitter`
-    ;; TODO check: duplicated with the logic in "window-all-closed" ?
-    (.on app "quit" watcher-del-f)))
-
-(defn- watch-global-dir!
-  "Only one watcher exists per global dir so only create the watcher for the
-  primary client. Secondary clients only seed their client database."
-  [dir options]
-  (if (get @*file-watcher dir)
-    (seed-client-with-initial-global-dir-data dir options)
-    (create-and-save-watcher dir options)))
-
-(defn watch-dir!
-  "Watches a directory and emits file events. In addition to file
-  watching, clients rely on watchers to initially seed their database with
-  the file contents of a dir. This is done with the ignoreInitial option
-  set to false, https://github.com/paulmillr/chokidar#path-filtering. The
-  watcher emits addDir and add file events which then seed the client database.
-  This fn has the following options:
-
-* :global-dir - Boolean that indicates the watched directory is global. This
-  type of directory has different behavior then a normal watcher as it
-  broadcasts its change events to all clients. This option needs to be passed to
-  clients in order for them to identify the correct db"
-  [dir options]
-  (if (:global-dir options)
-    (watch-global-dir! dir options)
-    (when-not (get @*file-watcher dir)
-      (if (fs/existsSync dir)
-        (create-and-save-watcher dir options)
-        ;; retry if the `dir` not exists, which is useful when a graph's folder is
-        ;; back after refreshing the window
-        (js/setTimeout #(watch-dir! dir options) 5000)))))
-
-(defn close-watcher!
-  "If no `dir` provided, close all watchers;
-   Otherwise, close the specific watcher if exists"
-  ([]
-   (doseq [[watcher watcher-del-f] (vals @*file-watcher)]
-     (.close watcher)
-     (.removeListener app "quit" watcher-del-f))
-   (reset! *file-watcher {}))
-  ([dir]
-   (let [[watcher watcher-del-f] (get @*file-watcher dir)]
-     (when watcher
-       (.close watcher)
-       (.removeListener app "quit" watcher-del-f)
-       (swap! *file-watcher dissoc dir)))))

+ 0 - 218
src/electron/electron/git.cljs

@@ -1,218 +0,0 @@
-(ns electron.git
-  (:require ["dugite" :refer [GitProcess]]
-            ["fs-extra" :as fs]
-            ["os" :as os]
-            ["path" :as node-path]
-            [clojure.string :as string]
-            [electron.logger :as logger]
-            [electron.state :as state]
-            [electron.utils :as utils]
-            [goog.object :as gobj]
-            [promesa.core :as p]))
-
-(def log-error (partial logger/error "[Git]"))
-
-(defn get-graph-git-dir
-  [graph-path & {:keys [ensure-dir?]
-                 :or {ensure-dir? true}}]
-  (when-let [graph-path (some-> graph-path
-                                (string/replace "/" "_")
-                                (string/replace ":" "comma"))]
-    (let [parent-dir (.join node-path (.homedir os) ".logseq" "git" graph-path)
-          dir (.join node-path parent-dir ".git")]
-      (when ensure-dir? (. fs ensureDirSync dir))
-      dir)))
-
-(defn run-git!
-  [graph-path commands]
-  (when (and graph-path (fs/existsSync graph-path))
-    (p/let [result (.exec GitProcess commands graph-path)]
-      (if (zero? (gobj/get result "exitCode"))
-        (let [result (gobj/get result "stdout")]
-          (p/resolved result))
-        (let [error (gobj/get result "stderr")]
-          (when-not (string/blank? error)
-            (log-error error))
-          (p/rejected error))))))
-
-(defn run-git2!
-  [graph-path commands]
-  (when (and graph-path (fs/existsSync graph-path))
-    (p/let [^js result (.exec GitProcess commands graph-path)]
-      result)))
-
-(defn git-dir-exists?
-  [graph-path]
-  (try
-    (let [p (.join node-path graph-path ".git")]
-      (when (fs/existsSync p)
-        (.isDirectory (fs/statSync p))))
-    (catch :default _e
-      nil)))
-
-(defn remove-dot-git-file!
-  [graph-path]
-  (try
-    (let [_ (when (string/blank? graph-path)
-              (utils/send-to-renderer :setCurrentGraph {})
-              (throw (js/Error. "Empty graph path")))
-          p (.join node-path graph-path ".git")]
-      (when (and (fs/existsSync p)
-                 (.isFile (fs/statSync p)))
-        (let [content (string/trim (.toString (fs/readFileSync p)))
-              dir-path (string/replace content "gitdir: " "")]
-          (when (and content
-                     (string/starts-with? content "gitdir:")
-                     (string/includes? content ".logseq/")
-                     (not (fs/existsSync dir-path)))
-            (fs/unlinkSync p)))))
-    (catch :default e
-      (log-error e))))
-
-(defn init!
-  [graph-path]
-  (let [_ (remove-dot-git-file! graph-path)
-        separate-git-dir (get-graph-git-dir graph-path)
-        dir-exists? (git-dir-exists? graph-path)
-        args (cond
-               dir-exists?
-               ["init"]
-               separate-git-dir
-               ["init" (str "--separate-git-dir=" separate-git-dir)]
-               :else
-               ["init"])]
-    (p/let [_ (run-git! graph-path (clj->js args))]
-      (p/do!
-       (when utils/win32?
-         (run-git! graph-path #js ["config" "core.safecrlf" "false"]))
-       (run-git! graph-path #js ["config" "diff.sqlite3.binary" "true"])
-       (run-git! graph-path #js ["config" "diff.sqlite3.textconv" "echo .dump | sqlite3"])
-       (let [path (node-path/join graph-path ".gitattributes")]
-         (when-not (fs/existsSync path)
-           (fs/writeFileSync path "*.sqlite diff=sqlite3")))))))
-
-(defn add-all!
-  [graph-path]
-  (-> (run-git! graph-path #js ["add" "--ignore-errors" "./*"])
-      (p/catch (fn [error]
-                 (let [error (string/lower-case (str error))]
-                   (if (or (string/includes? error "permission denied")
-                           (string/includes? error "index.lock': File exists"))
-                     (log-error error)
-                     (p/rejected error)))))))
-
-;; git log -100 --oneline -p ~/Desktop/org/pages/contents.org
-
-(defn commit!
-  [graph-path message]
-  (p/do!
-   (run-git! graph-path #js ["config" "core.quotepath" "false"])
-   (run-git! graph-path #js ["commit" "-m" message])))
-
-(defn add-all-and-commit-single-graph!
-  [graph-path message]
-  ;; Don't run git on db graphs
-  (when (string/includes? graph-path "logseq_local_")
-    (let [message (if (string/blank? message)
-                    "Auto saved by Logseq"
-                    message)]
-      (->
-       (p/let [_ (init! graph-path)
-               _ (add-all! graph-path)]
-         (commit! graph-path message))
-       (p/catch (fn [error]
-                  (when (and
-                         (string? error)
-                         (not (string/blank? error)))
-                    (if (string/starts-with? error "Author identity unknown")
-                      (utils/send-to-renderer "setGitUsernameAndEmail" {:type "git"})
-                      (utils/send-to-renderer "notification" {:type "error"
-                                                              :payload (str error "\nIf you don't want to see those errors or don't need git, you can disable the \"Git auto commit\" feature on Settings > Version control.")})))))))))
-
-(defn add-all-and-commit!
-  ([]
-   (add-all-and-commit! nil))
-  ([message]
-   (doseq [path (state/get-all-graph-paths)]
-     (add-all-and-commit-single-graph! path message))))
-
-(defn short-status!
-  [graph-path]
-  (p/do!
-   (when-not (or (fs/existsSync (git-dir-exists? graph-path))
-                 (fs/existsSync (get-graph-git-dir graph-path {:ensure-dir? false})))
-     (init! graph-path))
-   (run-git! graph-path #js ["status" "--porcelain"])))
-
-(defonce quotes-regex #"\"[^\"]+\"")
-(defn wrapped-by-quotes?
-  [v]
-  (and (string? v) (>= (count v) 2) (= "\"" (first v) (last v))))
-
-(defn unquote-string
-  [v]
-  (string/trim (subs v 1 (dec (count v)))))
-
-(defn- split-args
-  [s]
-  (let [quotes (re-seq quotes-regex s)
-        non-quotes (string/split s quotes-regex)
-        col (if (seq quotes)
-              (concat (interleave non-quotes quotes)
-                      (drop (count quotes) non-quotes))
-              non-quotes)]
-    (->> col
-         (map (fn [s]
-                (if (wrapped-by-quotes? s)
-                  [(unquote-string s)]
-                  (string/split s #"\s"))))
-         (flatten)
-         (remove string/blank?))))
-
-(defn raw!
-  [graph-path args]
-  (init! graph-path)
-  (let [args (if (string? args)
-               (split-args args)
-               args)
-        error-handler (fn [error]
-                        ;; TODO: why this happen?
-                        (when-not (string/blank? error)
-                          (let [error (str (first args) " error: " error)]
-                            (utils/send-to-renderer "notification" {:type "error"
-                                                                    :payload error}))
-                          (p/rejected error)))]
-    (->
-     (p/let [result (when (= (first args) "commit")
-                      (add-all! graph-path))
-             result (if (= (first args) "init")
-                      result
-                      (run-git! graph-path (clj->js args)))]
-       (p/resolved result))
-     (p/catch error-handler))))
-
-(defonce auto-commit-interval (atom nil))
-(defn- auto-commit-tick-fn
-  []
-  (when (state/git-auto-commit-enabled?)
-    (add-all-and-commit!)))
-
-(defn configure-auto-commit!
-  "Configure auto commit interval, reentrantable"
-  []
-  (when @auto-commit-interval
-    (swap! auto-commit-interval js/clearInterval))
-  (when (state/git-auto-commit-enabled?)
-    (let [seconds (state/get-git-commit-seconds)
-          millis (if (int? seconds)
-                   (* seconds 1000)
-                   6000)]
-      (logger/info ::set-auto-commit-interval seconds)
-      (js/setTimeout add-all-and-commit! 100)
-      (reset! auto-commit-interval (js/setInterval auto-commit-tick-fn millis)))))
-
-(defn before-graph-close-hook!
-  []
-  (when (and (state/git-auto-commit-enabled?)
-             (state/git-commit-on-close-enabled?))
-    (add-all-and-commit!)))

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

@@ -17,10 +17,7 @@
             [electron.backup-file :as backup-file]
             [electron.configs :as cfgs]
             [electron.db :as db]
-            [electron.file-sync-rsapi :as rsapi]
             [electron.find-in-page :as find]
-            [electron.fs-watcher :as watcher]
-            [electron.git :as git]
             [electron.handler-interface :refer [handle]]
             [electron.keychain :as keychain]
             [electron.logger :as logger]
@@ -30,7 +27,6 @@
             [electron.state :as state]
             [electron.utils :as utils]
             [electron.window :as win]
-            [goog.functions :refer [debounce]]
             [logseq.cli.common.graph :as cli-common-graph]
             [logseq.common.graph :as common-graph]
             [logseq.db :as ldb]
@@ -386,33 +382,15 @@
         (p/let [^js files (js-utils/getAllFiles assets-path (clj->js exts))]
           files)))))
 
-(defn close-watcher-when-orphaned!
-  "When it's the last window for the directory, close the watcher."
-  [window graph-path]
-  (when (not (win/graph-has-other-windows? window graph-path))
-    (watcher/close-watcher! graph-path)))
-
 (defn set-current-graph!
   [window graph-path]
-  (let [old-path (state/get-window-graph-path window)]
-    (when (and old-path graph-path (not= old-path graph-path))
-      (close-watcher-when-orphaned! window old-path))
-    (swap! state/state assoc-in [:window/graph window] graph-path)
-    nil))
+  (swap! state/state assoc-in [:window/graph window] graph-path)
+  nil)
 
 (defmethod handle :setCurrentGraph [^js window [_ graph-name]]
   (when graph-name
     (set-current-graph! window (utils/get-graph-dir graph-name))))
 
-(defmethod handle :runGit [_ [_ {:keys [repo command]}]]
-  (when (seq command)
-    (git/raw! (utils/get-graph-dir repo) command)))
-
-(defmethod handle :runGitWithinCurrentGraph [_ [_ {:keys [repo command]}]]
-  (when (seq command)
-    (git/init! (utils/get-graph-dir repo))
-    (git/run-git2! (utils/get-graph-dir repo) (clj->js command))))
-
 (defmethod handle :runCli [window [_ {:keys [command args returnResult]}]]
   (try
     (let [on-data-handler (fn [message]
@@ -431,17 +409,6 @@
                               {:type    "error"
                                :payload (.-message e)}))))
 
-(defmethod handle :gitCommitAll [_ [_ message]]
-  (git/add-all-and-commit! message))
-
-(defmethod handle :gitStatus [_ [_ repo]]
-  (git/short-status! (utils/get-graph-dir repo)))
-
-(def debounced-configure-auto-commit! (debounce git/configure-auto-commit! 5000))
-(defmethod handle :setGitAutoCommit []
-  (debounced-configure-auto-commit!)
-  nil)
-
 (defmethod handle :installMarketPlugin [_ [_ manifest]]
   (plugin/install-or-update! manifest))
 
@@ -507,27 +474,10 @@
         windows (win/get-graph-all-windows dir)]
     (> (count windows) 1)))
 
-(defmethod handle :addDirWatcher [^js _window [_ dir options]]
-  ;; receive dir path (not repo / graph) from frontend
-  ;; Windows on same dir share the same watcher
-  ;; Only close file watcher when:
-  ;;    1. there is no one window on the same dir
-  ;;    2. reset file watcher to resend `add` event on window refreshing
-  (when dir
-    (logger/debug ::watch-dir {:path dir})
-    (watcher/watch-dir! dir options)
-    nil))
-
-(defmethod handle :unwatchDir [^js _window [_ dir]]
-  (when dir
-    (logger/debug ::unwatch-dir {:path dir})
-    (watcher/close-watcher! dir)
-    nil))
-
 (defn open-new-window!
   [repo]
   (let [win (win/create-main-window! win/MAIN_WINDOW_ENTRY {:graph repo})]
-    (win/on-close-actions! win close-watcher-when-orphaned!)
+    (win/on-close-actions! win)
     (win/setup-window-listeners! win)
     win))
 
@@ -559,58 +509,6 @@
   (.manage (windowStateKeeper) win)
   (.show win))
 
-;;;;;;;;;;;;;;;;;;;;;;;
-;; file-sync-rs-apis ;;
-;;;;;;;;;;;;;;;;;;;;;;;
-
-(defmethod handle :key-gen [_]
-  (rsapi/key-gen))
-
-(defmethod handle :set-env [_ args]
-  (apply rsapi/set-env (rest args)))
-
-(defmethod handle :get-local-files-meta [_ args]
-  (apply rsapi/get-local-files-meta (rest args)))
-
-(defmethod handle :get-local-all-files-meta [_ args]
-  (apply rsapi/get-local-all-files-meta (rest args)))
-
-(defmethod handle :rename-local-file [_ args]
-  (apply rsapi/rename-local-file (rest args)))
-
-(defmethod handle :delete-local-files [_ args]
-  (apply rsapi/delete-local-files (rest args)))
-
-(defmethod handle :fetch-remote-files [_ args]
-  (apply rsapi/fetch-remote-files (rest args)))
-
-(defmethod handle :update-local-files [_ args]
-  (apply rsapi/update-local-files (rest args)))
-
-(defmethod handle :download-version-files [_ args]
-  (apply rsapi/download-version-files (rest args)))
-
-(defmethod handle :delete-remote-files [_ args]
-  (apply rsapi/delete-remote-files (rest args)))
-
-(defmethod handle :update-remote-files [_ args]
-  (apply rsapi/update-remote-files (rest args)))
-
-(defmethod handle :decrypt-fnames [_ args]
-  (apply rsapi/decrypt-fnames (rest args)))
-
-(defmethod handle :encrypt-fnames [_ args]
-  (apply rsapi/encrypt-fnames (rest args)))
-
-(defmethod handle :encrypt-with-passphrase [_ args]
-  (apply rsapi/encrypt-with-passphrase (rest args)))
-
-(defmethod handle :decrypt-with-passphrase [_ args]
-  (apply rsapi/decrypt-with-passphrase (rest args)))
-
-(defmethod handle :cancel-all-requests [_ args]
-  (apply rsapi/cancel-all-requests (rest args)))
-
 (defmethod handle :keychain/save-e2ee-password [_window [_ key encrypted-text]]
   (keychain/<set-password! key encrypted-text))
 

+ 0 - 28
src/electron/electron/state.cljs

@@ -17,39 +17,11 @@
     (swap! state assoc-in path value)
     (swap! state assoc path value)))
 
-(defn get-git-commit-seconds
-  []
-  (get-in @state [:config :git/auto-commit-seconds] 60))
-
-(defn git-auto-commit-enabled?
-  []
-  ;; For backward compatibility, use negative logic
-  (false? (get-in @state [:config :git/disable-auto-commit?] true)))
-
-(defn git-commit-on-close-enabled?
-  []
-  (get-in @state [:config :git/commit-on-close?] false))
-
 (defn get-window-graph-path
   "Get the path of the graph of a window (might be `nil`)"
   [window]
   (get (:window/graph @state) window))
 
-(defn get-all-graph-paths
-  "Get the paths of all graphs currently open in all windows."
-  []
-  (set (vals (:window/graph @state))))
-
-;; Disabled until FIXME in electron.core is addressed
-#_(defn get-active-window-graph-path
-    "Get the path of the graph of the currently focused window (might be `nil`)"
-    []
-    (let [windows (:window/graph @state)
-          active-windows-pairs (filter #(.isFocused (first %)) windows)
-          active-window-pair (first active-windows-pairs)
-          path (second active-window-pair)]
-      path))
-
 (defn close-window!
   [window]
   (swap! state medley/dissoc-in [:window/graph window]))

+ 5 - 23
src/electron/electron/utils.cljs

@@ -1,6 +1,5 @@
 (ns electron.utils
-  (:require ["@logseq/rsapi" :as rsapi]
-            ["electron" :refer [app BrowserWindow]]
+  (:require ["electron" :refer [app BrowserWindow]]
             ["fs-extra" :as fs]
             ["path" :as node-path]
             [cljs-bean.core :as bean]
@@ -81,14 +80,6 @@
         (logger/error "Unknown proxy protocol:" protocol)))
     (reset! *fetchAgent nil)))
 
-(defn- set-rsapi-proxy
-  "Set proxy for Logseq Sync(rsapi)"
-  [{:keys [protocol host port]}]
-  (if (and protocol host port (or (= protocol "http") (= protocol "socks5")))
-    (let [proxy-url (str protocol "://" host ":" port)]
-      (rsapi/setProxy proxy-url))
-    (rsapi/setProxy nil)))
-
 (defn <set-electron-proxy
   "Set proxy for electron
   type: system | direct | socks5 | http"
@@ -159,27 +150,24 @@
          (first pac-opts))))))
 
 (defn <set-proxy
-  "Set proxy for electron, fetch, and rsapi"
+  "Set proxy for electron, fetch"
   ([{:keys [type host port] :or {type "system"} :as opts}]
    (logger/info "set proxy to" opts)
    (cond
      (= type "system")
      (p/let [_ (<set-electron-proxy {:type "system"})
              proxy (<get-system-proxy)]
-       (set-fetch-agent-proxy proxy)
-       (set-rsapi-proxy proxy))
+       (set-fetch-agent-proxy proxy))
 
      (= type "direct")
      (do
        (<set-electron-proxy {:type "direct"})
-       (set-fetch-agent-proxy nil)
-       (set-rsapi-proxy nil))
+       (set-fetch-agent-proxy nil))
 
      (or (= type "socks5") (= type "http"))
      (do
        (<set-electron-proxy {:type type :host host :port port})
-       (set-fetch-agent-proxy {:protocol type :host host :port port})
-       (set-rsapi-proxy {:protocol type :host host :port port}))
+       (set-fetch-agent-proxy {:protocol type :host host :port port}))
 
      :else
      (logger/error "Unknown proxy type:" type))))
@@ -208,12 +196,6 @@
     (cfgs/set-item! :settings/agent {:type type :test test'})
     (cfgs/set-item! :settings/agent {:type type :protocol type :host host :port port :test test'})))
 
-(defn should-read-content?
-  "Skip reading content of file while using file-watcher"
-  [path]
-  (let [ext (string/lower-case (node-path/extname path))]
-    (contains? #{".md" ".markdown" ".org" ".js" ".edn" ".css"} ext)))
-
 (defn read-file-raw
   [path]
   (fs/readFileSync path))

+ 3 - 5
src/electron/electron/window.cljs

@@ -80,10 +80,8 @@
   (.destroy win))
 
 (defn close-handler
-  [^js win close-watcher-f e]
+  [^js win e]
   (.preventDefault e)
-  (when-let [dir (state/get-window-graph-path win)]
-    (close-watcher-f win dir))
   (state/close-window! win)
   (let [web-contents (. win -webContents)]
     (.send web-contents "persist-zoom-level" (.getZoomLevel web-contents)))
@@ -91,8 +89,8 @@
 
 (defn on-close-actions!
   ;; TODO merge with the on close in core
-  [^js win close-watcher-f] ;; injected watcher related func
-  (.on win "close" (fn [e] (close-handler win close-watcher-f e))))
+  [^js win]
+  (.on win "close" (fn [e] (close-handler win e))))
 
 (defn switch-to-window!
   [^js win]

+ 0 - 20
src/main/frontend/encrypt.cljs

@@ -1,20 +0,0 @@
-(ns frontend.encrypt
-  "Encryption related fns for use with encryption feature and file sync"
-  (:require [electron.ipc :as ipc]
-            [frontend.util :as util]
-            [logseq.graph-parser.utf8 :as utf8]
-            [promesa.core :as p]))
-
-(defn encrypt-with-passphrase
-  [passphrase content]
-  (when (util/electron?)
-    (p/let [raw-content (utf8/encode content)
-            encrypted (ipc/ipc "encrypt-with-passphrase" passphrase raw-content)]
-      (utf8/decode encrypted))))
-
-(defn decrypt-with-passphrase
-  [passphrase content]
-  (when (util/electron?)
-    (p/let [raw-content (utf8/encode content)
-            decrypted (ipc/ipc "decrypt-with-passphrase" passphrase raw-content)]
-      (utf8/decode decrypted))))

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

@@ -129,8 +129,6 @@
         (p/then (fn [result]
                   (:files (bean/->clj result))))))
 
-  (watch-dir! [_this dir options]
-    (ipc/ipc "addDirWatcher" dir options))
+  (watch-dir! [_this _dir _options])
 
-  (unwatch-dir! [_this dir]
-    (ipc/ipc "unwatchDir" dir)))
+  (unwatch-dir! [_this _dir]))

+ 4 - 53
src/main/frontend/handler/shell.cljs

@@ -1,24 +1,10 @@
 (ns frontend.handler.shell
   "Git related handler fns"
-  (:require [electron.ipc :as ipc]
-            [clojure.string :as string]
-            [logseq.common.util :as common-util]
+  (:require [clojure.string :as string]
+            [electron.ipc :as ipc]
             [frontend.handler.notification :as notification]
-            [logseq.shui.ui :as shui]
-            [promesa.core :as p]
-            [frontend.db :as db]
-            [frontend.state :as state]
-            [frontend.util :as util]))
-
-(defn run-git-command!
-  [command]
-  (ipc/ipc :runGit {:repo (state/get-current-repo)
-                    :command command}))
-
-(defn run-git-command2!
-  [command]
-  (ipc/ipc :runGitWithinCurrentGraph {:repo (state/get-current-repo) 
-                                      :command command}))
+            [frontend.util :as util]
+            [logseq.common.util :as common-util]))
 
 (defn run-cli-command!
   [command args]
@@ -26,17 +12,6 @@
                     :args         args
                     :returnResult true}))
 
-(defn wrap-notification!
-  [command f args]
-  (p/let [result (f command args)]
-    (notification/show!
-     (if (string/blank? result)
-       [:p [:code.mr-1 (str command " " args)]
-        "was executed successfully!"]
-       result)
-     :success
-     false)))
-
 (def commands-denylist
   #{"rm" "mv" "rename" "dd" ">" "command" "sudo"})
 
@@ -55,33 +30,9 @@
          [:div (str command " is too dangerous!")]
          :error)
 
-        (= "git" command)
-        (wrap-notification! command (fn [_ args] (run-git-command! args)) args)
-
         :else
         (run-cli-command! command args)))))
 
-
-(defn get-file-latest-git-log
-  [page n]
-  (when (integer? n)
-    (let [file-id (:db/id (:block/file page))]
-      (when-let [path (:file/path (db/entity file-id))]
-        (p/let [result (run-git-command! ["log" (str "-" n) "--pretty=format:Commit: %C(auto)%h$$$%s$$$%ad" "-p" path])
-                lines (->> (string/split-lines result)
-                           (filter #(string/starts-with? % "Commit: ")))]
-          (state/pub-event! [:modal/display-file-version-selector  lines path  (fn [hash path] (run-git-command! ["show" (str hash ":" path)]))]))))))
-
-
-(defn set-git-username-and-email
-  [username email]
-  (p/let [_r1 (run-git-command! ["config" "--global" "user.name" username])
-          _r2 (run-git-command! ["config" "--global" "user.email" email])]
-    (shui/dialog-close!)
-    (notification/show!
-     [:div "git config successfully!"]
-     :success)))
-
 (defn run-cli-command-wrapper!
   [command content]
   (let [args (case command

+ 0 - 2
src/main/logseq/api.cljs

@@ -19,7 +19,6 @@
             [logseq.sdk.assets :as sdk-assets]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [logseq.sdk.ui :as sdk-ui]
             [logseq.sdk.utils :as sdk-utils]
             [promesa.core :as p]))
@@ -101,7 +100,6 @@
 (def ^:export download_graph_db api-editor/download_graph_db)
 (def ^:export download_graph_pages api-editor/download_graph_pages)
 (def ^:export edit_block api-editor/edit_block)
-(def ^:export exec_git_command api-editor/exec_git_command)
 (def ^:export exit_editing_mode api-editor/exit_editing_mode)
 (def ^:export get_all_pages api-editor/get_all_pages)
 (def ^:export get_block api-editor/get_block)

+ 0 - 1
src/main/logseq/api/app.cljs

@@ -18,7 +18,6 @@
             [logseq.api.db-based :as db-based-api]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [logseq.sdk.utils :as sdk-utils]
             [reitit.frontend.easy :as rfe]))
 

+ 0 - 1
src/main/logseq/api/db.cljs

@@ -11,7 +11,6 @@
             [frontend.state :as state]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [logseq.sdk.utils :as sdk-utils]
             [promesa.core :as p]))
 

+ 0 - 1
src/main/logseq/api/db_based.cljs

@@ -25,7 +25,6 @@
             [logseq.outliner.core :as outliner-core]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [logseq.sdk.utils :as sdk-utils]
             [promesa.core :as p]))
 

+ 0 - 7
src/main/logseq/api/editor.cljs

@@ -15,7 +15,6 @@
             [frontend.handler.export :as export-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.property :as property-handler]
-            [frontend.handler.shell :as shell]
             [frontend.modules.layout.core]
             [frontend.modules.outliner.tree :as outliner-tree]
             [frontend.state :as state]
@@ -29,7 +28,6 @@
             [logseq.db :as ldb]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [logseq.sdk.utils :as sdk-utils]
             [promesa.core :as p]))
 
@@ -422,11 +420,6 @@
   (when-let [repo (state/get-current-repo)]
     (export-handler/export-repo-as-zip! repo)))
 
-(defn exec_git_command
-  [^js args]
-  (when-let [args (and args (seq (bean/->clj args)))]
-    (shell/run-git-command! args)))
-
 ;; block properties
 (defn upsert_block_property
   [block-uuid key ^js value ^js options]

+ 0 - 1
src/main/logseq/api/plugin.cljs

@@ -19,7 +19,6 @@
             [lambdaisland.glogi :as log]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
-            [logseq.sdk.git]
             [promesa.core :as p]))
 
 (defn get-caller-plugin-id

+ 0 - 28
src/main/logseq/sdk/git.cljs

@@ -1,28 +0,0 @@
-(ns logseq.sdk.git
-  (:require [cljs-bean.core :as bean]
-            [frontend.config :as config]
-            [frontend.fs :as fs]
-            [frontend.handler.shell :as shell]
-            [frontend.state :as state]
-            [promesa.core :as p]))
-
-(defn ^:export exec_command
-  [^js args]
-  (when-let [args (and args (seq (bean/->clj args)))]
-    (shell/run-git-command2! args)))
-
-(defn ^:export load_ignore_file
-  []
-  (when-let [repo (state/get-current-repo)]
-    (p/let [file ".gitignore"
-            dir (config/get-repo-dir repo)
-            _ (fs/create-if-not-exists repo dir file)
-            content (fs/read-file dir file)]
-      content)))
-
-(defn ^:export save_ignore_file
-  [content]
-  (when-let [repo (and (string? content) (state/get-current-repo))]
-    (p/let [file ".gitignore"
-            dir (config/get-repo-dir repo)
-            _ (fs/write-plain-text-file! repo dir file content {:skip-compare? true})])))

+ 0 - 5
yarn.lock

@@ -849,11 +849,6 @@
   resolved "https://registry.yarnpkg.com/@js-joda/timezone/-/timezone-2.5.0.tgz#b422ff400c25ae311384239c62724eecee2e442b"
   integrity sha512-HHFVhGUKIOtITiT+sbQRdYuO5Q+a8FDj/vQSGUSxe6+5w2in5JsavfRsAN2tU/NCdBeFx/6q8evHMtOrXfdn2g==
 
-"@logseq/diff-merge@^0.2.2":
-  version "0.2.2"
-  resolved "https://registry.yarnpkg.com/@logseq/diff-merge/-/diff-merge-0.2.2.tgz#583bd8c8c66d5ff05ea70906475efaa078e839a3"
-  integrity sha512-0WeKNhq8PsjvunOqNEd9aSM4tgiClwhonXgXzrQ4KYj8VoyLaEAyEWWGOAoE7mwR+aqwM+bMB4MxuNFywnUb8A==
-
 "@logseq/[email protected]":
   version "1.3.1-1"
   resolved "https://registry.yarnpkg.com/@logseq/react-tweet-embed/-/react-tweet-embed-1.3.1-1.tgz#119d22be8234de006fc35c3fa2a36f85634c5be6"