Keep window ratio in electronjs

Tags: ,



How can I keep the window width and height aspect ratio in electron?

For example, a square shape that can be resized by the user.

Answer

There’s a win.setAspectRatio API for the BrowserWindow.

Note that it’s currently only available on macOS on the latest stable (Electron 8.2.1), but should be available on Linux as of Electron 9.

PR #18306 attempts to add support for Windows, but hasn’t been accepted yet.



Source: stackoverflow