From 81a8bbd8ad6aa1757b7cf7eaad62ff5953a321fd Mon Sep 17 00:00:00 2001 From: Vladimir Y Date: Mon, 24 Sep 2018 18:48:56 +0300 Subject: [PATCH] improve restoring "maximized" window state logic --- .../api/endpoints-builders/general.ts | 16 +++++++++++----- src/electron-main/window.ts | 11 +---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/electron-main/api/endpoints-builders/general.ts b/src/electron-main/api/endpoints-builders/general.ts index 44ddb0cbd..fdfa5ac41 100644 --- a/src/electron-main/api/endpoints-builders/general.ts +++ b/src/electron-main/api/endpoints-builders/general.ts @@ -50,20 +50,26 @@ export async function buildEndpoints(ctx: Context): Promise { + activateBrowserWindow: () => from((async () => { + const {window} = await ctx.configStore.readExisting(); const browserWindow = ctx.uiContext && ctx.uiContext.browserWindow; if (!browserWindow) { - return EMPTY; + return EMPTY.toPromise(); + } + + if (window.maximized) { + browserWindow.maximize(); + } else { + browserWindow.show(); } - browserWindow.show(); browserWindow.focus(); NOTIFICATION_SUBJECT.next(IPC_MAIN_API_NOTIFICATION_ACTIONS.ActivateBrowserWindow()); - return of(null); - }, + return null; + })()), toggleBrowserWindow: ({forcedState}) => from((async () => { const browserWindow = ctx.uiContext && ctx.uiContext.browserWindow; diff --git a/src/electron-main/window.ts b/src/electron-main/window.ts index 5aded3881..1f04215bc 100644 --- a/src/electron-main/window.ts +++ b/src/electron-main/window.ts @@ -78,8 +78,7 @@ export async function initBrowserWindow(ctx: Context, endpoints: Endpoints): Pro } async function keepState(ctx: Context, browserWindow: Electron.BrowserWindow) { - const {window, startMinimized} = await ctx.configStore.readExisting(); - const {maximized, bounds} = window; + const {bounds} = (await ctx.configStore.readExisting()).window; const debounce = 500; let timeoutId: any; @@ -87,14 +86,6 @@ async function keepState(ctx: Context, browserWindow: Electron.BrowserWindow) { browserWindow.center(); } - if (maximized) { - browserWindow.maximize(); - - if (startMinimized) { - browserWindow.hide(); - } - } - browserWindow.on("close", saveWindowStateHandler); browserWindow.on("resize", saveWindowStateHandlerDebounced); browserWindow.on("move", saveWindowStateHandlerDebounced);