smoother way to show main window after splash

This commit is contained in:
Zamitto 2024-05-20 17:41:57 -03:00
parent 5667c813d9
commit a817a26be1
4 changed files with 14 additions and 7 deletions

View file

@ -42,7 +42,7 @@ const mockValuesForDebug = async () => {
bytesPerSecond: 4568,
},
});
await sleep(1000);
await sleep(800);
}
sendEvent({ type: "update-downloaded" });

View file

@ -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);

View file

@ -10,8 +10,7 @@ const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
autoUpdater.quitAndInstall(true, true);
} else {
autoUpdater.removeAllListeners();
WindowManager.splashWindow?.close();
WindowManager.createMainWindow();
WindowManager.prepareMainWindowAndCloseSplash();
}
};

View file

@ -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);