fix(electron): create window when app is already ready

This commit is contained in:
4gray committed 2026-06-28 19:50:09 +02:00
1 parent 916e7608f3
commit 1a302a9c33
2 files changed
+23 -1

No files matched your search

+18
View File
@@ -4,6 +4,8 @@ jest.mock('electron', () => ({
app: {
getPath: jest.fn(() => '/tmp'),
isPackaged: false,
isReady: jest.fn(() => false),
on: jest.fn(),
},
BrowserWindow: jest.fn(),
Menu: {
@@ -230,6 +232,22 @@ describe('Electron app security helpers', () => {
);
});
it('creates the main window immediately when Electron is already ready', () => {
const mainWindow = createMockMainWindow();
(BrowserWindow as unknown as jest.Mock).mockReturnValue(mainWindow);
(electronApp.isReady as jest.Mock).mockReturnValue(true);
App.main(electronApp, BrowserWindow);
expect(BrowserWindow).toHaveBeenCalled();
expect(electronApp.on).not.toHaveBeenCalledWith(
'ready',
expect.any(Function)
);
expect(mainWindow.loadURL).not.toHaveBeenCalled();
expect(mainWindow.loadFile).not.toHaveBeenCalled();
});
it('clears only service worker registrations and cache storage', async () => {
await clearElectronServiceWorkerStorage();
+5 -1
View File
@@ -476,7 +476,11 @@ export default class App {
App.application = app;
App.application.on('window-all-closed', App.onWindowAllClosed); // Quit when all windows are closed.
App.application.on('ready', App.onReady); // App is ready to load data
if (App.application.isReady()) {
App.onReady();
} else {
App.application.on('ready', App.onReady); // App is ready to load data
}
App.application.on('activate', App.onActivate); // App is activated
App.application.on('before-quit', () => {
if (App.mainWindow)