[MM 19649] Fix blank window when auto-starting the app on login (#1106)
* Windows: fix hidden/shown/maximized window on start * allow for some overlap with the top/left edge of the screen before resetting * support maximizing directly from app tray icon after initial startup * inline comments * alternative to prevent minimize effect on startup * default hideOnStartup to false * update comment
This commit is contained in:
parent
395cbf9c9e
commit
d23c8cf48a
|
@ -544,6 +544,7 @@ function initializeAfterAppReady() {
|
|||
|
||||
mainWindow = createMainWindow(config.data, {
|
||||
hideOnStartup,
|
||||
trayIconShown: process.platform === 'win32' || config.showTrayIcon,
|
||||
linuxAppIcon: path.join(assetsDir, 'appicon.png'),
|
||||
deeplinkingUrl,
|
||||
});
|
||||
|
|
|
@ -8,6 +8,8 @@ const defaultOptions = {
|
|||
stripUnknown: true,
|
||||
};
|
||||
|
||||
const defaultMinWindowXPos = -100;
|
||||
const defaultMinWindowYPos = -100;
|
||||
const defaultWindowWidth = 1000;
|
||||
const defaultWindowHeight = 700;
|
||||
const minWindowWidth = 400;
|
||||
|
@ -23,8 +25,8 @@ const argsSchema = Joi.object({
|
|||
});
|
||||
|
||||
const boundsInfoSchema = Joi.object({
|
||||
x: Joi.number().integer().min(0),
|
||||
y: Joi.number().integer().min(0),
|
||||
x: Joi.number().integer().min(defaultMinWindowXPos).default(0),
|
||||
y: Joi.number().integer().min(defaultMinWindowYPos).default(0),
|
||||
width: Joi.number().integer().min(minWindowWidth).required().default(defaultWindowWidth),
|
||||
height: Joi.number().integer().min(minWindowHeight).required().default(defaultWindowHeight),
|
||||
maximized: Joi.boolean().default(false),
|
||||
|
|
|
@ -39,13 +39,16 @@ function createMainWindow(config, options) {
|
|||
windowOptions = {width: defaultWindowWidth, height: defaultWindowHeight};
|
||||
}
|
||||
|
||||
const {hideOnStartup, trayIconShown} = options;
|
||||
const {maximized: windowIsMaximized} = windowOptions;
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
windowOptions.icon = options.linuxAppIcon;
|
||||
}
|
||||
Object.assign(windowOptions, {
|
||||
title: app.getName(),
|
||||
fullscreenable: true,
|
||||
show: false,
|
||||
show: hideOnStartup || false,
|
||||
minWidth: minimumWindowWidth,
|
||||
minHeight: minimumWindowHeight,
|
||||
fullscreen: false,
|
||||
|
@ -63,34 +66,49 @@ function createMainWindow(config, options) {
|
|||
const indexURL = global.isDev ? 'http://localhost:8080/browser/index.html' : `file://${app.getAppPath()}/browser/index.html`;
|
||||
mainWindow.loadURL(indexURL);
|
||||
|
||||
// This section should be called after loadURL() #570
|
||||
if (options.hideOnStartup) {
|
||||
if (windowOptions.maximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
|
||||
// on MacOS, the window is already hidden until 'ready-to-show'
|
||||
if (process.platform !== 'darwin') {
|
||||
// handle hiding the app when launched by auto-start
|
||||
if (hideOnStartup) {
|
||||
if (trayIconShown && process.platform !== 'darwin') {
|
||||
mainWindow.hide();
|
||||
} else {
|
||||
mainWindow.minimize();
|
||||
}
|
||||
} else if (windowOptions.maximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow.webContents.setZoomLevel(0);
|
||||
|
||||
// handle showing the window when not launched by auto-start
|
||||
// - when not configured to auto-start, immediately show contents and optionally maximize as needed
|
||||
if (!hideOnStartup) {
|
||||
mainWindow.show();
|
||||
if (windowIsMaximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.once('show', () => {
|
||||
// handle showing the app when hidden to the tray icon by auto-start
|
||||
// - optionally maximize the window as needed
|
||||
if (hideOnStartup && windowIsMaximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.once('restore', () => {
|
||||
// handle restoring the window when minimized to the app icon by auto-start
|
||||
// - optionally maximize the window as needed
|
||||
if (hideOnStartup && windowIsMaximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('will-attach-webview', (event, webPreferences) => {
|
||||
webPreferences.nodeIntegration = false;
|
||||
webPreferences.contextIsolation = true;
|
||||
});
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow.webContents.setZoomLevel(0);
|
||||
if (process.platform !== 'darwin') {
|
||||
mainWindow.show();
|
||||
} else if (options.hideOnStartup !== true) {
|
||||
mainWindow.show();
|
||||
}
|
||||
});
|
||||
|
||||
// App should save bounds when a window is closed.
|
||||
// However, 'close' is not fired in some situations(shutdown, ctrl+c)
|
||||
// because main process is killed in such situations.
|
||||
|
|
Loading…
Reference in a new issue