Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping track of window size in electron

Tags:

electron

I'm just starting to play with Electron today. I need to be able to get the available window size, and to update it on the window resize.

It seems that this isn't as simple as it is in a conventional JS app. What's the recommended way for keeping track of the window size?

At the moment, I have my main process and a single renderer, with no plans to have more than 1 renderer/window open at a time.

I have tried to use the following, but it seems completely wrong so I must have misunderstood the docs.

const {BrowserWindow} = require('electron').remote
BrowserWindow.getSize()

EDIT:

Is it reasonable to keep track of the height by watching the body of the app? I can set this to 100% width/height and watch it, but it seems a bit of a hack.

Thanks Tom

like image 912
tom_h Avatar asked Oct 15 '25 11:10

tom_h


1 Answers

you can try

const electron = require('electron')
const remote = electron.remote

remote.getCurrentWindow().webContents.getOwnerBrowserWindow().getBounds()

Bounds will have co-ordinate and size of current window,

{ 
  height: 1040,
  width : 837,
  x : 276,
  y : 78 
}
like image 60
manirikhi Avatar answered Oct 19 '25 12:10

manirikhi