Просмотр исходного кода

fix: no available handles to import to

Tienson Qin 2 лет назад
Родитель
Сommit
8c3ec50c07

+ 1 - 1
package.json

@@ -101,7 +101,7 @@
         "@logseq/capacitor-file-sync": "5.0.1",
         "@logseq/diff-merge": "0.2.2",
         "@logseq/react-tweet-embed": "1.3.1-1",
-        "@logseq/sqlite-wasm": "^0.0.4",
+        "@logseq/sqlite-wasm": "=0.0.6",
         "@radix-ui/colors": "^0.1.8",
         "@sentry/react": "^6.18.2",
         "@sentry/tracing": "^6.18.2",

+ 2 - 3
src/electron/electron/git.cljs

@@ -98,9 +98,8 @@
 
 (defn commit!
   [message]
-  (p/do!
-   (run-git! #js ["config" "core.quotepath" "false"])
-   (run-git! #js ["commit" "-m" message])))
+  (p/let [_ (run-git! #js ["config" "core.quotepath" "false"])]
+    (run-git! #js ["commit" "-m" message])))
 
 (defn add-all-and-commit!
   ([]

+ 1 - 2
src/main/electron/listener.cljs

@@ -39,8 +39,7 @@
                           (notification/show! error :error))]
       (if (config/db-based-graph? repo)
         (->
-         (p/do!
-           (persistent-db/<export-db repo {})
+         (p/let [_ (persistent-db/<export-db repo {})]
            (ipc/ipc "persistent-dbs-saved"))
          (p/catch error-handler))
         ;; TODO: Move all file based graphs to use the above persist approach

+ 11 - 10
src/main/frontend/db_worker.cljs

@@ -104,17 +104,17 @@
         (restore-data-from-addr repo addr)))))
 
 (defn- close-db!
-  [repo]
+  [repo ^js db]
   (swap! *sqlite-conns dissoc repo)
   (swap! *datascript-conns dissoc repo)
-  (swap! *opfs-pools dissoc repo))
+  (swap! *opfs-pools dissoc repo)
+  (when db (.close db)))
 
 (defn- close-other-dbs!
   [repo]
   (doseq [[r db] @*sqlite-conns]
     (when-not (= repo r)
-      (close-db! r)
-      (.close ^Object db))))
+      (close-db! r db))))
 
 (defn- create-or-open-db!
   [repo]
@@ -168,10 +168,9 @@
       (p/all (map (fn [dir] (.remove dir)) dirs)))))
 
 (defn- remove-vfs!
-  [repo]
-  (p/let [^js pool (<get-opfs-pool repo)]
-    (when pool
-      (.removeVfs ^js pool))))
+  [^js pool]
+  (when pool
+    (.removeVfs ^js pool)))
 
 #_:clj-kondo/ignore
 (defclass SQLiteDB
@@ -237,8 +236,10 @@
 
   (unsafeUnlinkDB
    [_this repo]
-   (p/let [result (remove-vfs! repo)
-           _ (close-db! repo)]
+   (p/let [db (get-sqlite-conn repo)
+           pool (get-opfs-pool repo)
+           _ (close-db! repo db)
+           result (remove-vfs! pool)]
      nil))
 
   (exportDB

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

@@ -179,9 +179,8 @@
                   (str (config/get-repo-dir repo) "/" %))
                [old-path new-path])
           new-dir (path/dirname new-path)]
-      (p/do!
-       (mkdir-if-not-exists new-dir)
-       (protocol/copy! (get-fs old-path) repo old-path new-path)))))
+      (p/let [_ (mkdir-if-not-exists new-dir)]
+        (protocol/copy! (get-fs old-path) repo old-path new-path)))))
 
 
 

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

@@ -409,8 +409,7 @@
   (get-files [_this dir]
     (get-files dir))
   (watch-dir! [_this dir _options]
-    (p/do!
-     (.unwatch mobile-util/fs-watcher)
-     (.watch mobile-util/fs-watcher (clj->js {:path dir}))))
+    (p/let [_ (.unwatch mobile-util/fs-watcher)]
+      (.watch mobile-util/fs-watcher (clj->js {:path dir}))))
   (unwatch-dir! [_this _dir]
     (.unwatch mobile-util/fs-watcher)))

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

@@ -99,9 +99,8 @@
 (defn await-get-nfs-file-handle
   "for accessing File handle outside, ensuring user granted."
   [repo handle-path]
-  (p/do!
-   (await-permission-granted repo)
-   (get-nfs-file-handle handle-path)))
+  (p/let [_ (await-permission-granted repo)]
+    (get-nfs-file-handle handle-path)))
 
 (defn- readdir-and-reload-all-handles
   "Return list of filenames"

+ 10 - 11
src/main/frontend/fs/watcher_handler.cljs

@@ -173,20 +173,19 @@
                 db-content (if-not db-empty?
                              (db/get-file repo file-rpath)
                              "")]
