From 76008e8abd3e89eda16d39260e93e570d44cff7f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 12 Apr 2017 18:13:25 +0100 Subject: [PATCH] Remember and Recall window layout so that position+size persist Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron/src/electron-main.js | 16 +++++++++++++++- package.json | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/electron/src/electron-main.js b/electron/src/electron-main.js index 33b44ce9..8dd5e813 100644 --- a/electron/src/electron-main.js +++ b/electron/src/electron-main.js @@ -30,6 +30,8 @@ const tray = require('./tray'); const VectorMenu = require('./vectormenu'); +const windowStateKeeper = require('electron-window-state'); + let vectorConfig = {}; try { vectorConfig = require('../../webapp/config.json'); @@ -186,11 +188,21 @@ electron.app.on('ready', () => { process.platform == 'win32' ? 'ico' : 'png' ); + // Load the previous window state with fallback to defaults + let mainWindowState = windowStateKeeper({ + defaultWidth: 1024, + defaultHeight: 768, + }); + mainWindow = new electron.BrowserWindow({ icon: icon_path, - width: 1024, height: 768, show: false, autoHideMenuBar: true, + + x: mainWindowState.x, + y: mainWindowState.y, + width: mainWindowState.width, + height: mainWindowState.height, }); mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`); electron.Menu.setApplicationMenu(VectorMenu); @@ -226,6 +238,8 @@ electron.app.on('ready', () => { onLinkContextMenu(ev, params); } }); + + mainWindowState.manage(mainWindow); }); electron.app.on('window-all-closed', () => { diff --git a/package.json b/package.json index 28cde389..35ffb87b 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "css-raw-loader": "^0.1.1", "electron-builder": "^11.2.4", "electron-builder-squirrel-windows": "^11.2.1", + "electron-window-state": "^4.1.0", "emojione": "^2.2.7", "eslint": "^3.14.0", "eslint-config-google": "^0.7.1",