From a817a26be1de8204af5b444e86cde46f595c669c Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 20 May 2024 17:41:57 -0300 Subject: [PATCH] smoother way to show main window after splash --- src/main/events/autoupdater/check-for-updates.ts | 2 +- .../events/autoupdater/continue-to-main-window.ts | 3 +-- .../autoupdater/restart-and-install-update.ts | 3 +-- src/main/services/window-manager.ts | 13 +++++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/events/autoupdater/check-for-updates.ts b/src/main/events/autoupdater/check-for-updates.ts index 22437eec..3ac23d92 100644 --- a/src/main/events/autoupdater/check-for-updates.ts +++ b/src/main/events/autoupdater/check-for-updates.ts @@ -42,7 +42,7 @@ const mockValuesForDebug = async () => { bytesPerSecond: 4568, }, }); - await sleep(1000); + await sleep(800); } sendEvent({ type: "update-downloaded" }); diff --git a/src/main/events/autoupdater/continue-to-main-window.ts b/src/main/events/autoupdater/continue-to-main-window.ts index 4c3c15e8..6a8965f9 100644 --- a/src/main/events/autoupdater/continue-to-main-window.ts +++ b/src/main/events/autoupdater/continue-to-main-window.ts @@ -6,8 +6,7 @@ const { autoUpdater } = updater; const continueToMainWindow = async (_event: Electron.IpcMainInvokeEvent) => { autoUpdater.removeAllListeners(); - WindowManager.splashWindow?.close(); - WindowManager.createMainWindow(); + WindowManager.prepareMainWindowAndCloseSplash(); }; registerEvent("continueToMainWindow", continueToMainWindow); diff --git a/src/main/events/autoupdater/restart-and-install-update.ts b/src/main/events/autoupdater/restart-and-install-update.ts index b99a1a36..be301c18 100644 --- a/src/main/events/autoupdater/restart-and-install-update.ts +++ b/src/main/events/autoupdater/restart-and-install-update.ts @@ -10,8 +10,7 @@ const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => { autoUpdater.quitAndInstall(true, true); } else { autoUpdater.removeAllListeners(); - WindowManager.splashWindow?.close(); - WindowManager.createMainWindow(); + WindowManager.prepareMainWindowAndCloseSplash(); } }; diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 261abcc8..e435ddb2 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -18,6 +18,7 @@ import { IsNull, Not } from "typeorm"; export class WindowManager { public static mainWindow: Electron.BrowserWindow | null = null; public static splashWindow: Electron.BrowserWindow | null = null; + public static isReadyToShowMainWindow = false; private static loadURL(hash = "") { // HMR for renderer base on electron-vite cli. @@ -60,7 +61,8 @@ export class WindowManager { width: 380, height: 380, frame: false, - alwaysOnTop: false, + resizable: false, + backgroundColor: "#1c1c1c", webPreferences: { preload: path.join(__dirname, "../preload/index.mjs"), sandbox: false, @@ -72,13 +74,14 @@ export class WindowManager { } public static createMainWindow() { - if (this.mainWindow) return; + if (this.mainWindow || !this.isReadyToShowMainWindow) return; this.mainWindow = new BrowserWindow({ width: 1200, height: 720, minWidth: 1024, minHeight: 540, + backgroundColor: "#1c1c1c", titleBarStyle: "hidden", ...(process.platform === "linux" ? { icon } : {}), trafficLightPosition: { x: 16, y: 16 }, @@ -112,6 +115,12 @@ export class WindowManager { }); } + public static prepareMainWindowAndCloseSplash() { + this.isReadyToShowMainWindow = true; + this.splashWindow?.close(); + this.createMainWindow(); + } + public static redirect(hash: string) { if (!this.mainWindow) this.createMainWindow(); this.loadURL(hash);