Skip to content

Commit

Permalink
fix: add the try catch block on UPDATE_SHARED_STATE to catch the erro…
Browse files Browse the repository at this point in the history
…r when a page has been destroyed before electron can share the updated data with it
  • Loading branch information
therockerline committed Jan 29, 2025
1 parent e4951a9 commit 0fe51c6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/lib/ipcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ export function registerIpcEvents() {
const windows = BrowserWindow.getAllWindows();
store.updateStore(newState, `${page}[${selector}]`)
windows.forEach(win => {
if (page !== win.webContents.getTitle()) {
win.webContents.send(IPC_EVENTS.SHARED_STATE_UPDATED, newState, page);
const targetPage = win.webContents.getTitle()
try {
if (page !== targetPage) {
win.webContents.send(IPC_EVENTS.SHARED_STATE_UPDATED, newState, page);
}
} catch (e) {
Log.error(`Data origin: ${page}, target: ${targetPage}`, e)
}
});
});
Expand Down

0 comments on commit 0fe51c6

Please sign in to comment.