Electron-350 (Store/Restore maximized and fullscreen application state on launch) (#377)

- Update the app to its previous state when the app is launched
- swap checks
This commit is contained in:
Kiran Niranjan 2018-05-22 14:29:28 +05:30 committed by Vishwas Shashidhar
parent ed04aacd73
commit dde5c7097a

View File

@ -160,7 +160,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
// if bounds if not fully contained in some display then use default size
// and position.
if (!isInDisplayBounds(bounds)) {
if (!isInDisplayBounds(bounds) || initialBounds.isMaximized || initialBounds.isFullScreen) {
bounds = null;
}
@ -189,10 +189,22 @@ function doCreateMainWindow(initialUrl, initialBounds) {
mainWindow = new BrowserWindow(newWinOpts);
mainWindow.winName = 'main';
let throttledMainWinBoundsChange = throttle(5000, saveMainWinBounds);
let throttledMainWinBoundsChange = throttle(1000, saveMainWinBounds);
mainWindow.on('move', throttledMainWinBoundsChange);
mainWindow.on('resize', throttledMainWinBoundsChange);
if (initialBounds && !isNodeEnv) {
// maximizes the application if previously maximized
if (initialBounds.isMaximized) {
mainWindow.maximize();
}
// Sets the application to full-screen if previously set to full-screen
if (isMac && initialBounds.isFullScreen) {
mainWindow.setFullScreen(true);
}
}
function retry() {
if (!isOnline) {
loadErrors.showNetworkConnectivityError(mainWindow, url, retry);
@ -611,6 +623,12 @@ app.on('before-quit', function () {
function saveMainWinBounds() {
let newBounds = getWindowSizeAndPosition(mainWindow);
// set application full-screen and maximized state
if (mainWindow && !mainWindow.isDestroyed()) {
newBounds.isMaximized = mainWindow.isMaximized();
newBounds.isFullScreen = mainWindow.isFullScreen();
}
if (newBounds) {
updateConfigField('mainWinPos', newBounds);
}