Skip to content

Commit

Permalink
Persist window state
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Jan 14, 2020
1 parent 6ec0c40 commit 66b71f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ const mainMenuTemplate = [{
}]
}];

// Window State Persistence Data
const windowState = new Store({
name: 'windowState',
defaults: {
bounds: {
x: 0,
y: 0,
width: 800,
height: 600,
},
isMaximized: false,
}
});

// Using singleInstanceLock for making app single instance
const singleInstanceLock = app.requestSingleInstanceLock();

Expand Down Expand Up @@ -494,14 +508,13 @@ if (!singleInstanceLock) {
},
// Hides main window until it is ready to show
show: false,
// Minimum width
minWidth: 818,
// Minimum height
minHeight: 636
});

// Maximizes the main window
mainWindow.maximize();
mainWindow.setBounds(windowState.get('bounds'));

if (windowState.get('isMaximized')) {
mainWindow.maximize();
}

// Shows window once ready
mainWindow.once('ready-to-show', () => {
Expand All @@ -517,6 +530,9 @@ if (!singleInstanceLock) {

// Main Window Close Event
mainWindow.on('close', e => {
// Store window bounds & maximize data
windowState.set('bounds', mainWindow.getBounds());
windowState.set('isMaximized', mainWindow.isMaximized());
// Checks if "app.showExitPrompt" variable is true
if (app.showExitPrompt) {
// Stops app from closing in usual manner
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altus",
"version": "3.2.0",
"version": "3.3.0",
"description": "Electron-based desktop wrapper for WhatsApp Web",
"homepage": "https://shadythgod.github.io/altus",
"repository": {
Expand Down

0 comments on commit 66b71f0

Please sign in to comment.