Skip to content

Commit

Permalink
feat(electron): add open file with Finder & Default app
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Jan 27, 2021
1 parent edc0b0a commit 15e7fc8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resources/js/preload.js
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/main/frontend/components/page.cljs
Expand Up @@ -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)
Expand Down Expand Up @@ -326,6 +331,7 @@
:on-click #(.writeText js/navigator.clipboard page-data))]
:success
false)))}})]
(flatten)
(remove nil?))]
(when (seq links)
(ui/dropdown-with-links
Expand Down
4 changes: 4 additions & 0 deletions src/main/frontend/dicts.cljs
Expand Up @@ -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"
Expand Down Expand Up @@ -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 时取消发布本页面"
Expand Down

0 comments on commit 15e7fc8

Please sign in to comment.