Fix black screen: wait for Vite before Electron, retry loadURL, show boot fallback.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+29
-1
@@ -69,9 +69,37 @@ function createWindow(): void {
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow?.show();
|
||||
mainWindow?.focus();
|
||||
});
|
||||
mainWindow.show();
|
||||
|
||||
const devUrl = process.env.VITE_DEV_SERVER_URL;
|
||||
if (devUrl) {
|
||||
void mainWindow.loadURL(devUrl);
|
||||
mainWindow.webContents.openDevTools({ mode: 'detach' });
|
||||
mainWindow.webContents.on('did-fail-load', (_e, code, desc, url) => {
|
||||
console.error('did-fail-load', code, desc, url);
|
||||
});
|
||||
mainWindow.webContents.on('console-message', (_e, level, message) => {
|
||||
console.log(`[renderer:${level}]`, message);
|
||||
});
|
||||
const load = async (attempt = 0) => {
|
||||
try {
|
||||
await mainWindow!.loadURL(devUrl);
|
||||
console.log('Loaded', devUrl);
|
||||
} catch (err) {
|
||||
console.error('loadURL attempt', attempt, err);
|
||||
if (attempt < 20) {
|
||||
setTimeout(() => void load(attempt + 1), 300);
|
||||
return;
|
||||
}
|
||||
await mainWindow!.loadURL(
|
||||
`data:text/html,<h1 style="color:#fff;font-family:sans-serif;padding:24px">Dev server not reachable: ${devUrl}</h1>`,
|
||||
);
|
||||
}
|
||||
};
|
||||
void load();
|
||||
} else {
|
||||
void mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user