electron / electron/electron

Support all actions that can be triggered via menu roles to be triggered programmatically too

Open
#22,456 2 comments 1 reaction 0 assignees View on GitHub
enhancement :sparkles:
Dominant language
C++
Stars
123k
Forks
17.5k
Avg merge
14h 31m
Merged PRs (30d)
858

Description

I think pretty much all actions that can be triggered via a menu item that has a special `role` property should be able to be triggered programmatically too, the reason is that for apps like VSCode that implement a custom menubar and/or a command palette you want to be able to show there all actions that you can show in the native menus by using the special `role` property.

So here's a list of all current roles, with an emoji indicating if they can be triggered programmatically or not, with a possible way to trigger them programmatically, to the best of my knowledge:

---

- ~~**appMenu**~~: this role doesn't actually trigger an action.
- ~~**fileMenu**~~: this role doesn't actually trigger an action.
- ~~**editMenu**~~: this role doesn't actually trigger an action.
- ~~**viewMenu**~~: this role doesn't actually trigger an action.
- ~~**windowMenu**~~: this role doesn't actually trigger an action.
- ~~**help**~~: this role doesn't actually trigger an action.
- ~~**services**~~: No need for APIs for this.
- ~~**window**~~: this role doesn't actually trigger an action.

---

- ✅ **undo**: `document.execCommand ( 'undo' )`.
- ✅ **redo**: `document.execCommand ( 'redo' )`.
- ✅ **cut**: `document.execCommand ( 'cut' )`.
- ✅ **copy**: `document.execCommand ( 'copy' )`.
- ✅ **paste**: `document.execCommand ( 'paste' )`.
- ❌ **pasteAndMatchStyle**
- ✅ **delete**: `document.execCommand ( 'delete' )`.
- ✅ **selectAll**: `document.execCommand ( 'selectAll' )`.

---

- ✅ **reload**: `BrowserWindow#webContents#reload`.
- ✅ **forceReload**: `BrowserWindow#webContents#reloadIgnoringCache`.
- ✅ **minimize**: `BrowserWindow#minimize`.
- ✅ **close**: `window.close ()`.
- ✅ **togglefullscreen**: `BrowserWindow#setFullScreen` + `BrowserWindow#isFullScreen`.
- A `BrowserWindow#toggleFullscreen` method would be nice to have.
- ✅ **toggleDevTools**: `BrowserWindow#webContents#toggleDevTools`.
- ✅ **resetZoom**: `document.documentElement.style.zoom = 1`.
- ✅ **zoomIn**: `document.documentElement.style.zoom = Number ( document.documentElement.style.zoom || 1 ) + .1`.
- ✅ **zoomOut**: `document.documentElement.style.zoom = Number ( document.documentElement.style.zoom || 1 ) - .1`.

---

- ✅ **about**: `app.showAboutPanel`
- ✅ **quit**: `app.quit`
- ❌ **startSpeaking**: Maybe an applescript could be used for this, but this feature probably be provided by Electron itself.
- ❌ **stopSpeaking**: Maybe an applescript could be used for this, but this feature probably be provided by Electron itself.
- ❌ **zoom**: Maybe an applescript could be used for this, but this feature probably be provided by Electron itself.
- ❌ **recentDocuments**
- ✅ **clearRecentDocuments** `app.clearRecentDocuments`

---

- ❌ **hide**
- `BrowserWindow#getAllWindows` doesn't return the devtools window.
- Once I call `BrowserWindow#hide` I can't show up the window anymore for some reason, Dock -> Show All Windows doesn't show it.
- A `BrowserWindow.hideAll` could be nice to have.
- ❌ **hideOthers**: Maybe an applescript could be used for this, but this feature probably be provided by Electron itself.
- ❌ **unhide**: Maybe an applescript could be used for this, but this feature probably be provided by Electron itself.
- This role doesn't seem to have a great name, it seems the inverse of the `hide` role, but `hide` hides only our Electron app, while `unhide` unhides everything.
- ❌ **front**: Maybe `BrowserWindow#focus` could be called on all windows retrieved via `BrowserWindow#getAllWindows` for this, but `BrowserWindow#getAllWindows` doesn't actually return all windows (no devtools, and there's no method for changing the visibility of the devtools window).
- ✅ **mergeAllWindows**: `BrowserWindow#mergeAllWindows`.

---

- ✅ **selectNextTab**: `BrowserWindow#selectNextTab`.
- ✅ **selectPreviousTab**: `BrowserWindow#selectPreviousTab`.
- ✅ **toggleTabBar**: `BrowserWindow#toggleTabbar`.
- ✅ **moveTabToNewWindow**: `BrowserWindow#moveTabToNewWindow`.

---

It'd be nice if the actions that can currently only be triggered via a menu item with the appropriate role could be triggered programmatically too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.