From b61697e8246888923a38ee55f362ffe527cf77f7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 27 Jan 2021 22:05:56 +0800 Subject: [PATCH] feat(electron): replace windows path \\ with / --- src/electron/electron/handler.cljs | 26 +++++++++++++++++--------- src/main/frontend/handler/file.cljs | 7 +++---- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index 11c8f1384b..2b2970aac5 100644 --- a/src/electron/electron/handler.cljs +++ b/src/electron/electron/handler.cljs @@ -6,7 +6,8 @@ ["chokidar" :as watcher] [promesa.core :as p] [goog.object :as gobj] - [clojure.string :as string])) + [clojure.string :as string] + [electron.utils :as utils])) (defmulti handle (fn [_window args] (keyword (first args)))) @@ -43,18 +44,25 @@ (defmethod handle :stat [_window [_ path]] (fs/statSync path)) +(defn- fix-win-path! + [path] + (when path + (if util/win32? + (string/replace path "\\" "/") + path))) + (defn- get-files [path] (let [result (->> (map (fn [path] (let [stat (fs/statSync path)] (when-not (.isDirectory stat) - {:path path + {:path (fix-win-path! path) :content (read-file path) :stat stat}))) (readdir path)) (remove nil?))] - (vec (cons {:path path} result)))) + (vec (cons {:path (fix-win-path! path)} result)))) ;; TODO: Is it going to be slow if it's a huge directory (defmethod handle :openDir [window _messages] @@ -89,22 +97,22 @@ (.on watcher "add" (fn [path] (send-file-watcher! win "add" - {:dir dir - :path path + {:dir (fix-win-path! dir) + :path (fix-win-path! path) :content (read-file path) :stat (fs/statSync path)}))) (.on watcher "change" (fn [path] (send-file-watcher! win "change" - {:dir dir - :path path + {:dir (fix-win-path! dir) + :path (fix-win-path! path) :content (read-file path) :stat (fs/statSync path)}))) (.on watcher "unlink" (fn [path] (send-file-watcher! win "unlink" - {:dir dir - :path path}))) + {:dir (fix-win-path! dir) + :path (fix-win-path! path)}))) (.on watcher "error" (fn [path] (println "Watch error happened: " diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 42cd795c2a..01cac57c3b 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -139,10 +139,9 @@ (utils/win32 file)) file - (and electron-local-repo? util/win32?) - (str (config/get-repo-dir repo-url) "\\" file) - - (and electron-local-repo? (not= "/" (first file))) + (and electron-local-repo? (or + util/win32? + (not= "/" (first file)))) (str (config/get-repo-dir repo-url) "/" file) :else