Skip to content

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

Closed

Description

@fabiospampinato

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.

Activity

  1. bpasero commented on Mar 2, 2020

    @bpasero
    Contributor
  2. fabiospampinato commented on Mar 2, 2020

    @fabiospampinato
    ContributorAuthor

    @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:

    • I think there's some good actionable feedback in here
      • I would appreciate standalone methods for the actions that can be triggered via the somewhat obscure Menu.sendActionToFirstReponder
      • I would be nice if this Menu.sendActionToFirstReponder API was better documented / more approachable, I would totally at the very least link this and this in the docs
    • If there's an action that can replicate pasteAndMatchStyle I'm not finding it
    • Menu items with the unhide role 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions