[solved] How to properly use the Rectangle Object in `win.SetBounds()` method?


I am prototyping some keybindings but am running into an issue when trying to move and resize my BrowserWindow.

Here is my code:

const electron = require('electron')
const {app, BrowserWindow, globalShortcut} = require('electron')

app.on('ready', () => {
  globalShortcut.register('CommandOrControl+Alt+Right', () => {
    let display = electron.screen.getPrimaryDisplay()
    let win = BrowserWindow.getFocusedWindow()

     x: display.width / 2,
     y: 0,
     width: display.width / 2,
     height: display.height
   }, true)

When trying to use the keybindings, I get an error dialog:

A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: Error processing argument at index 0, conversion failure from #Object
at Function.globalShortcut.register (/path-to-file/shortcuts.js:9:9)

The setBounds documentation is a bit scant, but I believe I am doing what it intends by using an object to denote the desired x, y, width and height values.


I figured it out.

I was using let display = electron.screen.getPrimaryDisplay() and determining width and height using display.width and display.height

This will not work. Instead I have switched to:
let {width, height} = electron.screen.getPrimaryDisplay().workAreaSize and it works perfectly