diff --git a/src/main/frontend/fs/capacitor_fs.cljs b/src/main/frontend/fs/capacitor_fs.cljs index 5e22be9b3c..6ab5041a86 100644 --- a/src/main/frontend/fs/capacitor_fs.cljs +++ b/src/main/frontend/fs/capacitor_fs.cljs @@ -55,7 +55,7 @@ (defn- (p/chain (.readdir Filesystem (clj->js {:path path})) #(js->clj % :keywordize-keys true) - #(get % "files" nil)) + :files) (p/catch (fn [error] (js/console.error "readdir Error: " path ": " error) nil)))) @@ -83,25 +83,26 @@ files (> files (remove (fn [file] - (let [uri (:uri file)] - (or (string/starts-with? uri ".") - (= file "bak")))))) - files (map (fn [file] - ;; TODO: use uri-join - (update file :uri - (fn [uri] - (str (string/replace d #"/+$" "") - "/" - (if (mobile-util/native-ios?) - (js/encodeURI uri) - uri))))) - files) - files-dir (->> files + (or (string/starts-with? file ".") + (and (mobile-util/native-android?) + (or (string/includes? file "#") + (string/includes? file "%"))) + (= file "bak"))))) + files (->> files + (map (fn [file] + ;; TODO: use uri-join + (str (string/replace d #"/+$" "") + "/" + (if (mobile-util/native-ios?) + (js/encodeURI file) + file))))) + files-with-stats (p/all (mapv > files-with-stats (filterv #(= (:type %) "directory")) (mapv :uri)) files-result (p/all - (->> files + (->> files-with-stats (filter #(= (:type %) "file")) (filter (fn [{:keys [uri]}] diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index bd26c55939..89d7c6495d 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -80,7 +80,7 @@ (do (state/set-state! :user/info result) (let [status (if (user-handler/alpha-user?) :welcome :unavailable)] - (when (= status :welcome) + (when (and (= status :welcome) (user-handler/logged-in?)) (async/ (p/let [txid-str (fs/read-file root "logseq/graphs-txid.edn") - txid-meta (and txid-str (reader/read-string txid-str))] - txid-meta) - (p/catch - (fn [^js e] - (js/console.error "[fs read txid data error]" e)))))) + (p/let [exists? (fs/file-exists? root "logseq/graphs-txid.edn")] + (when exists? + (-> (p/let [txid-str (fs/read-file root "logseq/graphs-txid.edn") + txid-meta (and txid-str (reader/read-string txid-str))] + txid-meta) + (p/catch + (fn [^js e] + (js/console.error "[fs read txid data error]" e)))))))) (defn inflate-graphs-info [graphs] diff --git a/src/main/frontend/util/persist_var.cljs b/src/main/frontend/util/persist_var.cljs index 181098ab00..13ca7596bc 100644 --- a/src/main/frontend/util/persist_var.cljs +++ b/src/main/frontend/util/persist_var.cljs @@ -32,24 +32,26 @@ (let [repo (state/get-current-repo) dir (config/get-repo-dir repo) path (load-path location)] - (-> (p/chain (fs/stat dir path) - (fn [stat] - (when stat - (fs/read-file dir path))) - (fn [content] - (when (not-empty content) - (try (cljs.reader/read-string content) - (catch js/Error e - (println (util/format "read persist-var failed: %s" (load-path location))) - (js/console.dir e))))) - (fn [value] - (when (some? value) - (swap! *value (fn [o] - (-> o - (assoc-in [repo :loaded?] true) - (assoc-in [repo :value] value))))))) - (p/catch (fn [e] - (println (util/format "load persist-var failed: %s: %s" (load-path location) e)))))))) + (p/let [file-exists? (fs/file-exists? dir path)] + (when file-exists? + (-> (p/chain (fs/stat dir path) + (fn [stat] + (when stat + (fs/read-file dir path))) + (fn [content] + (when (not-empty content) + (try (cljs.reader/read-string content) + (catch js/Error e + (println (util/format "read persist-var failed: %s" (load-path location))) + (js/console.dir e))))) + (fn [value] + (when (some? value) + (swap! *value (fn [o] + (-> o + (assoc-in [repo :loaded?] true) + (assoc-in [repo :value] value))))))) + (p/catch (fn [e] + (println (util/format "load persist-var failed: %s: %s" (load-path location) e)))))))))) (-loaded? [_] (get-in @*value [(state/get-current-repo) :loaded?]))