From 4435bdfebca490140ee7e0eb11a891348ea26a4d Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Thu, 22 Apr 2021 09:31:06 +0300 Subject: [PATCH] UI content shown with delay after opening the app from the system tray [fix] (macOS) Clicking the icon in Launchpad or system dock does not open the app main window after system boot https://privatus.atlassian.net/browse/WC-1182 https://privatus.atlassian.net/browse/WC-1183 --- src/background.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/background.js b/src/background.js index 2395262..6a21128 100644 --- a/src/background.js +++ b/src/background.js @@ -274,17 +274,15 @@ if (gotTheLock) { if (store.state.settings.minimizeToTray && WasOpenedAtLogin()) { // do not show main application window when application was started automatically on login // (if enabled minimizeToTray) + const doNotShowWhenReady = true; + createWindow(doNotShowWhenReady); } else { createWindow(); } }); app.on("activate", () => { - // On macOS it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (win === null) { - createWindow(); - } + menuOnShow(); }); // Quit when all windows are closed. @@ -518,7 +516,7 @@ function createBrowserWindow(config) { } // CREATE WINDOW -function createWindow() { +function createWindow(doNotShowWhenReady) { // Create the browser window. let windowConfig = { @@ -575,12 +573,13 @@ function createWindow() { win.loadURL("app://./index.html"); } - // show\hide app from system dock - updateAppDockVisibility(); - - win.once("ready-to-show", () => { - win.show(); - }); + if (doNotShowWhenReady != true) { + win.once("ready-to-show", () => { + win.show(); + // show\hide app from system dock + updateAppDockVisibility(); + }); + } win.on("close", async event => { // save last window position in order to be able to restore it @@ -591,8 +590,14 @@ function createWindow() { isTrayInitialized == true && store.state.settings.minimizeToTray == true ) { + // Prevent closing the window to be able to show it back immediately. + // Just hide it. + win.hide(); + event.preventDefault(); + return; + // 'window-all-closed' event will be raised - return; // close window + //return; // close window } event.preventDefault();