an easy fix to ensure electron only loads the page after the vite dev server is ready (avoids that white blank page at first)
// main.js
function waitForViteServer(url, cb) {
const tryConnect = () => {
http.get(url, () => cb()).on('error', () => setTimeout(tryConnect, 300));
};
tryConnect();
}
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
if (isDevEnvironment) {
waitForViteServer('http://localhost:5173', () => {
mainWindow.loadURL('http://localhost:5173/');
log('Electron running in dev mode');
});
} else {
mainWindow.loadFile(path.join(__dirname, 'build', 'index.html'));
log('Electron running in prod mode');
}
};
Mira
need #pins ?
welp
15 votes. we subject to the majority rule (fondly remembered this from a civic class)
15 votes. we subject to the majority rule (fondly remembered this from a civic class)