electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.65k stars 1.74k forks source link

Context menu works, but their accelerators shortcut doesn't #1317

Closed heldr closed 7 years ago

heldr commented 7 years ago

Hi,

electron-builder 14.5.3

Context menu works nicely. Their accelerator shortcut doesn't though, only on built version and even if printed on menu:

screen shot 2017-03-01 at 1 11 22 pm

Code:

const { Menu } = require('electron');

const menuSeparator = { type: 'separator' };

const reloadMenuItem = {
  role: 'reload',
  accelerator: 'CmdOrCtrl+R'
};

const copyMenuItem = {
  role: 'copy',
  accelerator: 'CmdOrCtrl+C'
};

const pasteMenuItem = {
  role: 'paste',
  accelerator: 'CmdOrCtrl+V'
};

const contextMenu = Menu.buildFromTemplate([reloadMenuItem]);

const selectionMenu = Menu.buildFromTemplate([
  copyMenuItem,
  pasteMenuItem,
  menuSeparator,
  reloadMenuItem
]);

const inputMenu = Menu.buildFromTemplate([
  {
    role: 'undo',
    accelerator: 'CmdOrCtrl+Z'
  },
  {
    role: 'redo',
    accelerator: 'CmdOrCtrl+Shift+Z'
  },
  menuSeparator,
  {
    role: 'cut',
    accelerator: 'CmdOrCtrl+Shift+X'
  },
  copyMenuItem,
  pasteMenuItem,
  menuSeparator,
  {
    role: 'selectall',
    accelerator: 'CmdOrCtrl+A'
  },
  menuSeparator,
  reloadMenuItem
]);

module.exports = win => win.webContents.on('context-menu', (e, props) => {
  const { selectionText, isEditable } = props;

  if (isEditable) {
    inputMenu.popup(win);
  } else if (selectionText && selectionText.trim() !== '') {
    selectionMenu.popup(win);
  } else {
    contextMenu.popup(win);
  }
});
develar commented 7 years ago

I am on vacation and cannot check, but it works in my sample app. Sorry, I think it is some common, not related to builder issue.

develar commented 7 years ago

May be related https://github.com/electron/electron/issues/2527

heldr commented 7 years ago

It works on electron process, but after build(packaged and stuff), it doesn't.

heldr commented 7 years ago

Sorry to bother you on vacation time. I'd keep the discussion open till you return from it.

akashnimare commented 7 years ago

@heldr can you able to put together a minimized repro-case? That would help me cross testing your issue.

develar commented 7 years ago

@heldr Is it still actual?