From 3e0e85aa031c1bef4510c62af221c61021277aab Mon Sep 17 00:00:00 2001 From: charlie Date: Sat, 8 May 2021 20:02:48 +0800 Subject: [PATCH] fix(electron): absolute path on win32 --- resources/js/preload.js | 4 +++- src/main/frontend/fs.cljs | 7 ++++--- src/main/frontend/util.cljc | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/resources/js/preload.js b/resources/js/preload.js index c7f33fbf5b..329e00cda2 100644 --- a/resources/js/preload.js +++ b/resources/js/preload.js @@ -139,5 +139,7 @@ contextBridge.exposeInMainWorld('apis', { setZoomFactor (factor) { webFrame.setZoomFactor(factor) - } + }, + + isAbsolutePath: path.isAbsolute.bind(path) }) diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index b3749ae512..24bcbeeb09 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -138,9 +138,10 @@ ([repo dir path] (create-if-not-exists repo dir path "")) ([repo dir path initial-content] - (let [path (if (util/starts-with? path "/") - path - (str "/" path))] + (let [path (if (util/is-absolute-path path) path + (if (util/starts-with? path "/") + path + (str "/" path)))] (-> (p/let [stat (stat dir path)] true) diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 7231f32378..3378745aec 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -1070,6 +1070,14 @@ (defonce win32? #?(:cljs goog.userAgent/WINDOWS :clj nil)) +#?(:cljs + (defn is-absolute-path + [path] + (try + (js/window.apis.isAbsolutePath path) + (catch js/Error _ + (node-path.isAbsolute path))))) + (defn ->system-modifier [keyboard-shortcut] (if mac?