npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

electron-win-state

v1.1.22

Published

Store and restore your Electron Window Size and Position

Readme

🖼️💾 Electron Window State

Node CI Release CI GitHub David

Store and restore your Electron Window's Size and Position.

Features

  • 💾 Persistent - persistently stores your Electron Window's size and position
  • 🔌 Easy integration - integrates easily with your existing BrowserWindow configuration
  • 🔨 Customization - customize the behaviour and the underlying electron-store instance
  • 🖼️ Frame option - you can optionally store the frame option as well

🚀 Get started

npm install electron-win-state

Requires Electron 11 or later

📚 Usage

The easiest way to use electron-win-state, is to add it as a wrapper around your normal BrowserWindow:

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	width: 800,
	height: 600,
	// your normal BrowserWindow options...
})

This will create a new BrowserWindow with the provided options and store any changes once the window is closed.

Thats it! Your Electron app now has a persistent window! 🎉

Manually

You can also use electron-win-state manually:

const winState = new WinState({ 
	defaultWidth: 800,
	defaultHeight: 600,
	// other winState options, see below
})

const browserWindow = new BrowserWindow({
	...winState.winOptions,
	// your normal BrowserWindow options...
})

// Attach the required event listeners
winState.manage(this.browserWindow)

With winState.winOptions you have access to the restored size and position of the window:

console.log(winState.winOptions) // => { width: 800, height: 600, x: 0, y: 0, frame: true }

⚙️ Options

You can customize the behaviour of electron-win-state further, by passing an options object to new WinState() or by specifying a winState object when using .createBrowserWindow():

new WinState({ 
	defaultWidth: 800,
	defaultHeight: 600,
	dev: true,
	addMethods: true
})

Or:

WinState.createBrowserWindow({
    winState: {
		defaultWidth: 800,
		defaultHeight: 600,
		dev: true,
		addMethods: true
	}
})

Or:

WinState.createBrowserWindow({
	width: 800,
	height: 600,
	winState: {
		dev: true,
		addMethods: true
	}
})

All of these result in the same.

Here are all the options electron-win-state supports:

| Name | Type | Description | Default | | ------------- | ------------- | ------------- | ------------- | | defaultWidth | number | The default width which will be used when no stored value was found | 800 | | defaultHeight | number | The default height which will be used when no stored value was found | 600 | | defaultFrame | boolean | The default value for the frame option when no stored value was found | true | | storeFrameOption | boolean | Store and restore the frame option (will be enabled automatically if defaultFrame is provided) | false | | dev | boolean | Enable development mode. Changes will be stored immediately after resizing or moving and not just after closing a window | false | | addMethods | boolean | Add the .resetWindowToDefault(), .setFramed() and .getStoredWinOptions() methods to the provided BrowserWindow | true | | electronStoreOptions | object | Will be passed to the underlying electron-store instance | { name: 'window-state' } | | store | instance | An existing electron-store instance to use | n/a |

📖 Examples

Here are a few examples to help you get started!

Basic Example

This is the most basic example. A new BrowserWindow will be created and the required event listeners will be attached automatically.

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	width: 800,
	height: 600
})

browserWindow.loadURL('https://github.com/BetaHuhn/electron-win-state')

Development Mode

During development it might be helpful to store the window size and position immediately after changing it and not just after closing the window. You can enable this functionality by setting dev to true:

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	width: 800,
	height: 600,
	winState: {
		dev: true
	}
})

browserWindow.loadURL('https://github.com/BetaHuhn/electron-win-state')

Resetting the Window

If addMethods is enabled (it is by default) a .resetWindowToDefault() method will be added to the provided BrowserWindow and can be used to both reset the stored state, as well as resizing the window to it's defaults:

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	width: 800,
	height: 600,
	winState: {
		dev: true
	}
})

// Later
browserWindow.resetWindowToDefault()

This method could also be accessed anywhere else in your Electron app by getting the currently focused window:

const browserWindow = BrowserWindow.getFocusedWindow()
browserWindow.resetWindowToDefault()

Storing the frame option

You can optionally store the frame option as well. This might be useful if you want your users to enable or disable the window frame and store their choice.

If storeFrameOption is enabled (or defaultFrame is provided) the frame or defaultFrame option will be stored and can be later changed with the .setFramed() method on the provided BrowserWindow (will be added if addMethods is true).

You have to recreate the window for the frame option to take effect

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	width: 800,
	height: 600,
	frame: false,
	winState: {
		storeFrameOption: true
	}
})

// Later
browserWindow.setFramed(true)

This method could also be accessed anywhere else in your Electron app by getting the currently focused window:

const browserWindow = BrowserWindow.getFocusedWindow()
browserWindow.setFramed(true)

Get stored values

You can access the restored window size and position with the winOptions object:

const winState = new WinState({ 
	defaultWidth: 800,
	defaultHeight: 600,
	defaultFrame: false
})

winState.winOptions // => { width: 1200, height: 700, x: 50, y: 105, frame: true }

You can get the stored values at any time using the added .getStoredWinOptions() method on the BrowserWindow (only added if addMethods is true):

import WinState from 'electron-win-state'

const browserWindow = WinState.createBrowserWindow({
	winState: {
		defaultWidth: 800,
		defaultHeight: 600,
		defaultFrame: false
	}
})

browserWindow.getStoredWinOptions() // => { width: 1200, height: 700, x: 50, y: 105, frame: true }

💻 Development

Issues and PRs are very welcome!

  • run yarn lint or npm run lint to run eslint.
  • run yarn watch or npm run watch to watch for changes.
  • run yarn build or npm run build to produce a compiled version in the lib folder.

❔ About

This project was developed by me (@betahuhn) in my free time. If you want to support me:

Donate via PayPal

ko-fi

Credit

This library uses the great electron-store by @sindresorhus under the hood and was inspired by electron-window-state and electron-boilerplate.

📄 License

Copyright 2021 Maximilian Schiller

This project is licensed under the MIT License - see the LICENSE file for details.