Procházet zdrojové kódy

enhance: select iCloud folder first when select existing graph

Tienson Qin před 3 roky
rodič
revize
2473ce92bf

+ 3 - 13
ios/App/App/FolderPicker.swift

@@ -27,21 +27,11 @@ public class FolderPicker: CAPPlugin, UIDocumentPickerDelegate {
       // Set the initial directory.
 
       if let path = call.getString("path") {
-        // guard let url = URL(string: path) else {
-        //     call.reject("can not parse url")
-        //     return
-        // }
-
-        guard let documentDirectory = FileManager.default.urls(
-          for: .documentDirectory,
-          in: .userDomainMask
-        ).first
-        else {
-          return
+        guard let url = URL(string: path) else {
+             call.reject("can not parse url")
+             return
         }
 
-        let url = documentDirectory.appendingPathComponent(path)
-
         print("picked folder url = " + url.path)
 
         documentPicker.directoryURL = url

+ 12 - 12
src/main/frontend/fs/capacitor_fs.cljs

@@ -275,18 +275,18 @@
           {: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))))
+                                                (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

+ 6 - 12
src/main/frontend/handler/page.cljs

@@ -691,18 +691,12 @@
 (defn ls-dir-files!
   ([ok-handler] (ls-dir-files! ok-handler nil))
   ([ok-handler opts]
-   (let [ios-logseq-sync? (when (and (mobile-util/native-ios?)
-                                     (state/enable-sync?)
-                                     (not (:sync-from-remote? opts)))
-                            (js/confirm "Use Logseq Sync for this new graph?"))]
-     (web-nfs/ls-dir-files-with-handler!
-      (fn [e]
-        (init-commands!)
-        (when ok-handler
-          (ok-handler e)
-          (when ios-logseq-sync?
-            (state/pub-event! [:sync/create-remote-graph (state/get-current-repo)]))))
-      (assoc opts :ios-logseq-sync? ios-logseq-sync?)))))
+   (web-nfs/ls-dir-files-with-handler!
+    (fn [e]
+      (init-commands!)
+      (when ok-handler
+        (ok-handler e)))
+    opts)))
 
 (defn get-all-pages
   [repo]

+ 6 - 5
src/main/frontend/handler/web/nfs.cljs

@@ -122,17 +122,18 @@
 (defn ^:large-vars/cleanup-todo ls-dir-files-with-handler!
   "Read files from directory and setup repo (for the first time setup a repo)"
   ([ok-handler] (ls-dir-files-with-handler! ok-handler nil))
-  ([ok-handler {:keys [empty-dir?-or-pred dir-result-fn picked-root-fn ios-logseq-sync?]}]
+  ([ok-handler {:keys [empty-dir?-or-pred dir-result-fn picked-root-fn dir]}]
    (let [path-handles (atom {})
          electron? (util/electron?)
          mobile-native? (mobile-util/native-platform?)
          nfs? (and (not electron?)
                    (not mobile-native?))
          *repo (atom nil)
-         dir (when ios-logseq-sync?
-               ;; open Logseq's Documents folder
-               "")]
-    ;; TODO: add ext filter to avoid loading .git or other ignored file handlers
+         dir (or dir nil)
+         dir (some-> dir
+                     (string/replace "file:///" "file://")
+                     (string/replace " " "%20"))]
+     ;; TODO: add ext filter to avoid loading .git or other ignored file handlers
      (->
       (p/let [result (if (fn? dir-result-fn)
                        (dir-result-fn {:path-handles path-handles :nfs? nfs?})

+ 19 - 15
src/main/frontend/mobile/graph_picker.cljs

@@ -46,7 +46,6 @@
         logseq-sync-on?  (= sync-mode :logseq-sync)
         *input-ref       (rum/create-ref)
         native-ios?      (mobile-util/native-ios?)
-
         open-picker      #(page-handler/ls-dir-files! shortcut/refresh! opts)
         on-create        (fn [input-val]
                            (let [graph-name (util/safe-sanitize-file-name input-val)]
@@ -103,23 +102,28 @@
        :init
        [:div.flex.flex-col.w-full.space-y-3
         (ui/button
-         [:span.flex.items-center.justify-between.w-full.py-1
-          [:strong "Create a new graph"]
-          (ui/icon "chevron-right")]
+          [:span.flex.items-center.justify-between.w-full.py-1
+           [:strong "Create a new graph"]
+           (ui/icon "chevron-right")]
 
-         :on-click #(if (and native-ios?
-                             (some (fn [s] (not (string/blank? s)))
-                                   (vals (:mobile/container-urls @state/state))))
-                      (set-step! :new-graph)
-                      (open-picker)))
+          :on-click #(if (and native-ios?
+                              (some (fn [s] (not (string/blank? s)))
+                                    (vals (:mobile/container-urls @state/state))))
+                       (set-step! :new-graph)
+                       (open-picker)))
 
         (ui/button
-         [:span.flex.items-center.justify-between.w-full.py-1
-          [:strong "Select an existing graph"]
-          (ui/icon "folder-plus")]
-
-         :intent "logseq"
-         :on-click open-picker)]
+          [:span.flex.items-center.justify-between.w-full.py-1
+           [:strong "Select an existing graph"]
+           (ui/icon "folder-plus")]
+
+          :intent "logseq"
+          :on-click (fn []
+                      (page-handler/ls-dir-files! shortcut/refresh!
+                                                  {:dir (when native-ios?
+                                                          (or
+                                                           (state/get-icloud-container-root-url)
+                                                           (state/get-local-container-root-url)))})))]
 
        ;; step 1
        :new-graph