{"id":18786836,"url":"https://github.com/chfoidl/electron-window-state-manager","last_synced_at":"2025-04-13T13:07:54.135Z","repository":{"id":57221982,"uuid":"49529566","full_name":"chfoidl/electron-window-state-manager","owner":"chfoidl","description":"Window-state manager for electron","archived":false,"fork":false,"pushed_at":"2017-12-09T00:10:03.000Z","size":21,"stargazers_count":25,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T04:11:50.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chfoidl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-12T21:20:09.000Z","updated_at":"2024-09-02T15:36:18.000Z","dependencies_parsed_at":"2022-08-31T08:31:39.177Z","dependency_job_id":null,"html_url":"https://github.com/chfoidl/electron-window-state-manager","commit_stats":null,"previous_names":["sethorax/electron-window-state-manager"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Felectron-window-state-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Felectron-window-state-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Felectron-window-state-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Felectron-window-state-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chfoidl","download_url":"https://codeload.github.com/chfoidl/electron-window-state-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717242,"owners_count":21150389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:52:41.138Z","updated_at":"2025-04-13T13:07:54.114Z","avatar_url":"https://github.com/chfoidl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-window-state-manager [![Build Status](https://travis-ci.org/Sethorax/electron-window-state-manager.svg?branch=master)](https://travis-ci.org/Sethorax/electron-window-state-manager) [![Build status](https://ci.appveyor.com/api/projects/status/eude9rmxi0oi1pe8/branch/master?svg=true)](https://ci.appveyor.com/project/Sethorax/electron-window-state-manager/branch/master)\n\nThe 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.\n\n# Installation\n```\nnpm install electron-window-state-manager\n```\n\n# What does it do?\n\nThe 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.  \nThe saved state can than later be retreived when using the same window name at the instance creation.\nThe saved state's data will be automatically retreived when creating a `WindowStateManager`instance with an already saved window name.\n\n## Usage\n\nTo be able to use this package in your project you need to require it:\n```javascript\nconst WindowStateManager = require('electron-window-state-manager');\n```\n\n#### Class: WindowStateManager\n\nIt creates a new `WindowStateManager` with a `name` and default properties as set by the `options`.\n\n### `new WindowStateManager(name, [options])`\n\n* `name` String - Name of the window.\n* `options` Object\n  * `defaultWidth` Integer - Default window width in pixels.\n  * `defaultHeight` Integer - Default window height in pixels.\n\nThe 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.\n\nIf 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.\n\n### Methods\n\nThe `WindowStateManager` class has the following methods:\n\n#### `WindowStateManager.saveState(window)`\n\n* `window` [BrowserWindow](https://github.com/atom/electron/blob/master/docs/api/browser-window.md)\n\nSaves the state of the passed `BrowserWindow` and returns `true`or `false` depending on whether the state was successfully saved to the json file.\n\nIn 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.\n\nThe 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.\n\nIf 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.\nHowever 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.\n\n\n## Example\n```javascript\nconst app = require('electron').app;\nconst BrowserWindow = require('electron').BrowserWindow;\nconst WindowStateManager = require('electron-window-state-manager');\n\nconst mainWindow;\n\n// Create a new instance of the WindowStateManager\n// and pass it the name and the default properties\nconst mainWindowState = new WindowStateManager('mainWindow', {\n    defaultWidth: 1024,\n    defaultHeight: 768\n});\n\napp.on('ready', () =\u003e {\n    // When creating a new BrowserWindow\n    // you can assign the properties of the mainWindowState.\n    // If a window with the name 'main' was saved before,\n    // the saved values will now be assigned to the BrowserWindow again\n    mainWindow = new BrowserWindow({\n        width: mainWindowState.width,\n        height: mainWindowState.height,\n        x: mainWindowState.x,\n        y: mainWindowState.y,\n    });\n\n    // You can check if the window was closed in a maximized saveState\n    // If so you can maximize the BrowserWindow again\n    if (mainWindowState.maximized) {\n        mainWindow.maximize();\n    }\n\n    // Don't forget to save the current state\n    // of the Browser window when it's about to be closed\n    mainWindow.on('close', () =\u003e {\n        mainWindowState.saveState(mainWindow);\n    });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoidl%2Felectron-window-state-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchfoidl%2Felectron-window-state-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoidl%2Felectron-window-state-manager/lists"}