electron-toolkit icon indicating copy to clipboard operation
electron-toolkit copied to clipboard

Zoom out does not work when optimizer is enabled with defaults

Open mrmartineau opened this issue 5 months ago • 0 comments

Describe the bug

I have been debugging this for longer than I'd care to admit.. I have a custom menu config like so:

{
  label: "Zoom in",
  role: "zoomIn",
  accelerator: "CmdOrCtrl+Plus",
  click: function (_item, focusedWindow): void {
    // do stuff
  },
},
{
  label: "Zoom out",
  role: "zoomOut",
  accelerator: "CmdOrCtrl+-",
  click: function (_item, focusedWindow): void {
      // do stuff
  },
},
{
  label: "Reset Zoom",
  role: "resetZoom",
  accelerator: "CmdOrCtrl+0",
  click: function (_item, focusedWindow): void {
      // do stuff
  },
},

Both "zoom in" and "reset zoom" worked as expected but "zoom out" did not. I changed the accelerator to other combinations and it would work and I was at a loss until I searched through my code for "shortcut", the optimizer.watchWindowShortcuts(window) came up. I must have misunderstood the purpose of the method because I didn't think it affected zooming until I searched the source code.

I think the logic here is incorrect such that if you use the suggestion in the docs: optimizer.watchWindowShortcuts(window) it incorrectly disables zoom out or CmdOrCtrl+-

If I set zoom to false everything works as expected:

optimizer.watchWindowShortcuts(window, {
  zoom: true,
  escToCloseWindow: false,
});

Also, interestingly I was forced to have the escToCloseWindow option there because of a TypeScript issue:

image

For what it's worth, using CmdOrCtrl+numsub wasn't affected by this issue.

Ultimately I don't think I'll actually use this method at all because my app doesn't need those things disabled, but I thought I should report it anyway.

Electron-Toolkit Version

3.0.0

Electron Version

32.1.0

Validations

mrmartineau avatar Sep 13 '24 10:09 mrmartineau