Skip to content

Commit

Permalink
fix(fs/mobile): ios fs and loading fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Mar 28, 2023
1 parent f1404fd commit c79c352
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deps/common/src/logseq/common/path.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
base-segs (drop (count common-segs) base-segs)
remain-segs (drop (count common-segs) path-segs)
base-prefix (apply str (repeat (max 0 (dec (count base-segs))) "../"))]
(js/console.error (js/Error. "buggy relative-path"))
(js/console.error (js/Error. "buggy relative-path") base-path sub-path)
#_{:clj-kondo/ignore [:path-invalid-construct/string-join]}
(if is-url?
(gp-util/safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
Expand Down
4 changes: 3 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@
(if (and (gp-config/local-protocol-asset? src)
(file-sync/current-graph-sync-on?))
(let [*exist? (::exist? state)
asset-path (path/url-to-path src)]
;; special handling for asset:// protcol
;; Capacitor uses a special URL for assets loading
asset-path (gp-config/remove-asset-protocol src)]
(if (string/blank? asset-path)
(reset! *exist? false)
;; FIXME(andelf): possible bug here
Expand Down
11 changes: 9 additions & 2 deletions src/main/frontend/fs/capacitor_fs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,15 @@
(p/catch (fn [error]
(log/error :copy-file-failed error)))))
(stat [_this fpath]
(p/chain (.stat Filesystem (clj->js {:path fpath}))
#(js->clj % :keywordize-keys true)))
(-> (p/chain (.stat Filesystem (clj->js {:path fpath}))
#(js->clj % :keywordize-keys true))
(p/catch (fn [error]
(let [errstr (if error (.toString error) "")]
(when (string/includes? errstr "because you don’t have permission to view it")
(state/pub-event! [:notification/show
{:content "No permission, please clear cache and re-open graph folder."
:status :error}]))
(p/rejected error))))))
(open-dir [_this dir]
(open-dir dir))
(get-files [_this dir]
Expand Down
28 changes: 16 additions & 12 deletions src/main/frontend/fs/watcher_handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@
;; FIXME(andelf): hack for demo graph, demo graph does not bind to local directory
(string/starts-with? dir "memory://") "local"
:else (config/get-local-repo dir))
repo-dir (config/get-local-dir repo)
{:keys [mtime]} stat
db-content (or (db/get-file repo path) "")]
db-content (db/get-file repo path)
exists-in-db? (not (nil? db-content))
db-content (or db-content "")]

(when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
(cond
Expand All @@ -76,17 +79,8 @@
(let [backup? (not (string/blank? db-content))]
(handle-add-and-change! repo path content db-content mtime backup?))

;; global config handling
(and (= "change" type)
(= dir (global-config-handler/global-config-dir)))
(when (= path "config.edn")
(global-config-handler/set-global-config-state! content))

(and (= "change" type)
(not (db/file-exists? repo path)))
(js/console.error "Can't get file in the db: " path)

(and (= "change" type)
(= dir repo-dir)
(not= (string/trim content) (string/trim db-content))
(not (gp-config/local-asset? path)))
(when-not (and
Expand All @@ -99,13 +93,23 @@
(handle-add-and-change! repo path content db-content mtime (not global-dir))) ;; no backup for global dir

(and (= "unlink" type)
(db/file-exists? repo path))
exists-in-db?)
(p/let [dir-exists? (fs/file-exists? dir "")]
(when dir-exists?
(when-let [page-name (db/get-file-page path)]
(println "Delete page: " page-name ", file path: " path ".")
(page-handler/delete! page-name #() :delete-file? false))))

;; global config handling
(and (= "change" type)
(= dir (global-config-handler/global-config-dir)))
(when (= path "config.edn")
(global-config-handler/set-global-config-state! content))

(and (= "change" type)
(not exists-in-db?))
(js/console.error "Can't get file in the db: " path)

(and (contains? #{"add" "change" "unlink"} type)
(string/ends-with? path "logseq/custom.css"))
(do
Expand Down
7 changes: 4 additions & 3 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,10 +1457,11 @@
path
(let [repo (state/get-current-repo)
repo-dir (config/get-repo-dir repo)
path (string/replace path "../" "/")
full-path (util/node-path.join repo-dir path)
;; Hack for path calculation
path (str "./" (string/replace path "../" "/"))
full-path (path/path-join repo-dir path)
data-url? (string/starts-with? path "data:")]
(prn ::make-asset-url full-path)
(prn ::make-asset-url full-path path)
(cond
data-url?
path ;; just return the original
Expand Down
6 changes: 4 additions & 2 deletions src/main/frontend/handler/global_config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

(defn global-config-dir
[]
(path/path-join @root-dir "config"))
(when @root-dir
(path/path-join @root-dir "config")))

(defn global-config-path
[]
(path/path-join @root-dir "config" "config.edn"))
(when @root-dir
(path/path-join @root-dir "config" "config.edn")))

(defn set-global-config-state!
[content]
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/mobile/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
(state/set-state! :mobile/container-urls paths)
(println "iOS container path: " paths))))

(state/pub-event! [:validate-appId])
;; Buggy, should not use
;; (state/pub-event! [:validate-appId])

(.addEventListener js/window
"load"
Expand Down

0 comments on commit c79c352

Please sign in to comment.