Save and restore window states.
TODO
- Add tests for _mainWindowFailed: windowPlus.loadURL failed and did-fail-load.
- Add tests for userdata update & restore.
- Add test for main window url different to default.
- Add tests for windowPlus.restore().
- Add other tests...
There are several great module such as electron-window-state, electron-window-manager that doing the same thing. What is the advantage of this module compare to them?
- Support save and restore multiple windows.
- Did not introduce new Window class for management.
- Try to recover to default when restore failed.
npm install --save electron-window-plus
npm start examples/${name}
const {app, BrowserWindow} = require('electron');
const windowPlus = require('electron-window-plus');
app.on('ready', function () {
if ( !windowPlus.restore() ) {
let win = new BrowserWindow({
width: 300,
height: 300,
});
windowPlus.manage(win);
windowPlus.loadURL(win, `file://${__dirname}/index.html`);
}
});
defaultUrl
stringopts
options
win
BrowserWindowuuid
stringuserdata
object
win
BrowserWindow|number
win
BrowserWindow|number
win
BrowserWindow|numberuserdata
object
win
BrowserWindowstring
urlobject
argv
win
BrowserWindowx
numbery
numberw
numberh
number
Try to adjust the window to fit the position and size we give
win
BrowserWindow
Adjust window position to make it open in the same display screen as main window
eventName
stringlistener
function
Adds an event listener function.
eventName
stringlistener
function
Removes an event listener function.
eventName
stringlistener
function
Adds a one time event listener function.
The main window.
Emit when window get managed via windowPlus.manage()
.
Emit when window unmanaged via windowPlus.unmanage()
.
Emit when window profile saved.
Emit when main window loading failed.
MIT © 2017 Johnny Wu