소스 검색

fix(mobile): loading stuck caused by global config

Andelf 3 년 전
부모
커밋
6de5c623ab

+ 1 - 1
ios/App/App/FileSync/FileSync.swift

@@ -119,7 +119,7 @@ public struct SyncMetadata: CustomStringConvertible, Equatable {
 @objc(FileSync)
 @objc(FileSync)
 public class FileSync: CAPPlugin, SyncDebugDelegate {
 public class FileSync: CAPPlugin, SyncDebugDelegate {
     override public func load() {
     override public func load() {
-        print("debug File sync iOS plugin loaded!")
+        print("debug FileSync iOS plugin loaded!")
 
 
         AWSMobileClient.default().initialize { (userState, error) in
         AWSMobileClient.default().initialize { (userState, error) in
             guard error == nil else {
             guard error == nil else {

+ 1 - 1
src/main/frontend/handler.cljs

@@ -215,7 +215,7 @@
       (p/finally (fn []
       (p/finally (fn []
                    (state/set-db-restoring! false))))
                    (state/set-db-restoring! false))))
   (when (mobile-util/native-platform?)
   (when (mobile-util/native-platform?)
-    (p/do! (mobile-util/hide-splash)))
+    (mobile-util/hide-splash))
 
 
   (db/run-batch-txs!)
   (db/run-batch-txs!)
   (file/<ratelimit-file-writes!)
   (file/<ratelimit-file-writes!)

+ 18 - 11
src/main/frontend/handler/global_config.cljs

@@ -34,21 +34,24 @@
 
 
 (defn- create-global-config-file-if-not-exists
 (defn- create-global-config-file-if-not-exists
   [repo-url]
   [repo-url]
-  (let [config-dir (global-config-dir)
+  (when (not-empty @root-dir)
+   (let [config-dir (global-config-dir)
         config-path (global-config-path)]
         config-path (global-config-path)]
     (p/let [_ (fs/mkdir-if-not-exists config-dir)
     (p/let [_ (fs/mkdir-if-not-exists config-dir)
             file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
             file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
            (when-not file-exists?
            (when-not file-exists?
              (file-common-handler/reset-file! repo-url config-path default-content)
              (file-common-handler/reset-file! repo-url config-path default-content)
-             (set-global-config-state! default-content)))))
+             (set-global-config-state! default-content))))))
 
 
 (defn restore-global-config!
 (defn restore-global-config!
   "Sets global config state from config file"
   "Sets global config state from config file"
   []
   []
-  (let [config-dir (global-config-dir)
-        config-path (global-config-path)]
-    (p/let [config-content (fs/read-file config-dir config-path)]
-      (set-global-config-state! config-content))))
+  (if (not-empty @root-dir)
+    (let [config-dir (global-config-dir)
+          config-path (global-config-path)]
+      (p/let [config-content (fs/read-file config-dir config-path)]
+        (set-global-config-state! config-content)))
+    (set-global-config-state! default-content)))
 
 
 (defn start
 (defn start
   "This component has four responsibilities on start:
   "This component has four responsibilities on start:
@@ -58,8 +61,12 @@
 - Start a file watcher for global config dir if it's not already started.
 - Start a file watcher for global config dir if it's not already started.
   Watcher ensures client db is seeded with correct file data."
   Watcher ensures client db is seeded with correct file data."
   [{:keys [repo]}]
   [{:keys [repo]}]
-  (p/let [root-dir' (ipc/ipc "getLogseqDotDirRoot")
-          _ (reset! root-dir root-dir')
-          _ (restore-global-config!)
-          _ (create-global-config-file-if-not-exists repo)
-          _ (fs/watch-dir! (global-config-dir) {:global-dir true})]))
+  (-> (p/do!
+       (p/let [root-dir' (ipc/ipc "getLogseqDotDirRoot")]
+         (reset! root-dir root-dir'))
+       (restore-global-config!)
+       (create-global-config-file-if-not-exists repo)
+       (fs/watch-dir! (global-config-dir) {:global-dir true}))
+      (p/timeout 6000)
+      (p/catch (fn [e]
+                 (js/console.error "cannot start global-config" e)))))

+ 12 - 10
src/main/frontend/handler/repo.cljs

@@ -396,22 +396,24 @@
   (-> (setup-local-repo-if-not-exists-impl!)
   (-> (setup-local-repo-if-not-exists-impl!)
       (p/timeout 3000)
       (p/timeout 3000)
       (p/catch (fn []
       (p/catch (fn []
-                 (state/set-db-restoring! false)
-                 (prn "setup-local-repo failed! timeout 3000ms")))))
+                 (prn "setup-local-repo failed! timeout 3000ms")))
+      (p/finally (fn []
+                   (state/set-db-restoring! false)))))
 
 
 (defn restore-and-setup-repo!
 (defn restore-and-setup-repo!
   "Restore the db of a graph from the persisted data, and setup. Create a new
   "Restore the db of a graph from the persisted data, and setup. Create a new
   conn, or replace the conn in state with a new one."
   conn, or replace the conn in state with a new one."
   [repo]
   [repo]
-  (p/let [_ (state/set-db-restoring! true)
-          _ (db/restore-graph! repo)
-          _ (repo-config-handler/restore-repo-config! repo)
-          _ (global-config-handler/restore-global-config!)]
+  (p/do!
+   (state/set-db-restoring! true)
+   (db/restore-graph! repo)
+   (repo-config-handler/restore-repo-config! repo)
+   (global-config-handler/restore-global-config!)
     ;; Don't have to unlisten the old listener, as it will be destroyed with the conn
     ;; Don't have to unlisten the old listener, as it will be destroyed with the conn
-    (db/listen-and-persist! repo)
-    (state/pub-event! [:shortcut/refresh])
-    (ui-handler/add-style-if-exists!)
-    (state/set-db-restoring! false)))
+   (db/listen-and-persist! repo)
+   (state/pub-event! [:shortcut/refresh])
+   (ui-handler/add-style-if-exists!)
+   (state/set-db-restoring! false)))
 
 
 (defn rebuild-index!
 (defn rebuild-index!
   [url]
   [url]

+ 0 - 2
src/main/frontend/mobile/core.cljs

@@ -36,8 +36,6 @@
 
 
   (mobile-util/check-ios-zoomed-display)
   (mobile-util/check-ios-zoomed-display)
 
 
-  (.removeAllListeners mobile-util/file-sync)
-
   (.addListener mobile-util/file-sync "debug"
   (.addListener mobile-util/file-sync "debug"
                 (fn [event]
                 (fn [event]
                   (js/console.log "🔄" event))))
                   (js/console.log "🔄" event))))