fix: prompt to create a Logseq sync graph or normal graph on iOS

Previously, users can create a graph everywhere including the iCloud
folder, which is both confusing and can cause unexpected data
conflicts.

Another enhancement:
After the user confirms the "Use Logseq Sync for this new graph?"
prompt, a remote graph will be created and start to sync automatically.

https://www.loom.com/share/69059969747c4b798a4c712c45e442d7
This commit is contained in:
Tienson Qin
2022-11-02 13:18:11 +08:00
parent 2dfac3d774
commit 7ddfa66004
11 changed files with 92 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
(ns frontend.fs.capacitor-fs
"Implementation of fs protocol for mobile"
(:require ["@capacitor/filesystem" :refer [Encoding Filesystem]]
(:require ["@capacitor/filesystem" :refer [Encoding Filesystem Directory]]
[cljs-bean.core :as bean]
[clojure.string :as string]
[goog.string :as gstring]
@@ -260,6 +260,25 @@
:webkit-allow-full-screen "webkitallowfullscreen"
:height "100%"}]])
(defn- open-dir
[dir]
(p/let [_ (when (mobile-util/native-android?) (android-check-permission))
{:keys [path localDocumentsPath]} (-> (.pickFolder mobile-util/folder-picker
(clj->js (when (and dir (mobile-util/native-ios?))
{:path dir})))
(p/then #(js->clj % :keywordize-keys true))
(p/catch (fn [e]
(js/alert (str e))
nil))) ;; NOTE: If pick folder fails, let it crash
_ (when (and (mobile-util/native-ios?)
(not (or (local-container-path? path localDocumentsPath)
(mobile-util/iCloud-container-path? path))))
(state/pub-event! [:modal/show-instruction]))
_ (js/console.log "Opening or Creating graph at directory: " path)
files (readdir path)
files (js->clj files :keywordize-keys true)]
(into [] (concat [{:path path}] files))))
(defrecord ^:large-vars/cleanup-todo Capacitorfs []
protocol/Fs
(mkdir! [_this dir]
@@ -336,21 +355,8 @@
(let [path (get-file-path dir path)]
(p/chain (.stat Filesystem (clj->js {:path path}))
#(js->clj % :keywordize-keys true))))
(open-dir [_this _ok-handler]
(p/let [_ (when (mobile-util/native-android?) (android-check-permission))
{:keys [path localDocumentsPath]} (-> (.pickFolder mobile-util/folder-picker)
(p/then #(js->clj % :keywordize-keys true))
(p/catch (fn [e]
(js/alert (str e))
nil))) ;; NOTE: If pick folder fails, let it crash
_ (when (and (mobile-util/native-ios?)
(not (or (local-container-path? path localDocumentsPath)
(mobile-util/iCloud-container-path? path))))
(state/pub-event! [:modal/show-instruction]))
_ (js/console.log "Opening or Creating graph at directory: " path)
files (readdir path)
files (js->clj files :keywordize-keys true)]
(into [] (concat [{:path path}] files))))
(open-dir [_this dir _ok-handler]
(open-dir dir))
(get-files [_this path-or-handle _ok-handler]
(readdir path-or-handle))
(watch-dir! [_this dir _options]