From 38d78739af96cdac1b223b847a146be437d4693e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 27 Sep 2021 16:02:37 +0800 Subject: [PATCH] mobile(fs): stat --- src/main/frontend/components/header.cljs | 4 +- src/main/frontend/components/widgets.cljs | 48 ++++++++++------------- src/main/frontend/fs/capacitor_fs.cljs | 7 +++- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/frontend/components/header.cljs b/src/main/frontend/components/header.cljs index a77de4b16..3b2f1ff56 100644 --- a/src/main/frontend/components/header.cljs +++ b/src/main/frontend/components/header.cljs @@ -240,7 +240,9 @@ [:div {:class "animate-spin-reverse"} svg/refresh]) - (when-not (util/electron?) + (when (and + (not (mobile-util/is-native-platform?)) + (not (util/electron?))) (login logged?)) (repo/sync-status current-repo) diff --git a/src/main/frontend/components/widgets.cljs b/src/main/frontend/components/widgets.cljs index b06636632..83f332839 100644 --- a/src/main/frontend/components/widgets.cljs +++ b/src/main/frontend/components/widgets.cljs @@ -86,36 +86,28 @@ (rum/with-context [[t] i18n/*tongue-context*] [:div.flex.flex-col [:h1.title "Add a graph"] - (if (mobile/is-native-platform?) - (ui/button "Open mobile graph test" - :on-click - (fn [] - (p/let [folder (.pickFolder mobile/folder-picker)] - (js/console.log folder) - ;;TODO - nil))) - (let [nfs-supported? (nfs/supported?)] - [:div.cp__widgets-open-local-directory - [:div.select-file-wrap.cursor - (when nfs-supported? - {:on-click #(page-handler/ls-dir-files! shortcut/refresh!)}) + (let [nfs-supported? (or (nfs/supported?) (mobile/is-native-platform?))] + [:div.cp__widgets-open-local-directory + [:div.select-file-wrap.cursor + (when nfs-supported? + {:on-click #(page-handler/ls-dir-files! shortcut/refresh!)}) - [:div - [:h1.title "Open a local directory"] - [:p "Logseq supports both Markdown and Org-mode. You can open an existing directory or create a new one on your device, a directory is also known simply as a folder. Your data will be stored only on this device."] - [:p "After you have opened your directory, it will create three folders in that directory:"] - [:ul - [:li "/journals - store your journal pages"] - [:li "/pages - store the other pages"] - [:li "/logseq - store configuration, custom.css, and some metadata."]] - (when-not nfs-supported? - (ui/admonition :warning - [:p "It seems that your browser doesn't support the " + [:div + [:h1.title "Open a local directory"] + [:p "Logseq supports both Markdown and Org-mode. You can open an existing directory or create a new one on your device, a directory is also known simply as a folder. Your data will be stored only on this device."] + [:p "After you have opened your directory, it will create three folders in that directory:"] + [:ul + [:li "/journals - store your journal pages"] + [:li "/pages - store the other pages"] + [:li "/logseq - store configuration, custom.css, and some metadata."]] + (when-not nfs-supported? + (ui/admonition :warning + [:p "It seems that your browser doesn't support the " - [:a {:href "https://web.dev/file-system-access/" - :target "_blank"} - "new native filesystem API"] - [:span ", please use any Chromium 86+ based browser like Chrome, Vivaldi, Edge, etc. Notice that the API doesn't support mobile browsers at the moment."]]))]]]))])) + [:a {:href "https://web.dev/file-system-access/" + :target "_blank"} + "new native filesystem API"] + [:span ", please use any Chromium 86+ based browser like Chrome, Vivaldi, Edge, etc. Notice that the API doesn't support mobile browsers at the moment."]]))]]])])) (rum/defcs add-graph < [state & {:keys [graph-types] diff --git a/src/main/frontend/fs/capacitor_fs.cljs b/src/main/frontend/fs/capacitor_fs.cljs index e0945822f..93f473266 100644 --- a/src/main/frontend/fs/capacitor_fs.cljs +++ b/src/main/frontend/fs/capacitor_fs.cljs @@ -67,6 +67,7 @@ (defrecord Capacitorfs [] protocol/Fs (mkdir! [this dir] + (prn "mkdir: " dir) (p/let [result (.mkdir Filesystem (clj->js {:path dir @@ -111,7 +112,11 @@ (rename! [this repo old-path new-path] nil) (stat [this dir path] - nil) + (let [path (str dir path)] + (p/let [result (.stat Filesystem (clj->js + {:path path + :directory (.-ExternalStorage Directory)}))] + result))) (open-dir [this ok-handler] (case (util/platform) "android"