fix: huddles not launching reliably

Closes #160
Race condition preventing proper initialization.
This commit is contained in:
talksik
2026-04-14 07:58:45 -07:00
parent 91a973b7fb
commit fe2a003e94
4 changed files with 29 additions and 34 deletions
+20 -20
View File
@@ -162,10 +162,7 @@ const createAutoplayWindow = () => {
};
const createHuddleWindow = () => {
if (huddleWindow) {
huddleWindow.focus();
return;
}
if (huddleWindow) return;
huddleWindow = new BrowserWindow({
width: 1024,
@@ -180,19 +177,28 @@ const createHuddleWindow = () => {
});
hardenWindow(huddleWindow);
if (HUDDLE_WINDOW_VITE_DEV_SERVER_URL) {
huddleWindow.loadURL(HUDDLE_WINDOW_VITE_DEV_SERVER_URL);
} else {
huddleWindow.loadFile(
path.join(__dirname, `../renderer/${HUDDLE_WINDOW_VITE_NAME}/index.html`),
);
}
huddleWindow.on('closed', () => {
huddleWindow = null;
});
};
// Connection data is passed via URL hash so it's available synchronously on
// renderer mount — avoids the IPC race where `huddle:connect` could be sent
// before React attached its listener.
const loadHuddleWindow = (data: { token: string; serverUrl: string }) => {
if (!huddleWindow) return;
const params = new URLSearchParams({ token: data.token, serverUrl: data.serverUrl });
const hash = params.toString();
if (HUDDLE_WINDOW_VITE_DEV_SERVER_URL) {
huddleWindow.loadURL(`${HUDDLE_WINDOW_VITE_DEV_SERVER_URL}#${hash}`);
} else {
huddleWindow.loadFile(
path.join(__dirname, `../renderer/${HUDDLE_WINDOW_VITE_NAME}/index.html`),
{ hash },
);
}
};
function positionAutoplayWindow() {
if (!autoplayWindow) return;
const { width } = screen.getPrimaryDisplay().workAreaSize;
@@ -261,14 +267,8 @@ ipcMain.on('window:fullscreen', (event) => {
// Secondary window IPC handlers
ipcMain.on('window:open-huddle', (_event, data: { token: string; serverUrl: string }) => {
createHuddleWindow();
// Send connection data once the huddle window is ready
huddleWindow?.webContents.once('did-finish-load', () => {
huddleWindow?.webContents.send('huddle:connect', data);
});
// If already loaded, send immediately
if (!huddleWindow?.webContents.isLoading()) {
huddleWindow?.webContents.send('huddle:connect', data);
}
loadHuddleWindow(data);
huddleWindow?.focus();
});
ipcMain.on('window:close-huddle', () => {
huddleWindow?.close();