Explorar el Código

fix(electron): open assets link in folder freezes file browser

Close #10491
Andelf hace 1 año
padre
commit
5ca28a3a56

+ 0 - 8
resources/js/preload.js

@@ -90,14 +90,6 @@ contextBridge.exposeInMainWorld('apis', {
     await shell.openPath(path)
   },
 
-  showItemInFolder (fullpath) {
-    if (IS_WIN32) {
-      shell.openPath(path.dirname(fullpath).replaceAll("/", "\\"))
-    } else {
-      shell.showItemInFolder(fullpath)
-    }
-  },
-
   /**
    * save all publish assets to disk
    *

+ 4 - 0
src/electron/electron/handler.cljs

@@ -86,6 +86,10 @@
     (let [dir (backup-file/get-backup-dir repo path)]
       (.openPath shell dir))))
 
+(defmethod handle :openFileInFolder [_window [_ full-path]]
+  (when (string? full-path)
+   (.showItemInFolder shell full-path)))
+
 (defmethod handle :readFile [_window [_ path]]
   (utils/read-file path))
 

+ 3 - 2
src/main/frontend/components/block.cljs

@@ -78,7 +78,8 @@
             [rum.core :as rum]
             [shadow.loader :as loader]
             [datascript.impl.entity :as e]
-            [logseq.common.path :as path]))
+            [logseq.common.path :as path]
+            [electron.ipc :as ipc]))
 
 
 
@@ -316,7 +317,7 @@
                  :on-click      (fn [e]
                                   (util/stop e)
                                   (if local?
-                                    (js/window.apis.showItemInFolder image-src)
+                                    (ipc/ipc "openFileInFolder" image-src)
                                     (js/window.apis.openExternal image-src)))}
                 image-src])
              [:.flex

+ 1 - 1
src/main/frontend/components/page_menu.cljs

@@ -130,7 +130,7 @@
             (let [repo-dir (config/get-repo-dir repo)
                   file-fpath (path/path-join repo-dir file-rpath)]
               [{:title   (t :page/open-in-finder)
-                :options {:on-click #(js/window.apis.showItemInFolder file-fpath)}}
+                :options {:on-click #(ipc/ipc "openFileInFolder" file-fpath)}}
                {:title   (t :page/open-with-default-app)
                 :options {:on-click #(js/window.apis.openPath file-fpath)}}]))
 

+ 3 - 2
src/main/frontend/handler/page.cljs

@@ -45,7 +45,8 @@
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util.page-ref :as page-ref]
             [promesa.core :as p]
-            [logseq.common.path :as path]))
+            [logseq.common.path :as path]
+            [electron.ipc :as ipc]))
 
 ;; FIXME: add whiteboard
 (defn- get-directory
@@ -878,7 +879,7 @@
   (if-let [file-rpath (and (util/electron?) (page-util/get-page-file-rpath))]
     (let [repo-dir (config/get-repo-dir (state/get-current-repo))
           file-fpath (path/path-join repo-dir file-rpath)]
-      (js/window.apis.showItemInFolder file-fpath))
+      (ipc/ipc "openFileInFolder" file-fpath))
     (notification/show! "No file found" :warning)))
 
 (defn copy-page-url