mawie81 / electron-window-state

A library to store and restore window sizes and positions for your Electron app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App off the screen if user selects a different display as their main and then launches the electron app

mseltene opened this issue · comments

When a user changes their main display (2 monitors windows 10: right click on desktop -> display settings -> make this my main display), then electron-windows-state does not detect this and instead of resetting the coordinates, it shows on the old coordinates, which launches off the screen. The solution would be the user reverts their main display selection and then launch the app and move it to different monitor, and then reelects main display and then the app starts okay. If there is any I am missing in the code, please kindly advice, or is there a way to reset x, y coordinates or detect if the app is in the visible zone.

temporary fix,
let electron = require('electron')
let frame;
frame = new BrowserWindow({.....})
...
...
...
frame.once('ready-to-show', () => {
frame.show();
if(frame.getPosition()[0] > electron.screen.getAllDisplays()[0].bounds.width || frame.getPosition()[0] < 0){frame.setPosition(200,50,true)}
});

It will be also nice if we can catch screen change event at run time and move app in primary screen when display attached is removed.
Ref: https://electronjs.org/docs/api/screen

We can fix this on our app but any chance to get this fix in this npm which will give advantage to all.

@micsel @pashvin This issue should have been fixed in the latest version 5.0.3

Please check and close this issue if solved.