diff --git a/src/SupApp/index.ts b/src/SupApp/index.ts index 9bf0d58..ea670b5 100644 --- a/src/SupApp/index.ts +++ b/src/SupApp/index.ts @@ -81,6 +81,9 @@ namespace SupApp { export function onMessage(messageType: string, callback: Function) { electron.ipcRenderer.addListener(`sup-app-message-${messageType}`, (event, ...args) => { callback(...args); }); } + export function sendMessage(windowId: number, message: string) { + electron.ipcRenderer.send("send-message", windowId, message); + } export function getCurrentWindow() { return currentWindow; } export function showMainWindow() { electron.ipcRenderer.send("show-main-window"); } diff --git a/src/ipc.ts b/src/ipc.ts index 095568e..bbc9b10 100644 --- a/src/ipc.ts +++ b/src/ipc.ts @@ -30,6 +30,7 @@ electron.ipcMain.on("choose-folder", onChooseFolder); electron.ipcMain.on("choose-file", onChooseFile); electron.ipcMain.on("authorize-folder", onAuthorizeFolder); electron.ipcMain.on("check-path-authorization", onCheckPathAuthorization); +electron.ipcMain.on("send-message", onSendMessage); const secretKeys = new Map(); @@ -96,3 +97,10 @@ function onCheckPathAuthorization(event: Electron.IpcMainEvent, secretKey: strin const authorization = canReadWrite ? "readWrite" : (canExecute ? "execute" : null); event.sender.send("check-path-authorization-callback", ipcId, normalizedPath, authorization); } + +function onSendMessage(event: Electron.IpcMainEvent, windowId: number, message: string, args: any[] = []) { + const window = electron.BrowserWindow.fromId(windowId); + if (window == null) return; + + window.webContents.send(`sup-app-message-${message}`, ...args); +}