Browse Source

fix(ios): handle ios indexedDB preload

Andelf 3 years ago
parent
commit
ba0a67ae05

+ 4 - 0
public/index.html

@@ -2,6 +2,10 @@
 <html>
 <head>
   <meta charset="utf-8">
+  <!-- Handle iOS indexedDB preloading. Ref: https://developer.apple.com/forums/thread/681201 -->
+  <script type="text/javascript">
+    window.indexedDB;
+  </script>
   <meta content="minimum-scale=1, initial-scale=1, maximum-scale=1, width=device-width, shrink-to-fit=no" name="viewport">
   <link rel="stylesheet" href="/static/css/tabler-icons.min.css">
   <link href="/static/css/style.css" rel="stylesheet" type="text/css">

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

@@ -210,9 +210,13 @@
 
     (events/run!)
 
-    (p/let [repos (get-repos)]
-      (state/set-repos! repos)
-      (restore-and-setup! repos db-schema))
+    (-> (p/let [repos (get-repos)]
+          (state/set-repos! repos)
+          (restore-and-setup! repos db-schema))
+        (p/catch (fn [e]
+                   (js/console.error "Errow while restoring repos: " e)))
+        (p/finally (fn []
+                     (state/set-db-restoring! false))))
     (when (mobile-util/native-platform?)
       (p/do! (mobile-util/hide-splash)))
 

+ 0 - 1
src/main/frontend/handler/web/nfs.cljs

@@ -217,7 +217,6 @@
                    (throw error))))
       (p/finally
         (fn []
-          (state/set-db-restoring! false)
           (state/set-loading-files! @*repo false)))))))
 
 (defn ls-dir-files-with-path!

+ 1 - 1
src/main/frontend/idbkv.js

@@ -16,7 +16,7 @@ class Store {
         return;
       }
       this._dbp = new Promise((resolve, reject) => {
-        const openreq = indexedDB.open(this._dbName, this._version);
+        const openreq = window.indexedDB.open(this._dbName, this._version);
         openreq.onerror = () => reject(openreq.error);
         openreq.onsuccess = () => resolve(openreq.result);
         // First time setup: create an empty object store