Skip to content

Commit

Permalink
Save window position and size (#38)
Browse files Browse the repository at this point in the history
* ADDED: window size/pos snapshot
  • Loading branch information
warpdesign authored May 6, 2019
1 parent d37f2c9 commit 5f60796
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 29 additions & 3 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@ const WINDOW_DEFAULT_SETTINGS = {
width: 800,
height: 600
};
const WIN_STATE_TPL = 'win.%s.state.json';

const ElectronApp = {
mainWindow: <Electron.BrowserWindow>null,
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5f60796

Please sign in to comment.