{"action":"created","issue":{"url":"https://api.github.com/repos/sindresorhus/module-requests/issues/9","labels_url":"https://api.github.com/repos/sindresorhus/module-requests/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/sindresorhus/module-requests/issues/9/comments","events_url":"https://api.github.com/repos/sindresorhus/module-requests/issues/9/events","html_url":"https://github.com/sindresorhus/module-requests/issues/9","id":93041856,"number":9,"title":"electron-window-state","user":{"login":"dylang","id":51505,"avatar_url":"https://avatars.githubusercontent.com/u/51505?v=3","gravatar_id":"","url":"https://api.github.com/users/dylang","html_url":"https://github.com/dylang","followers_url":"https://api.github.com/users/dylang/followers","following_url":"https://api.github.com/users/dylang/following{/other_user}","gists_url":"https://api.github.com/users/dylang/gists{/gist_id}","starred_url":"https://api.github.com/users/dylang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylang/subscriptions","organizations_url":"https://api.github.com/users/dylang/orgs","repos_url":"https://api.github.com/users/dylang/repos","events_url":"https://api.github.com/users/dylang/events{/privacy}","received_events_url":"https://api.github.com/users/dylang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-04T19:47:03Z","updated_at":"2015-10-23T21:36:17Z","closed_at":null,"body":"## Problem\r\n\r\nElectron does not save/restore window size and position between loads.\r\n\r\n## Solution\r\n\r\nA library for storing and loading window state. \r\n\r\nSome logic might be required for plugging in and unplugging from a multi-monitor setup.\r\n\r\nElectron lets you save state in files or localStorage. I'm not sure if one is better than the other."},"comment":{"url":"https://api.github.com/repos/sindresorhus/module-requests/issues/comments/150699189","html_url":"https://github.com/sindresorhus/module-requests/issues/9#issuecomment-150699189","issue_url":"https://api.github.com/repos/sindresorhus/module-requests/issues/9","id":150699189,"user":{"login":"floydpink","id":171072,"avatar_url":"https://avatars.githubusercontent.com/u/171072?v=3","gravatar_id":"","url":"https://api.github.com/users/floydpink","html_url":"https://github.com/floydpink","followers_url":"https://api.github.com/users/floydpink/followers","following_url":"https://api.github.com/users/floydpink/following{/other_user}","gists_url":"https://api.github.com/users/floydpink/gists{/gist_id}","starred_url":"https://api.github.com/users/floydpink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floydpink/subscriptions","organizations_url":"https://api.github.com/users/floydpink/orgs","repos_url":"https://api.github.com/users/floydpink/repos","events_url":"https://api.github.com/users/floydpink/events{/privacy}","received_events_url":"https://api.github.com/users/floydpink/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T21:36:17Z","updated_at":"2015-10-23T21:36:17Z","body":"[One of the boilerplates](https://github.com/szwacz/electron-boilerplate) mentioned in [awesome-electron](https://github.com/sindresorhus/awesome-electron) has [a module](https://github.com/szwacz/electron-boilerplate/blob/master/app/vendor/electron_boilerplate/window_state.js) that does this:\r\n\r\n```\r\n// Simple module to help you remember the size and position of windows.\r\n// Can be used for more than one window, just construct many\r\n// instances of it and give each different name.\r\n\r\n'use strict';\r\n\r\nvar app = require('app');\r\nvar jetpack = require('fs-jetpack');\r\n\r\nmodule.exports = function (name, defaults) {\r\n\r\n    var userDataDir = jetpack.cwd(app.getPath('userData'));\r\n    var stateStoreFile = 'window-state-' + name +'.json';\r\n\r\n    var state = userDataDir.read(stateStoreFile, 'json') || {\r\n        width: defaults.width,\r\n        height: defaults.height\r\n    };\r\n\r\n    var saveState = function (win) {\r\n        if (!win.isMaximized() && !win.isMinimized()) {\r\n            var position = win.getPosition();\r\n            var size = win.getSize();\r\n            state.x = position[0];\r\n            state.y = position[1];\r\n            state.width = size[0];\r\n            state.height = size[1];\r\n        }\r\n        state.isMaximized = win.isMaximized();\r\n        userDataDir.write(stateStoreFile, state, { atomic: true });\r\n    };\r\n\r\n    return {\r\n        get x() { return state.x; },\r\n        get y() { return state.y; },\r\n        get width() { return state.width; },\r\n        get height() { return state.height; },\r\n        get isMaximized() { return state.isMaximized; },\r\n        saveState: saveState\r\n    };\r\n};\r\n```\r\n\r\nMaybe that can be built as an npm module with some nice tests etc."}}