{"id":18328315,"url":"https://github.com/thorstenhans/electron-memento","last_synced_at":"2025-04-09T16:54:09.708Z","repository":{"id":57221765,"uuid":"165046991","full_name":"ThorstenHans/electron-memento","owner":"ThorstenHans","description":"Simple module to track position and dimension of an electron window across an application lifecycle","archived":false,"fork":false,"pushed_at":"2019-01-10T15:00:16.000Z","size":77,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T09:20:21.391Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ThorstenHans.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}},"created_at":"2019-01-10T11:20:48.000Z","updated_at":"2019-05-16T16:32:44.000Z","dependencies_parsed_at":"2022-08-29T01:50:50.233Z","dependency_job_id":null,"html_url":"https://github.com/ThorstenHans/electron-memento","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThorstenHans%2Felectron-memento","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThorstenHans%2Felectron-memento/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThorstenHans%2Felectron-memento/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThorstenHans%2Felectron-memento/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThorstenHans","download_url":"https://codeload.github.com/ThorstenHans/electron-memento/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248073969,"owners_count":21043475,"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-05T19:13:44.208Z","updated_at":"2025-04-09T16:54:09.689Z","avatar_url":"https://github.com/ThorstenHans.png","language":"TypeScript","funding_links":["https://www.patreon.com/bePatron?u=16380186"],"categories":[],"sub_categories":[],"readme":"For [Electron](https://electronjs.org/) applications you can specify the size and positioning of `BrowserWindow` instances. No API could be used to store and retrieve those configuration values across an application restart. `electron-memento` will change this. `electron-memento` provides a simple set of APIs that allows you to store and load the `dimension` and the `position` of your application's main window.\n\n`electron-memento` is licensed under [MIT](./LICENSE).\n\n## Build Status\n\n### Release build on `master`\n\n[![Build Status](https://dev.azure.com/thns/electron-memento/_apis/build/status/ThorstenHans.electron-memento?branchName=master)](https://dev.azure.com/thns/electron-memento/_build/latest?definitionId=3?branchName=master)\n\n### CI build on `develop`\n\n[![Build Status](https://dev.azure.com/thns/electron-memento/_apis/build/status/electron-memento-ci?branchName=develop)](https://dev.azure.com/thns/electron-memento/_build/latest?definitionId=4?branchName=develop)\n\n## Support me\n\n[![Become a Patron!](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?u=16380186)\n\n## Install\n\n```\nnpm install electron-memento --save\n```\n\n## Usage\n\n`electron-memento` is meant to be used from within the **main process** of an Electron app. \n\n```\nconst { app, BrowserWindow } = require('electron');\nconst Memento = require('electron-memento');\n\nlet mainWindow;\n\nfunction createWindow() {\n  const bounds = Memento.read();\n  const mainWindowConfig = {\n    width: bounds.width,\n    height: bounds.height,\n    x: bounds.x,\n    y: bounds.y,\n    title: 'Memento Sample'\n  };\n  const mainWindowUrl = 'some-url.html';\n\n  mainWindow = new BrowserWindow(mainWindowConfig);\n  Memento.infect(mainWindow);\n  mainWindow.loadURL(mainWindowUrl);\n  mainWindow.webContents.openDevTools();\n\n  mainWindow.on('closed', () =\u003e {\n    mainWindow = null;\n  });\n}\n // ...\n```\n\n## API\n\n### read\n\nThe `read` method will read the dimension and position from the configuration file. If no configuration exists, either *internal defaults* or default values provided by the caller will be returned.\n\n`read(defaultDimension?: { width: number, height: number }, defaultPosition?: { x: number, y: number }): Rectangle`\nType: `Rectangle`\n\n#### Internal Defaults\nIf you don't specify default values, the window will be `centered` and the dimension will be set to `1000x700 pixels`\n\n\n### writePosition\n\nYou can instruct `electron-memento` explicitly to store the position of the current window by calling the `writePosition` method. It will store the position of `mainApplicationWindow` (`Electron.BrowserWindow`).\n\n`writePosition(mainApplicationWindow: BrowserWindow): void`\n\n\n### writeDimension\n\nYou can instruct `electron-memento` explicitly to store the dimension of the current window by calling the `writeDimension` method. It will store the dimension of `mainApplicationWindow` (`Electron.BrowserWindow`).\n\n`writeDimension(mainApplicationWindow: BrowserWindow): void`\n\n\n### infect\n\nThe `infect` method will register `writePosition` and `writeDimension` to the corresponding events of 'mainApplicationWindow' (`move` and `resize`). Once infected, `electron-memento` will always be invoked to store both,\n`dimension` and `position` of `mainApplicationWindow`. Both `listeners` are unregistered using **explicit** de-registration in `mainApplicationWindow.on('close')`.\n\n`infect(mainApplicationWindow: BrowserWindow): void`\n\n\n## Credits\n\nThe project has been built using [electron-store](https://github.com/sindresorhus/electron-store) from [Sindre Sorhus](https://github.com/sindresorhus).\n\n## Other libraries\n\n* [ngx-electron](https://github.com/ThorstenHans/ngx-electron)\n\n## Copyright\n\n\u0026copy; [Thorsten Hans](https://thorsten-hans.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorstenhans%2Felectron-memento","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthorstenhans%2Felectron-memento","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorstenhans%2Felectron-memento/lists"}