Repository navigation
Closed
Labels
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#toggleFullscreenmethod would be nice to have.
- A
- ✅ 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#getAllWindowsdoesn't return the devtools window.- Once I call
BrowserWindow#hideI can't show up the window anymore for some reason, Dock -> Show All Windows doesn't show it. - A
BrowserWindow.hideAllcould 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
hiderole, buthidehides only our Electron app, whileunhideunhides everything.
- This role doesn't seem to have a great name, it seems the inverse of the
- ❌ front: Maybe
BrowserWindow#focuscould be called on all windows retrieved viaBrowserWindow#getAllWindowsfor this, butBrowserWindow#getAllWindowsdoesn'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.
Reacted by Sindre Sorhus
Activity
bpasero commentedon Mar 2, 2020
@fabiospampinato have you looked at
Menu.sendActionToFirstResponder?fabiospampinato commentedon Mar 2, 2020
@bpasero no 😱 thanks for the link! Apparently here there's also a list of native actions some roles map to.
I'm keeping this open because:
Menu.sendActionToFirstReponderMenu.sendActionToFirstReponderAPI was better documented / more approachable, I would totally at the very least link this and this in the docspasteAndMatchStyleI'm not finding itunhiderole are only enabled if there actually are any hidden apps, I don't think there are any APIs for understanding if that's the case so this logic doesn't seem entirely reimplementable