fix window coming to the front on reload

This commit is contained in:
violetadev 2024-09-09 01:24:54 +02:00
parent 0539673a33
commit 1315e8c853

View file

@ -11,6 +11,7 @@
import path from 'path';
import { app, BrowserWindow, shell, screen, ipcMain } from 'electron';
import { setupTitlebar } from 'custom-electron-titlebar/main';
import { useState } from 'react';
import cli from './cli';
import { PROTOCOL } from '../common/constants';
import MenuBuilder from './menu';
@ -102,8 +103,13 @@ if (customTitlebarStatus && process.platform === 'win32') {
const createWindow = async () => {
windowShownOnOpen = false;
let isAppInitiated = false;
await installExtensions();
const setIsAppInitiated = () => {
isAppInitiated = true;
};
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
@ -202,20 +208,24 @@ const createWindow = async () => {
});
mainWindow.on('ready-to-show', async () => {
await initInstance();
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
webPermissionHandlers.init();
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.showInactive();
if (!windowShownOnOpen) {
windowShownOnOpen = true;
mainWindow.show();
if (!isAppInitiated) {
await initInstance();
setIsAppInitiated();
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
webPermissionHandlers.init();
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.showInactive();
if (!windowShownOnOpen) {
windowShownOnOpen = true;
mainWindow.show();
} else {
mainWindow.showInactive();
}
}
}
});