Add indexedb support check

Resolves https://github.com/logseq/logseq/issues/3
This commit is contained in:
Tienson Qin
2020-07-24 09:15:54 +08:00
parent e2204ffc55
commit c2fe05f260
5 changed files with 47 additions and 11 deletions

View File

@@ -149,6 +149,7 @@
global-graph-pages? (= :graph route-name)
logged? (:name me)
db-restoring? (state/sub :db/restoring?)
indexeddb-support? (state/sub :indexeddb/support?)
page? (= :page route-name)]
[:div {:class (if white? "white-theme" "dark-theme")
:on-click (fn []
@@ -296,6 +297,9 @@
:width "100%"
:margin-bottom 200})}
(cond
(not indexeddb-support?)
nil
db-restoring?
[:div.mt-20
[:div.ls-center

View File

@@ -48,16 +48,20 @@
;; TODO: Support more storage options (dropbox, google drive), git logic should be
;; moved to another namespace, better there should be a `protocol`.
(defn show-notification!
[content status]
(swap! state/state assoc
:notification/show? true
:notification/content content
:notification/status status)
(js/setTimeout #(swap! state/state assoc
:notification/show? false
:notification/content nil
:notification/status nil)
5000))
([content status]
(show-notification! content status true))
([content status clear?]
(swap! state/state assoc
:notification/show? true
:notification/content content
:notification/status status)
(when clear?
(js/setTimeout #(swap! state/state assoc
:notification/show? false
:notification/content nil
:notification/status nil)
5000))))
(defn get-github-token
[]
@@ -1560,6 +1564,11 @@
(when me (state/set-state! :me me))
(state/set-db-restoring! true)
(render)
(util/indexeddb-check?
(fn [_error]
(show-notification! "Sorry, it seems that your browser doesn't support IndexedDB, we recommend to use latest Chrome(Chromium) or Firefox(Non-private mode)." :error false)
(state/set-indexedb-support? false)))
(-> (p/all (db/restore! (assoc me :repos repos) db-listen-to-tx! #(restore-config! % false)))
(p/then
(fn []

View File

@@ -17,6 +17,7 @@
:repo/loading-files? nil
:repo/importing-to-db? nil
:repo/sync-status {}
:indexeddb/support? true
:me nil
:git/clone-repo (or (storage/get :git/clone-repo) "")
:git/current-repo (storage/get :git/current-repo)
@@ -497,3 +498,7 @@
project (:name (first (filter (fn [p] (= (:repo p) repo)) projects)))]
(when-not (string/blank? project)
project))))
(defn set-indexedb-support?
[value]
(set-state! :indexeddb/support? value))

View File

@@ -728,3 +728,21 @@
(update f 0 keyword)
f))
hiccup))
(defn chrome?
[]
(let [user-agent js/navigator.userAgent
vendor js/navigator.vendor]
(and (re-find #"Chrome" user-agent)
(re-find #"Google Inc" user-agent))))
(defn indexeddb-check?
[error-handler]
(let [test-db "logseq-test-db-foo-bar-baz"
db (and js/window.indexedDB
(js/window.indexedDB.open test-db))]
(when (and db (not (chrome?)))
(gobj/set db "onerror" error-handler)
(gobj/set db "onsuccess"
(fn []
(js/window.indexedDB.deleteDatabase test-db))))))

View File

@@ -1,3 +1,3 @@
(ns frontend.version)
(defonce version "0.0.1-1")
(defonce version "0.0.1-2")