2025-05-25 22:40:12 +08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
const __SCOPE = "main";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {import("electron")} electron
|
|
|
|
|
*/
|
2025-04-18 19:20:46 +08:00
|
|
|
const buildIpcMain = (electron) => {
|
2025-05-25 22:40:12 +08:00
|
|
|
const { app } = electron;
|
|
|
|
|
/**
|
|
|
|
|
* @type {import("../../types/main/electron").AuraIPCMain}
|
|
|
|
|
*/
|
2025-06-05 00:35:50 +08:00
|
|
|
// @ts-expect-error
|
2025-05-25 22:40:12 +08:00
|
|
|
const ipcMain = electron.ipcMain;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} windowKey
|
|
|
|
|
* @param {string} channel
|
|
|
|
|
* @param {any} data
|
|
|
|
|
* @param {import("electron").WebContents?} grep
|
|
|
|
|
*/
|
|
|
|
|
ipcMain.send = (windowKey, channel, data, grep = null) => {
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} key
|
|
|
|
|
* @param {string} chan
|
|
|
|
|
* @param {any} targetData
|
|
|
|
|
*/
|
2025-06-05 00:35:50 +08:00
|
|
|
if (!global.__HUGO_AURA__.hookedWindows) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-25 22:40:12 +08:00
|
|
|
const sendDataToWebContents = (key, chan, targetData) => {
|
|
|
|
|
const webContents =
|
2025-06-05 00:35:50 +08:00
|
|
|
// @ts-expect-error
|
|
|
|
|
global.__HUGO_AURA__.hookedWindows.get(key)?.webContents;
|
|
|
|
|
|
|
|
|
|
if (!webContents) {
|
|
|
|
|
console.error(
|
|
|
|
|
`[HugoAura / Main / IPC / ERROR] Failed sending data to ${key}: WebContents not found`
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (grep !== webContents) {
|
|
|
|
|
webContents.send(chan, targetData);
|
|
|
|
|
}
|
2025-05-25 22:40:12 +08:00
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
};
|
2025-05-25 22:40:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (windowKey === "*") {
|
|
|
|
|
for (const perWindow of global.__HUGO_AURA__.hookedWindows.keys()) {
|
|
|
|
|
sendDataToWebContents(perWindow, channel, data);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const isWindowValid = global.__HUGO_AURA__.hookedWindows.has(windowKey);
|
|
|
|
|
if (!isWindowValid) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`[HugoAura / Main / IPC / ERROR] Unknown windowKey: ${windowKey}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendDataToWebContents(windowKey, channel, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
const { applyConfigIpcHandler } = require("./ipcModules/configIpcHandler");
|
2025-05-25 22:40:12 +08:00
|
|
|
const { applyPlsIpcHandler } = require("./ipcModules/plsIpcHandler");
|
2025-04-18 19:20:46 +08:00
|
|
|
|
|
|
|
|
ipcMain.handle("$aura.base.restartApplication", async () => {
|
|
|
|
|
app.relaunch();
|
|
|
|
|
app.exit(0);
|
|
|
|
|
});
|
2025-05-25 22:40:12 +08:00
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
applyConfigIpcHandler(ipcMain);
|
2025-05-25 22:40:12 +08:00
|
|
|
applyPlsIpcHandler(ipcMain);
|
2025-04-18 19:20:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = { buildIpcMain };
|