diff --git a/package-lock.json b/package-lock.json index cc09ffe4..477bd51f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2785,6 +2785,15 @@ } } }, + "electron-window-state": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-5.0.3.tgz", + "integrity": "sha512-1mNTwCfkolXl3kMf50yW3vE2lZj0y92P/HYWFBrb+v2S/pCka5mdwN3cagKm458A7NjndSwijynXgcLWRodsVg==", + "requires": { + "jsonfile": "^4.0.0", + "mkdirp": "^0.5.1" + } + }, "elliptic": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", @@ -4201,8 +4210,7 @@ "graceful-fs": { "version": "4.1.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", - "dev": true + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, "gud": { "version": "1.0.0", @@ -5070,7 +5078,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } diff --git a/package.json b/package.json index ccca8c8f..be6d4019 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "basic-ftp": "^3.2.2", "classnames": "^2.2.6", "del": "^3.0.0", + "electron-window-state": "^5.0.3", "get-folder-size": "^2.0.0", "i18next": "^13.0.0", "mkdirp": "^0.5.1", diff --git a/src/electron/main.ts b/src/electron/main.ts index 8374c65d..c7f669fc 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -3,6 +3,7 @@ import * as process from 'process'; import { watch } from 'fs'; import { AppMenu, LocaleString } from './appMenus'; import { isPackage } from '../utils/platform'; +import * as windowStateKeeper from 'electron-window-state'; declare var __dirname: string declare var ENV: any; @@ -15,6 +16,7 @@ const WINDOW_DEFAULT_SETTINGS = { width: 800, height: 600 }; +const WIN_STATE_TPL = 'win.%s.state.json'; const ElectronApp = { mainWindow: null, @@ -53,15 +55,26 @@ const ElectronApp = { */ createMainWindow() { console.log('Create Main Window'); + + const winState = windowStateKeeper({ + defaultWidth: WINDOW_DEFAULT_SETTINGS.width, + defaultHeight: WINDOW_DEFAULT_SETTINGS.height, + file: WIN_STATE_TPL.replace('%s', "0") + }); + this.mainWindow = new BrowserWindow({ minWidth: WINDOW_DEFAULT_SETTINGS.minWidth, - width: WINDOW_DEFAULT_SETTINGS.width, - height: WINDOW_DEFAULT_SETTINGS.height, + width: winState.width, + height: winState.height, + x: winState.x, + y: winState.y, webPreferences: { enableBlinkFeatures: 'OverlayScrollbars,OverlayScrollbarsFlashAfterScrollUpdate,OverlayScrollbarsFlashWhenMouseEnter' } }); + winState.manage(this.mainWindow); + this.mainWindow.loadURL(HTML_PATH); // this.mainWindow.on('close', () => app.quit()); @@ -191,7 +204,20 @@ const ElectronApp = { // spectron problem if devtools is opened, see https://github.com/electron/spectron/issues/254 if ((!ENV_E2E && !isPackage) || force) { if (!this.devWindow || this.devWindow.isDestroyed()) { - this.devWindow = new BrowserWindow(); + const winState = windowStateKeeper({ + defaultWidth: WINDOW_DEFAULT_SETTINGS.width, + defaultHeight: WINDOW_DEFAULT_SETTINGS.height, + file: WIN_STATE_TPL.replace('%s', "devtools") + }); + + this.devWindow = new BrowserWindow({ + width: winState.width, + height: winState.height, + x: winState.x, + y: winState.y, + }); + winState.manage(this.devWindow); + this.mainWindow.webContents.setDevToolsWebContents(this.devWindow.webContents); this.mainWindow.webContents.openDevTools({ mode: 'detach' }); } else {