fix: wait for renderer ready before sending tab data
- Wait for did-finish-load event in transfer-tab-data handler - Await transferTabData before closing file in handlePopOut - Remove arbitrary 500ms timeout, now uses proper IPC ack flow
This commit is contained in:
@@ -497,7 +497,18 @@ ipcMain.handle('transfer-tab-data', async (_event, windowId: number, tabData: an
|
|||||||
if (!win) {
|
if (!win) {
|
||||||
return { success: false, error: 'Window not found' };
|
return { success: false, error: 'Window not found' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
if (win.webContents.isLoading()) {
|
||||||
|
win.webContents.once('did-finish-load', () => resolve());
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
setTimeout(resolve, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
win.webContents.send('tab-data-received', tabData);
|
win.webContents.send('tab-data-received', tabData);
|
||||||
|
log.info('[PopOut] Tab data sent to window:', windowId);
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
log.error('[PopOut] Failed to transfer tab data:', error);
|
log.error('[PopOut] Failed to transfer tab data:', error);
|
||||||
|
|||||||
@@ -135,9 +135,7 @@ export const NoteBrowser = () => {
|
|||||||
const result = await window.electronAPI?.createWindow({ route, title: file.name })
|
const result = await window.electronAPI?.createWindow({ route, title: file.name })
|
||||||
|
|
||||||
if (result?.success && result.windowId) {
|
if (result?.success && result.windowId) {
|
||||||
setTimeout(() => {
|
await window.electronAPI?.transferTabData(result.windowId!, tabData)
|
||||||
window.electronAPI?.transferTabData(result.windowId!, tabData)
|
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeFile(file)
|
closeFile(file)
|
||||||
|
|||||||
Reference in New Issue
Block a user