浏览代码

Warning on multiple tab/windows access to the same graph

Tienson Qin 1 年之前
父节点
当前提交
8a20b419d4
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 8 0
      src/main/frontend/handler/events.cljs
  2. 5 2
      src/main/frontend/persist_db/browser.cljs

+ 8 - 0
src/main/frontend/handler/events.cljs

@@ -949,6 +949,14 @@
 (defmethod handle :editor/edit-block [[_ block pos id opts]]
   (editor-handler/edit-block! block pos id opts))
 
+(defmethod handle :db/multiple-tabs-opfs-failed [_]
+  ;; close current tab or window
+  (notification/show!
+   (let [word (if (util/electron?) "window" "tab")]
+     (util/format "Logseq doesn't support multiple %ss access to the same graph yet, please close this %s."
+                  word word))
+   :warning false))
+
 (defn run!
   []
   (let [chan (state/get-events-chan)]

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

@@ -9,7 +9,8 @@
             [promesa.core :as p]
             [frontend.util :as util]
             [frontend.handler.notification :as notification]
-            [cljs-bean.core :as bean]))
+            [cljs-bean.core :as bean]
+            [frontend.state :as state]))
 
 (defonce *sqlite (atom nil))
 
@@ -46,7 +47,9 @@
                     (bean/->clj result)))
           (p/catch (fn [error]
                      (prn :debug :list-db-error (js/Date.))
-                     (notification/show! [:div (str "SQLiteDB error: " error)] :error)
+                     (if (= "NoModificationAllowedError"  (.-name error))
+                       (state/pub-event! [:db/multiple-tabs-opfs-failed])
+                       (notification/show! [:div (str "SQLiteDB error: " error)] :error))
                      [])))))
 
   (<unsafe-delete [_this repo]