electron-window-plus

1.3.5 • Public • Published

electron-window-plus

Linux Build Status Windows Build status Dependency Status devDependency Status

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 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 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 string
  • listener function

Adds an event listener function.

windowPlus.off (eventName, listener)

  • eventName string
  • listener function

Removes an event listener function.

windowPlus.once (eventName, listener)

  • eventName string
  • listener 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

Readme

Keywords

Package Sidebar

Install

npm i electron-window-plus

Weekly Downloads

6

Version

1.3.5

License

MIT

Last publish

Collaborators

  • johnnywu