-          (p/do!
-           (cond
-             (and file-exists?
-                  db-empty?)
-             (handle-add-and-change! repo file-rpath file-content db-content file-mtime false)
+          (p/let [_ (cond
+                      (and file-exists?
+                           db-empty?)
+                      (handle-add-and-change! repo file-rpath file-content db-content file-mtime false)
 
-             (and file-exists?
-                  (not db-empty?)
-                  (not= file-content db-content))
-             (handle-add-and-change! repo file-rpath file-content db-content file-mtime true))
+                      (and file-exists?
+                           (not db-empty?)
+                           (not= file-content db-content))
+                      (handle-add-and-change! repo file-rpath file-content db-content file-mtime true))]
 
-           (ui-handler/re-render-root!)
+            (ui-handler/re-render-root!)
 
-           [file-rpath]))))))
+            [file-rpath]))))))
 
 (defn load-graph-files!
   "This fn replaces the former initial fs watcher"

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

@@ -77,10 +77,9 @@
 (defn restore-and-setup!
   [repo repos]
   (when repo
-    (-> (p/do!
-         (db-restore/restore-graph! repo)
-         (repo-config-handler/start {:repo repo})
-         (op-mem-layer/<init-load-from-indexeddb! repo))
+    (-> (p/let [_ (db-restore/restore-graph! repo)
+                _ (repo-config-handler/start {:repo repo})]
+          (op-mem-layer/<init-load-from-indexeddb! repo))
         (p/then
          (fn []
            (db-listener/listen-and-persist! repo)

+ 2 - 3
src/main/frontend/handler/editor.cljs

@@ -1879,9 +1879,8 @@
     (cond
       (and (= content "1. ") (= last-input-char " ") input-id edit-block
            (not (own-order-number-list? edit-block)))
-      (p/do!
-       (state/pub-event! [:editor/toggle-own-number-list edit-block])
-       (state/set-edit-content! input-id ""))
+      (p/let [_ (state/pub-event! [:editor/toggle-own-number-list edit-block])]
+        (state/set-edit-content! input-id ""))
 
       (and (= last-input-char commands/command-trigger)
            (or (re-find #"(?m)^/" (str (.-value input))) (start-of-new-word? input pos)))

+ 2 - 3
src/main/frontend/handler/import.cljs

@@ -223,12 +223,11 @@
 (defn import-from-sqlite-db!
   [buffer bare-graph-name finished-ok-handler]
   (let [graph (str config/db-version-prefix bare-graph-name)]
-    (-> (do
-          (persist-db/<import-db graph buffer)
-          (state/set-current-repo! graph)
+    (-> (p/let [_ (persist-db/<import-db graph buffer)]
           (repo-handler/restore-and-setup-repo! graph))
         (p/then
          (fn [_result]
+           (state/set-current-repo! graph)
            (finished-ok-handler)))
         (p/catch
          (fn [e]

+ 2 - 3
src/main/frontend/persist_db/browser.cljs

@@ -31,9 +31,8 @@
           worker (js/Worker. (str worker-url "?electron=" (util/electron?)))
           sqlite (Comlink/wrap worker)]
       (reset! *sqlite sqlite)
-      (-> (p/do!
-           (.init sqlite)
-           (ask-persist-permission!))
+      (-> (p/let [_ (.init sqlite)]
+            (ask-persist-permission!))
           (p/catch (fn [error]
                      (prn :debug "Can't init SQLite wasm")
                      (js/console.error error)

+ 4 - 4
yarn.lock

@@ -552,10 +552,10 @@
   resolved "https://registry.yarnpkg.com/@logseq/react-tweet-embed/-/react-tweet-embed-1.3.1-1.tgz#119d22be8234de006fc35c3fa2a36f85634c5be6"
   integrity sha512-9O0oHs5depCvh6ZQvwtl1xb7B80YG5rUfY10uSUat5itOlcE3IWaYYpe6p/tcHErqHWnWgkXHitAB9M29FMbQg==
 
-"@logseq/sqlite-wasm@^0.0.4":
-  version "0.0.4"
-  resolved "https://registry.yarnpkg.com/@logseq/sqlite-wasm/-/sqlite-wasm-0.0.4.tgz#7d9d9fb6034149d503fa66237b1a5f5206107f15"
-  integrity sha512-aV1nhgUPIrv36E9J7GRKLAFuqPKJbSFxuhrzbxNAhHS8Wn0XO/0++UcikwCOK9aKnbgqfoRgX+VSxiFhwfno2g==
+"@logseq/sqlite-wasm@=0.0.6":
+  version "0.0.6"
+  resolved "https://registry.yarnpkg.com/@logseq/sqlite-wasm/-/sqlite-wasm-0.0.6.tgz#df44513298e323caa0fea02c4179145df65371e8"
+  integrity sha512-goo4vnxlq8H/Ea/8zhsEMG+9zGBRMSwazMdYAZyH6WaZbQGsCCoGcsGIgJOJsCDLVnMKqJL5h6WtbbR1JJis6g==
 
 "@mapbox/node-pre-gyp@^1.0.0":
   version "1.0.11"