electron-window-plus
v1.3.5
Published
Save and restore window states.
Downloads
42
Readme
electron-window-plus
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...
Why this module?
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.
Install
npm install --save electron-window-plus
Run Examples:
npm start examples/${name}
Usage
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`);
}
});
API Reference
Methods
windowPlus.restore ([defaultUrl, opts])
defaultUrl
stringopts
options
windowPlus.manage (win[, uuid, userdata])
win
BrowserWindowuuid
stringuserdata
object
windowPlus.unmanage (win)
win
BrowserWindow|number
windowPlus.getUserData (win)
win
BrowserWindow|number
windowPlus.updateUserData (win, userdata)
win
BrowserWindow|numberuserdata
object
windowPlus.save ()
windowPlus.loadURL (win, url, argv)
win
BrowserWindowstring
urlobject
argv
windowPlus.adjust (win, x, y, w, h)
win
BrowserWindowx
numbery
numberw
numberh
number
Try to adjust the window to fit the position and size we give
windowPlus.adjustToMain (win)
win
BrowserWindow
Adjust window position to make it open in the same display screen as main window
windowPlus.on (eventName, listener)
eventName
stringlistener
function
Adds an event listener function.
windowPlus.off (eventName, listener)
eventName
stringlistener
function
Removes an event listener function.
windowPlus.once (eventName, listener)
eventName
stringlistener
function
Adds a one time event listener function.
Properties
windowPlus.main
The main window.
Events
'manage'
Emit when window get managed via windowPlus.manage()
.
'unmanage'
Emit when window unmanaged via windowPlus.unmanage()
.
'save'
Emit when window profile saved.
'main-window-failed'
Emit when main window loading failed.
License
MIT © 2017 Johnny Wu