1
0
Эх сурвалжийг харах

feat(electron): add open file with Finder & Default app

charlie 4 жил өмнө
parent
commit
15e7fc8a1b

+ 8 - 0
resources/js/preload.js

@@ -35,6 +35,14 @@ contextBridge.exposeInMainWorld('apis', {
     await shell.openExternal(url, options)
   },
 
+  async openPath (path) {
+    await shell.openPath(path)
+  },
+
+  showItemInFolder (fullpath) {
+    shell.showItemInFolder(fullpath)
+  },
+
   /**
    * When from is empty. The resource maybe from
    * client paste or screenshoot.

+ 6 - 0
src/main/frontend/components/page.cljs

@@ -283,6 +283,11 @@
                              :options {:on-click (fn [] (page-handler/handle-add-page-to-contents! page-original-name))}}
                             {:title (t :page/rename)
                              :options {:on-click #(state/set-modal! (rename-page-dialog page-name))}}
+                            (when (and file-path (util/electron?))
+                              [{:title   (t :page/open-in-finder)
+                                :options {:on-click #(js/window.apis.showItemInFolder file-path)}}
+                               {:title (t :page/open-with-default-app)
+                                :options {:on-click #(js/window.apis.openPath file-path)}}])
                             {:title (t :page/delete)
                              :options {:on-click #(state/set-modal! (delete-page-dialog page-name))}}
                             {:title   (t :page/action-publish)
@@ -326,6 +331,7 @@
                                                                     :on-click #(.writeText js/navigator.clipboard page-data))]
                                                         :success
                                                         false)))}})]
+                           (flatten)
                            (remove nil?))]
                 (when (seq links)
                   (ui/dropdown-with-links

+ 4 - 0
src/main/frontend/dicts.cljs

@@ -222,6 +222,8 @@ title: How to take dummy notes?
         :page/re-index "Re-index this page"
         :page/copy-to-json "Copy the whole page as JSON"
         :page/rename "Rename page"
+        :page/open-in-finder "Open in directory"
+        :page/open-with-default-app "Open with default app"
         :page/action-publish "Publish"
         :page/make-public "Publish it when exporting to an html file"
         :page/make-private "Make it private"
@@ -709,6 +711,8 @@ title: How to take dummy notes?
            :page/re-index "对此页面重新建立索引"
            :page/copy-to-json "将整页以 JSON 格式复制"
            :page/rename "重命名本页"
+           :page/open-in-finder "打开文件对应目录"
+           :page/open-with-default-app "用默认应用打开文件"
            :page/action-publish "发布"
            :page/make-public "导出 HTML 时发布本页面"
            :page/make-private "导出 HTML 时取消发布本页面"