Skip to content

Commit

Permalink
window state manager (#608)
Browse files Browse the repository at this point in the history
* window state manager

Merged electron-window-state-manager.
Providing store/restore of window position.

* update package-lock.json

* Update electron-window-state-manager.d.ts

content was missing in initial PR

Co-authored-by: Justin Kim <justinkim943@gmail.com>
  • Loading branch information
stweyel and angle943 authored Apr 22, 2021
1 parent 5bd3cc6 commit 9f94b0a
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 42 deletions.
185 changes: 145 additions & 40 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"dependencies": {
"@thenewboston/ui": "^0.1.5",
"@thenewboston/utils": "^1.0.0",
"app-root-path": "3.0.0",
"axios": "^0.21.1",
"bfj": "^7.0.2",
"camelcase": "^6.1.0",
Expand All @@ -133,6 +134,7 @@
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^5.2.0",
"electron-updater": "^4.3.5",
"electron-window-state-manager": "^0.3.2",
"formik": "^2.2.6",
"fs-extra": "^9.0.1",
"lodash-es": "^4.17.20",
Expand Down
21 changes: 19 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import contextMenu from 'electron-context-menu';
import installExtension, {REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS} from 'electron-devtools-installer';
import fs from 'fs';
import {getFailChannel, getSuccessChannel, IpcChannel} from '@shared/ipc';
import WindowStateManager from 'electron-window-state-manager';
import menu from './menu';

declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
Expand All @@ -20,15 +21,31 @@ contextMenu({

let mainWindow: BrowserWindow;

const mainWindowState = new WindowStateManager('mainWindow', {
defaultHeight: 1080,
defaultWidth: 1920,
});

const createWindow = (): void => {
mainWindow = new BrowserWindow({
height: 1080,
height: mainWindowState.height,
webPreferences: {
nodeIntegration: true,
},
width: 1920,
width: mainWindowState.width,
x: mainWindowState.x,
y: mainWindowState.y,
});

mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);

if (mainWindowState.maximized) {
mainWindow.maximize();
}

mainWindow.on('close', () => {
mainWindowState.saveState(mainWindow);
});
};

// if gotTheLock is false, another instance of application is already running
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'electron-window-state-manager';

0 comments on commit 9f94b0a

Please sign in to comment.