feat(desktop): save and restore window state

pull/81/head
moonrailgun 3 years ago
parent e1a8110aaf
commit e6bd06bf73

@ -31,6 +31,7 @@
"typescript": "~4.5.4" "typescript": "~4.5.4"
}, },
"dependencies": { "dependencies": {
"electron-squirrel-startup": "^1.0.0" "electron-squirrel-startup": "^1.0.0",
"electron-window-state": "^5.0.3"
} }
} }

@ -1,5 +1,6 @@
import { app, BrowserWindow } from 'electron'; import { app, BrowserWindow } from 'electron';
import path from 'path'; import path from 'path';
import windowStateKeeper from 'electron-window-state';
const isDev = !app.isPackaged; const isDev = !app.isPackaged;
const webUrl = isDev const webUrl = isDev
@ -13,10 +14,17 @@ if (require('electron-squirrel-startup')) {
} }
const createWindow = (): void => { const createWindow = (): void => {
const mainWindowState = windowStateKeeper({
defaultWidth: 960,
defaultHeight: 640,
});
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
height: 640, x: mainWindowState.x,
width: 960, y: mainWindowState.y,
height: mainWindowState.height,
width: mainWindowState.width,
minHeight: 640, minHeight: 640,
minWidth: 960, minWidth: 960,
center: true, center: true,
@ -29,6 +37,8 @@ const createWindow = (): void => {
mainWindow.loadURL(webUrl); mainWindow.loadURL(webUrl);
mainWindowState.manage(mainWindow);
if (isDev) { if (isDev) {
// Open the DevTools. // Open the DevTools.
mainWindow.webContents.openDevTools(); mainWindow.webContents.openDevTools();

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save