Просмотр исходного кода

fix: force /private part on iOS

Tienson Qin 3 лет назад
Родитель
Сommit
d801c96a52
2 измененных файлов с 10 добавлено и 5 удалено
  1. 9 4
      src/main/frontend/fs/capacitor_fs.cljs
  2. 1 1
      src/main/frontend/handler/events.cljs

+ 9 - 4
src/main/frontend/fs/capacitor_fs.cljs

@@ -212,10 +212,13 @@
                       (error-handler error)
                       (log/error :write-file-failed error)))))))))
 
-(defn remove-private-part
-  "iOS sometimes return the private part."
+(defn ios-force-include-private
+  "iOS sometimes return paths without the private part."
   [path]
-  (string/replace path "///private/" "///"))
+  (if (string/includes? path "///private/")
+    path
+    (let [[prefix others] (string/split path "///")]
+      (str prefix "///private/" others))))
 
 (defn normalize-file-protocol-path [dir path]
   (let [dir             (some-> dir (string/replace #"/+$" ""))
@@ -249,7 +252,9 @@
                 :else
                 (let [path' (safe-encode-url path)]
                   (str dir "/" path')))]
-    (remove-private-part path')))
+    (if (mobile-util/native-ios?)
+      (ios-force-include-private path')
+      path')))
 
 (defn- local-container-path?
   "Check whether `path' is logseq's container `localDocumentsPath' on iOS"

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

@@ -570,7 +570,7 @@
         payload (-> event
                     (js->clj :keywordize-keys true)
                     (update :path (fn [path]
-                                    (when (string? path) (capacitor-fs/remove-private-part path)))))]
+                                    (when (string? path) (capacitor-fs/ios-force-include-private path)))))]
     (fs-watcher/handle-changed! type payload)
     (when (file-sync-handler/enable-sync?)
      (sync/file-watch-handler type payload))))