Remember Window State

This commit is contained in:
Akshit Kr Nagpal 2018-06-21 01:08:53 +05:30 committed by Saúl Ibarra Corretgé
parent 994a605ce0
commit 93d8268a68
3 changed files with 46 additions and 21 deletions

47
main.js
View file

@ -1,7 +1,13 @@
/* global __dirname, process */ /* global __dirname, process */
const electron = require('electron'); const {
app: APP,
BrowserWindow,
Menu,
shell
} = require('electron');
const isDev = require('electron-is-dev'); const isDev = require('electron-is-dev');
const windowStateKeeper = require('electron-window-state');
const { const {
setupAlwaysOnTopMain, setupAlwaysOnTopMain,
initPopupsConfigurationMain, initPopupsConfigurationMain,
@ -10,8 +16,6 @@ const {
const path = require('path'); const path = require('path');
const URL = require('url'); const URL = require('url');
const { app: APP, BrowserWindow, Menu } = electron;
/** /**
* Load debug utilities (don't open the DevTools window by default though). * Load debug utilities (don't open the DevTools window by default though).
*/ */
@ -38,20 +42,6 @@ const indexURL = URL.format({
*/ */
let jitsiMeetWindow = null; let jitsiMeetWindow = null;
/**
* Options used when creating the main Jitsi Meet window.
*/
const jitsiMeetWindowOptions = {
width: 800,
height: 600,
minWidth: 800,
minHeight: 600,
titleBarStyle: 'hidden',
webPreferences: {
nativeWindowOpen: true
}
};
/** /**
* Sets the APP object listeners. * Sets the APP object listeners.
*/ */
@ -87,7 +77,28 @@ function setAPPListeners() {
function createJitsiMeetWindow() { function createJitsiMeetWindow() {
Menu.setApplicationMenu(null); Menu.setApplicationMenu(null);
// Load the previous state with fallback to defaults
const jitsiMeetWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600
});
// Options used when creating the main Jitsi Meet window.
const jitsiMeetWindowOptions = {
x: jitsiMeetWindowState.x,
y: jitsiMeetWindowState.y,
width: jitsiMeetWindowState.width,
height: jitsiMeetWindowState.height,
minWidth: 800,
minHeight: 600,
titleBarStyle: 'hidden',
webPreferences: {
nativeWindowOpen: true
}
};
jitsiMeetWindow = new BrowserWindow(jitsiMeetWindowOptions); jitsiMeetWindow = new BrowserWindow(jitsiMeetWindowOptions);
jitsiMeetWindowState.manage(jitsiMeetWindow);
jitsiMeetWindow.loadURL(indexURL); jitsiMeetWindow.loadURL(indexURL);
initPopupsConfigurationMain(jitsiMeetWindow); initPopupsConfigurationMain(jitsiMeetWindow);
@ -96,7 +107,7 @@ function createJitsiMeetWindow() {
if (!target || target === 'browser') { if (!target || target === 'browser') {
event.preventDefault(); event.preventDefault();
electron.shell.openExternal(url); shell.openExternal(url);
} }
}); });

19
package-lock.json generated
View file

@ -3503,6 +3503,11 @@
"resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-0.3.8.tgz", "resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-0.3.8.tgz",
"integrity": "sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ=" "integrity": "sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ="
}, },
"deep-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
},
"deep-extend": { "deep-extend": {
"version": "0.6.0", "version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
@ -4063,6 +4068,16 @@
"integrity": "sha1-07DYWTgUBE4JLs4hCPw6ya6kuQA=", "integrity": "sha1-07DYWTgUBE4JLs4hCPw6ya6kuQA=",
"dev": true "dev": true
}, },
"electron-window-state": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-4.1.1.tgz",
"integrity": "sha1-azT9wxs4UU3+yLfI97XUrdtnYy0=",
"requires": {
"deep-equal": "1.0.1",
"jsonfile": "2.4.0",
"mkdirp": "0.5.1"
}
},
"elegant-spinner": { "elegant-spinner": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/elegant-spinner/-/elegant-spinner-1.0.1.tgz", "resolved": "https://registry.npmjs.org/elegant-spinner/-/elegant-spinner-1.0.1.tgz",
@ -6133,8 +6148,7 @@
"graceful-fs": { "graceful-fs": {
"version": "4.1.11", "version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
"dev": true
}, },
"grouped-queue": { "grouped-queue": {
"version": "0.3.3", "version": "0.3.3",
@ -7432,7 +7446,6 @@
"version": "2.4.0", "version": "2.4.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true,
"requires": { "requires": {
"graceful-fs": "4.1.11" "graceful-fs": "4.1.11"
} }

View file

@ -40,6 +40,7 @@
"@atlaskit/theme": "3.2.2", "@atlaskit/theme": "3.2.2",
"electron-debug": "2.0.0", "electron-debug": "2.0.0",
"electron-is-dev": "0.3.0", "electron-is-dev": "0.3.0",
"electron-window-state": "4.1.1",
"history": "4.7.2", "history": "4.7.2",
"jitsi-meet-electron-utils": "github:jitsi/jitsi-meet-electron-utils#1972c3bf0884ace68eb496894dabae593d6dbf49", "jitsi-meet-electron-utils": "github:jitsi/jitsi-meet-electron-utils#1972c3bf0884ace68eb496894dabae593d6dbf49",
"react": "16.3.2", "react": "16.3.2",