fix: resolve did-finish-load race condition, remove unused import
- Move did-finish-load listener before loadFile() to prevent missing the event - Remove unused nativeImage import
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const { app, BrowserWindow, dialog, ipcMain, Menu, nativeImage } = require('electron');
|
const { app, BrowserWindow, dialog, ipcMain, Menu } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -23,6 +23,14 @@ function createWindow() {
|
|||||||
show: false
|
show: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Register did-finish-load BEFORE loadFile to avoid race condition
|
||||||
|
mainWindow.webContents.on('did-finish-load', () => {
|
||||||
|
if (pendingFilePath) {
|
||||||
|
openFile(pendingFilePath);
|
||||||
|
pendingFilePath = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Load the index.html
|
// Load the index.html
|
||||||
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
||||||
|
|
||||||
@@ -261,16 +269,7 @@ app.whenReady().then(() => {
|
|||||||
if (fileToOpen) {
|
if (fileToOpen) {
|
||||||
pendingFilePath = fileToOpen;
|
pendingFilePath = fileToOpen;
|
||||||
}
|
}
|
||||||
|
// pendingFilePath will be opened by the did-finish-load handler in createWindow()
|
||||||
// Open pending file once window is fully ready
|
|
||||||
if (pendingFilePath) {
|
|
||||||
mainWindow.webContents.on('did-finish-load', () => {
|
|
||||||
if (pendingFilePath) {
|
|
||||||
openFile(pendingFilePath);
|
|
||||||
pendingFilePath = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user