3

This question is specific to electron-quick-start, so it's not a duplicate.

I'm in the very first steps of JS desktop apps with https://github.com/electron/electron-quick-start, I have the code and I can run the app on my mac(hine).

I've note It's possible to zoon in/out the text on the app, which is a feature common to web. Not so common to desktop apps.

How do I disable that behavior?

KcFnMi
  • 4,665
  • 8
  • 52
  • 106

4 Answers4

9

If you want to do the same, but in the Main Process (in your case in main.js), you can do this :

let webContents = mainWindow.webContents
webContents.on('did-finish-load', () => {
  webContents.setZoomFactor(1)
  webContents.setVisualZoomLevelLimits(1, 1)
  webContents.setLayoutZoomLevelLimits(0, 0)
})
popod
  • 309
  • 3
  • 9
5

Add the following to the JavaScript file that your rendered html file is sourcing in (see, main process vs renderer process).

var webFrame = require('electron').webFrame;
webFrame.setVisualZoomLevelLimits(1, 1);
webFrame.setLayoutZoomLevelLimits(0, 0);

In your case, it's renderer.js for the electron-quick-start app.

Documentation: https://github.com/electron/electron/blob/master/docs/api/web-frame.md#webframesetzoomlevellimitsminimumlevel-maximumlevel

therobinkim
  • 2,295
  • 12
  • 20
2

The setVisualZoomLevelLimits command is deprecated.

var app = require('electron')
app.commandLine.appendSwitch('disable-pinch');

Solution found by mixing these two links:

1 - https://github.com/electron/electron/issues/8793#issuecomment-289791853

2 - https://github.com/electron/electron/blob/master/docs/api/chrome-command-line-switches.md

Carlos Oliveira
  • 738
  • 9
  • 22
0

It appears that adding the following to renderer.js does the job:

var webFrame = require('electron').webFrame;
    webFrame.setVisualZoomLevelLimits(1,1);
require('electron').webFrame.setLayoutZoomLevelLimits(0, 0);

Both, zoom via mouse and via Ctrl++/Ctrl+- are disabled.

If some one has comments or a better answer I'll appreciate.

KcFnMi
  • 4,665
  • 8
  • 52
  • 106