diff --git a/app/package.json b/app/package.json index 4d631c05..8a60ab85 100644 --- a/app/package.json +++ b/app/package.json @@ -25,6 +25,7 @@ "author": "Ramiro Saenz", "license": "MIT", "dependencies": { + "electron-window-state": "^3.0.3", "firebase": "^3.0.5", "firebase-token-generator": "^2.0.0" } diff --git a/electron/main.js b/electron/main.js index 842218f1..9f82a35c 100644 --- a/electron/main.js +++ b/electron/main.js @@ -13,6 +13,8 @@ const appMenu = require('./menu'); const tray = require('./tray'); // Require for autpUpdate file const autoupdater = require('./autoupdater'); +// Window State Plugin +const windowStateKeeper = require('electron-window-state'); const MenuItem = electron.MenuItem; @@ -91,11 +93,21 @@ let mainWindow; let isQuitting = false; function createWindow () { - // Create the browser window. + // Load the previous state with fallback to defaults + let mainWindowState = windowStateKeeper({ + defaultWidth: 1000 + ,defaultHeight: 800 + ,maximize: true + }); + // Create the browser window using the state information mainWindow = new BrowserWindow({ title: 'Rambox' ,skipTaskbar: false ,icon: __dirname + '/../resources/Icon.png' + ,x: mainWindowState.x + ,y: mainWindowState.y + ,width: mainWindowState.width + ,height: mainWindowState.height ,webPreferences: { webSecurity: false ,nodeIntegration: true @@ -104,10 +116,12 @@ function createWindow () { } }); - process.setMaxListeners(100); + // Let us register listeners on the window, so we can update the state + // automatically (the listeners will be removed when the window is closed) + // and restore the maximized or full screen state + mainWindowState.manage(mainWindow); - // Start maximize - mainWindow.maximize(); + process.setMaxListeners(100); // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/../index.html');