Skip to content

Commit

Permalink
smoother way to show main window after splash
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto committed May 20, 2024
1 parent 45a82aa commit cbc026c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/main/events/autoupdater/continue-to-main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 1 addition & 2 deletions src/main/events/autoupdater/restart-and-install-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
autoUpdater.quitAndInstall(true, true);
} else {
autoUpdater.removeAllListeners();
WindowManager.splashWindow?.close();
WindowManager.createMainWindow();
WindowManager.prepareMainWindowAndCloseSplash();
}
};

Expand Down
11 changes: 10 additions & 1 deletion src/main/services/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -72,7 +73,7 @@ export class WindowManager {
}

public static createMainWindow() {
if (this.mainWindow) return;
if (this.mainWindow || !this.isReadyToShowMainWindow) return;

this.mainWindow = new BrowserWindow({
width: 1200,
Expand All @@ -91,13 +92,15 @@ export class WindowManager {
preload: path.join(__dirname, "../preload/index.mjs"),
sandbox: false,
},
show: false,
});

this.loadURL();
this.mainWindow.removeMenu();

this.mainWindow.on("ready-to-show", () => {
if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools();
WindowManager.mainWindow?.show();
});

this.mainWindow.on("close", async () => {
Expand All @@ -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);
Expand Down

0 comments on commit cbc026c

Please sign in to comment.