Skip to content

Instantly share code, notes, and snippets.

@dfahlander
Created February 27, 2023 00:02
Show Gist options
  • Save dfahlander/71d04fc3995d11bafa41236563dce229 to your computer and use it in GitHub Desktop.
Save dfahlander/71d04fc3995d11bafa41236563dce229 to your computer and use it in GitHub Desktop.
Electron 23 liveQuery workaround
// This module shall be imported from the main node module in electron.
// The BrowserWindows shall instead import 'workaround-renderer.ts'
// NOTE: This gist shall NOT be used in Electron versions where https://github.com/electron/electron/issues/37417 is resolved
import { ipcMain } from "electron";
import { BrowserWindow } from "electron";
if (typeof BroadcastChannel !== "undefined") {
// We're on electron version 23 with BroadcastChannel support in node
ipcMain.on("dexie-storagemutated", (event, json) => {
BrowserWindow.getAllWindows().forEach((window) => {
if (window.webContents.id !== event.sender.id) {
try {
window.webContents.send("dexie-storagemutated", json);
} catch {}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment