diff --git a/web/src/main/frontend/components/sidebar.cljs b/web/src/main/frontend/components/sidebar.cljs index b08a308844..dbd8ba0a14 100644 --- a/web/src/main/frontend/components/sidebar.cljs +++ b/web/src/main/frontend/components/sidebar.cljs @@ -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 diff --git a/web/src/main/frontend/handler.cljs b/web/src/main/frontend/handler.cljs index b89b15c7d3..137efd7689 100644 --- a/web/src/main/frontend/handler.cljs +++ b/web/src/main/frontend/handler.cljs @@ -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 [] diff --git a/web/src/main/frontend/state.cljs b/web/src/main/frontend/state.cljs index 8035d38da5..5326ed88fd 100644 --- a/web/src/main/frontend/state.cljs +++ b/web/src/main/frontend/state.cljs @@ -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)) diff --git a/web/src/main/frontend/util.cljs b/web/src/main/frontend/util.cljs index 2f2bb5de6e..69d132f8ea 100644 --- a/web/src/main/frontend/util.cljs +++ b/web/src/main/frontend/util.cljs @@ -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)))))) diff --git a/web/src/main/frontend/version.cljs b/web/src/main/frontend/version.cljs index fbb29f7099..d2581347cc 100644 --- a/web/src/main/frontend/version.cljs +++ b/web/src/main/frontend/version.cljs @@ -1,3 +1,3 @@ (ns frontend.version) -(defonce version "0.0.1-1") +(defonce version "0.0.1-2")