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 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-window-state-manager

v0.3.2

Published

Window-state manager for electron

Downloads

1,366

Readme

electron-window-state-manager Build Status Build status

The Electron Window State Manager is a small package that gives you the ability to save the state of a BrowserWindow and retreive the saved data of the state later.

Installation

npm install electron-window-state-manager

What does it do?

The Window State Manager can store the dimensions (width and height), the position (x and y coordinates) and the current state (maximized or not) of a BrowserWindow and save it to a json file.
The saved state can than later be retreived when using the same window name at the instance creation. The saved state's data will be automatically retreived when creating a WindowStateManagerinstance with an already saved window name.

Usage

To be able to use this package in your project you need to require it:

const WindowStateManager = require('electron-window-state-manager');

Class: WindowStateManager

It creates a new WindowStateManager with a name and default properties as set by the options.

new WindowStateManager(name, [options])

  • name String - Name of the window.
  • options Object
    • defaultWidth Integer - Default window width in pixels.
    • defaultHeight Integer - Default window height in pixels.

The value of name is used to reference a saved state in the json file. If you create a new instance of WindowStateManager with a name which was already saved previously, the data of this state will be loaded.

If a state with the value of name cannot be found in the json file or a saved state has wrong data, the default values assigned in the options Object will be used.

Methods

The WindowStateManager class has the following methods:

WindowStateManager.saveState(window)

Saves the state of the passed BrowserWindow and returns trueor false depending on whether the state was successfully saved to the json file.

In case the state of a window in fullscreen is saved, the saving process will not succeed because we don't want to save the dimensions of a fullscreen window.

The method returns false and will not save anything if a window in fullscreen is saved, because we don't want to save the dimensions of a fullscreen window.

If a maximized window is saved, the dimensions and position of the window will not be stored, only the previously saved values or the default values will be saved. However the maximized state of the window will be saved, so that you can open the window in a maximized state again later if the window was closed in a maximized state.

Example

const app = require('electron').app;
const BrowserWindow = require('electron').BrowserWindow;
const WindowStateManager = require('electron-window-state-manager');

const mainWindow;

// Create a new instance of the WindowStateManager
// and pass it the name and the default properties
const mainWindowState = new WindowStateManager('mainWindow', {
    defaultWidth: 1024,
    defaultHeight: 768
});

app.on('ready', () => {
    // When creating a new BrowserWindow
    // you can assign the properties of the mainWindowState.
    // If a window with the name 'main' was saved before,
    // the saved values will now be assigned to the BrowserWindow again
    mainWindow = new BrowserWindow({
        width: mainWindowState.width,
        height: mainWindowState.height,
        x: mainWindowState.x,
        y: mainWindowState.y,
    });

    // You can check if the window was closed in a maximized saveState
    // If so you can maximize the BrowserWindow again
    if (mainWindowState.maximized) {
        mainWindow.maximize();
    }

    // Don't forget to save the current state
    // of the Browser window when it's about to be closed
    mainWindow.on('close', () => {
        mainWindowState.saveState(mainWindow);
    });
});