{"id":13402929,"url":"https://github.com/mawie81/electron-window-state","last_synced_at":"2025-05-14T18:06:16.546Z","repository":{"id":1907996,"uuid":"45307461","full_name":"mawie81/electron-window-state","owner":"mawie81","description":"A library to store and restore window sizes and positions for your Electron app","archived":false,"fork":false,"pushed_at":"2024-05-20T21:58:01.000Z","size":320,"stargazers_count":666,"open_issues_count":39,"forks_count":68,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T06:04:12.531Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mawie81.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-31T15:43:06.000Z","updated_at":"2025-05-03T18:21:25.000Z","dependencies_parsed_at":"2024-11-15T14:43:22.767Z","dependency_job_id":null,"html_url":"https://github.com/mawie81/electron-window-state","commit_stats":{"total_commits":65,"total_committers":15,"mean_commits":4.333333333333333,"dds":0.4307692307692308,"last_synced_commit":"2701d9a0f90a44dc8dbf81430538ceb16c9ff27a"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawie81%2Felectron-window-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawie81%2Felectron-window-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawie81%2Felectron-window-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawie81%2Felectron-window-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mawie81","download_url":"https://codeload.github.com/mawie81/electron-window-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"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-07-30T19:01:23.022Z","updated_at":"2025-05-14T18:06:11.533Z","avatar_url":"https://github.com/mawie81.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Tools","Library"],"sub_categories":["For Electron","Position/Size"],"readme":"# electron-window-state [![Build Status](https://travis-ci.org/mawie81/electron-window-state.svg)](https://travis-ci.org/mawie81/electron-window-state)\n\n\u003e A library to store and restore window sizes and positions for your\n[Electron](http://electron.atom.io) app\n\n*Heavily influenced by the implementation in [electron-boilerplate](https://github.com/szwacz/electron-boilerplate).*\n\n## Install\n\n```\n$ npm install --save electron-window-state\n```\n\n## Usage\n\n```js\nconst windowStateKeeper = require('electron-window-state');\nlet win;\n\napp.on('ready', function () {\n  // Load the previous state with fallback to defaults\n  let mainWindowState = windowStateKeeper({\n    defaultWidth: 1000,\n    defaultHeight: 800\n  });\n\n  // Create the window using the state information\n  win = new BrowserWindow({\n    'x': mainWindowState.x,\n    'y': mainWindowState.y,\n    'width': mainWindowState.width,\n    'height': mainWindowState.height\n  });\n\n  // Let us register listeners on the window, so we can update the state\n  // automatically (the listeners will be removed when the window is closed)\n  // and restore the maximized or full screen state\n  mainWindowState.manage(win);\n});\n```\n\nPlease do not set `useContentSize` to `true` at creating `BrowserWindow` instance\nbecause it changes how to calculate window size.\n\n## API\n\n#### windowStateKeeper(opts)\n\nNote: Don't call this function before the `ready` event is fired.\n\n##### opts\n\n`defaultWidth` - *Number*\n\n  The width that should be returned if no file exists yet. Defaults to `800`.\n\n`defaultHeight` - *Number*\n\n  The height that should be returned if no file exists yet. Defaults to `600`.\n\n`path` - *String*\n\n  The path where the state file should be written to. Defaults to\n  `app.getPath('userData')`\n\n`file` - *String*\n\n  The name of file. Defaults to `window-state.json`. This is usefull if you want to support multiple windows. Simply create multiple ```windowStateKeeper``` instances with different filenames.\n\n`maximize` - *Boolean*\n\n  Should we automatically maximize the window, if it was last closed\n  maximized. Defaults to `true`\n\n`fullScreen` - *Boolean*\n\n  Should we automatically restore the window to full screen, if it was last\n  closed full screen. Defaults to `true`\n\n### state object\n\n```js\nconst windowState = windowStateKeeper({\n  defaultWidth: 1000,\n  defaultHeight: 800\n});\n```\n\n`x` - *Number*\n\n  The saved `x` coordinate of the loaded state. `undefined` if the state has not\n  been saved yet.\n\n`y` - *Number*\n\n  The saved `y` coordinate of the loaded state. `undefined` if the state has not\n  been saved yet.\n\n`width` - *Number*\n\n  The saved `width` of loaded state. `defaultWidth` if the state has not been\n  saved yet.\n\n`height` - *Number*\n\n  The saved `heigth` of loaded state. `defaultHeight` if the state has not been\n  saved yet.\n\n`isMaximized` - *Boolean*\n\n  `true` if the window state was saved while the window was maximized.\n  `undefined` if the state has not been saved yet.\n\n`isFullScreen` - *Boolean*\n\n  `true` if the window state was saved while the window was in full screen\n  mode. `undefined` if the state has not been saved yet.\n\n`manage(window)` - *Function*\n\n  Register listeners on the given `BrowserWindow` for events that are\n  related to size or position changes (`resize`, `move`). It will also restore\n  the window's maximized or full screen state.\n  When the window is closed we automatically remove the listeners and save the\n  state.\n\n`unmanage` - *Function*\n\n  Removes all listeners of the managed `BrowserWindow` in case it does not\n  need to be managed anymore.\n\n`saveState(window)` - *Function*\n\n  Saves the current state of the given `BrowserWindow`. This exists mostly for\n  legacy purposes, and in most cases it's better to just use `manage`.\n\n## License\n\nMIT © [Marcel Wiehle](http://marcel.wiehle.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmawie81%2Felectron-window-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmawie81%2Felectron-window-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmawie81%2Felectron-window-state/lists"}