https://github.com/electron-utils/electron-window-plus
Save and restore window states.
https://github.com/electron-utils/electron-window-plus
electron window window-manager
Last synced: 2 months ago
JSON representation
Save and restore window states.
- Host: GitHub
- URL: https://github.com/electron-utils/electron-window-plus
- Owner: electron-utils
- License: mit
- Created: 2017-02-19T14:38:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-21T09:23:11.000Z (about 7 years ago)
- Last Synced: 2023-11-26T13:16:45.951Z (over 1 year ago)
- Topics: electron, window, window-manager
- Language: JavaScript
- Size: 41 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# electron-window-plus
[](https://travis-ci.org/electron-utils/electron-window-plus)
[](https://ci.appveyor.com/project/jwu/electron-window-plus)
[](https://david-dm.org/electron-utils/electron-window-plus)
[](https://david-dm.org/electron-utils/electron-window-plus#info=devDependencies)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](https://github.com/mawie81/electron-window-state), [electron-window-manager](https://github.com/TamkeenLMS/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
```bash
npm install --save electron-window-plus
```## Run Examples:
```bash
npm start examples/${name}
```## Usage
```javascript
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` string
- `opts` options### windowPlus.manage (win[, uuid, userdata])
- `win` BrowserWindow
- `uuid` string
- `userdata` object### windowPlus.unmanage (win)
- `win` BrowserWindow|number
### windowPlus.getUserData (win)
- `win` BrowserWindow|number
### windowPlus.updateUserData (win, userdata)
- `win` BrowserWindow|number
- `userdata` object### windowPlus.save ()
### windowPlus.loadURL (win, url, argv)
- `win` BrowserWindow
- `string` url
- `object` argv### windowPlus.adjust (win, x, y, w, h)
- `win` BrowserWindow
- `x` number
- `y` number
- `w` number
- `h` numberTry 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` string
- `listener` functionAdds an event listener function.
### windowPlus.off (eventName, listener)
- `eventName` string
- `listener` functionRemoves an event listener function.
### windowPlus.once (eventName, listener)
- `eventName` string
- `listener` functionAdds 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