mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-22 16:24:27 +08:00
[Feat] Early support for PLS & Use JSDoc (Partially)
This commit is contained in:
56
src/aura/init/main/ipcHandler.js
Normal file → Executable file
56
src/aura/init/main/ipcHandler.js
Normal file → Executable file
@@ -1,10 +1,64 @@
|
||||
// @ts-check
|
||||
|
||||
const __SCOPE = "main";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("electron")} electron
|
||||
*/
|
||||
const buildIpcMain = (electron) => {
|
||||
const { app, ipcMain } = electron;
|
||||
const { app } = electron;
|
||||
/**
|
||||
* @type {import("../../types/main/electron").AuraIPCMain}
|
||||
*/
|
||||
// @ts-ignore
|
||||
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
|
||||
*/
|
||||
const sendDataToWebContents = (key, chan, targetData) => {
|
||||
const webContents =
|
||||
global.__HUGO_AURA__.hookedWindows.get(key).webContents;
|
||||
|
||||
if (grep !== webContents) webContents.send(chan, targetData);
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
const { applyPlsIpcHandler } = require("./ipcModules/plsIpcHandler");
|
||||
|
||||
ipcMain.handle("$aura.base.restartApplication", async () => {
|
||||
app.relaunch();
|
||||
app.exit(0);
|
||||
});
|
||||
|
||||
applyPlsIpcHandler(ipcMain);
|
||||
};
|
||||
|
||||
module.exports = { buildIpcMain };
|
||||
|
||||
190
src/aura/init/main/ipcModules/plsIpcHandler.js
Executable file
190
src/aura/init/main/ipcModules/plsIpcHandler.js
Executable file
@@ -0,0 +1,190 @@
|
||||
// @ts-check
|
||||
|
||||
const __SCOPE = "main";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../../../types/main/electron").AuraIPCMain} ipcMain
|
||||
*/
|
||||
const applyPlsIpcHandler = (ipcMain) => {
|
||||
const methodBase = "$aura.pls";
|
||||
|
||||
const isPlsDetached = process.argv.includes("--pls-detach");
|
||||
|
||||
global.__HUGO_AURA__.plsStats = {
|
||||
installed: false,
|
||||
launched: false,
|
||||
detached: isPlsDetached,
|
||||
connected: false,
|
||||
version: "未知",
|
||||
status: "dead",
|
||||
authToken: global.__HUGO_AURA_CONFIG__.plsToken,
|
||||
};
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.getPlsFolderExists`,
|
||||
/**
|
||||
*
|
||||
* @returns {{ success: boolean; data: { isExists: boolean }; error?: Error }}
|
||||
*/
|
||||
(_event, _arg) => {
|
||||
const plsFolderPath = path.join(__dirname, "../../../proxy");
|
||||
try {
|
||||
const result = fs.existsSync(plsFolderPath);
|
||||
return {
|
||||
success: true,
|
||||
data: { isExists: result },
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
data: { isExists: false },
|
||||
error: e,
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.getPlsStats`,
|
||||
/**
|
||||
*
|
||||
* @returns {{ success: boolean; data: PLSStatus; }}
|
||||
*/
|
||||
(_event, _arg) => {
|
||||
return {
|
||||
success: true,
|
||||
data: global.__HUGO_AURA__.plsStats,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.updatePlsStats`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainInvokeEvent} _event
|
||||
* @param {PLSStatus} arg
|
||||
* @returns
|
||||
*/
|
||||
(_event, arg) => {
|
||||
global.__HUGO_AURA__.plsStats = arg;
|
||||
ipcMain.send("assistant", `${methodBase}.post.onPlsStatsUpdate`, arg);
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.getPlsSettings`,
|
||||
/**
|
||||
*
|
||||
* @returns {{ success: boolean; data: Record<any, any> }}
|
||||
*/
|
||||
(_event, _arg) => {
|
||||
return {
|
||||
success: true,
|
||||
data: global.__HUGO_AURA__.plsSettings,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.updatePlsSettings`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainInvokeEvent} _event
|
||||
* @param {Record<any, any>} arg
|
||||
* @returns
|
||||
*/
|
||||
(_event, arg) => {
|
||||
global.__HUGO_AURA__.plsSettings = arg;
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.getPlsRules`,
|
||||
/**
|
||||
*
|
||||
* @returns {{ success: boolean; data: Record<any, any> }}
|
||||
*/
|
||||
(_event, _arg) => {
|
||||
return {
|
||||
success: true,
|
||||
data: global.__HUGO_AURA__.plsRules,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.updatePlsRules`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainInvokeEvent} _event
|
||||
* @param {Record<any, any>} arg
|
||||
* @returns
|
||||
*/
|
||||
(_event, arg) => {
|
||||
global.__HUGO_AURA__.plsRules = arg;
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.on(
|
||||
`${methodBase}.ws.broadcastMessageRecv`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainEvent} _event
|
||||
* @param {PLSResponse} arg
|
||||
*/
|
||||
(_event, arg) => {
|
||||
ipcMain.send("assistant", `${methodBase}.ws.post.onNewMsgRecv`, arg);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.ws.sendWsMessage`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainInvokeEvent} _event
|
||||
* @param {ClientPLSRequest} arg
|
||||
*/
|
||||
(_event, arg) => {
|
||||
ipcMain.send(
|
||||
"desktopAssistant",
|
||||
`${methodBase}.ws.post.onReqSendMsg`,
|
||||
arg
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
`${methodBase}.syncPlsConfig`,
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").IpcMainInvokeEvent} event
|
||||
* @param {{ basic: Record<any, any>, rules: Record<any, any> }} arg
|
||||
*/
|
||||
(event, arg) => {
|
||||
global.__HUGO_AURA__.plsRules = arg.rules;
|
||||
global.__HUGO_AURA__.plsSettings = arg.basic;
|
||||
|
||||
ipcMain.send("*", `${methodBase}.syncPlsConfig`, arg, event.sender);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = { applyPlsIpcHandler };
|
||||
0
src/aura/init/preload/webpackHook.js
Normal file → Executable file
0
src/aura/init/preload/webpackHook.js
Normal file → Executable file
32
src/aura/init/rendererHook/hooksManager.js
Normal file → Executable file
32
src/aura/init/rendererHook/hooksManager.js
Normal file → Executable file
@@ -1,13 +1,20 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
class HooksManager {
|
||||
loadHooks() {
|
||||
if (global.__HUGO_AURA__.hooks) {
|
||||
if (
|
||||
global.__HUGO_AURA__.hooks &&
|
||||
Object.keys(global.__HUGO_AURA__.hooks).length !== 0
|
||||
) {
|
||||
return global.__HUGO_AURA__.hooks;
|
||||
}
|
||||
|
||||
const hooksPath = path.join(__dirname, "../../../aura/ui/hooks");
|
||||
const hooksPath = path.join(__dirname, "../../../aura/ui/hookDefinitions");
|
||||
|
||||
/** @type {import("../../types/main/core").HooksMap} */
|
||||
const hooks = new Map();
|
||||
|
||||
try {
|
||||
@@ -17,6 +24,7 @@ class HooksManager {
|
||||
|
||||
try {
|
||||
const hook = require(path.join(hooksPath, file));
|
||||
/** @type {import("../../types/main/core").WindowName} */
|
||||
const targetWindow = hook.windowName || path.basename(file, ".js");
|
||||
hooks.set(targetWindow, hook);
|
||||
console.log(
|
||||
@@ -40,13 +48,19 @@ class HooksManager {
|
||||
return hooks;
|
||||
}
|
||||
|
||||
cleanupWindow(windowKey, listeners) {
|
||||
/**
|
||||
*
|
||||
* @param {import("../../types/main/core").WindowName} windowKey
|
||||
* @param {import("../../types/main/core").HookedWindow} hookedWindowProps
|
||||
*/
|
||||
cleanupWindow(windowKey, hookedWindowProps) {
|
||||
console.log(
|
||||
`[HugoAura / Cleanup / ${windowKey}] Window destroyed, cleaning up...`
|
||||
);
|
||||
|
||||
if (listeners) {
|
||||
const { webContents, domReadyListener, destroyedListener } = listeners;
|
||||
if (hookedWindowProps) {
|
||||
const { webContents, domReadyListener, destroyedListener } =
|
||||
hookedWindowProps;
|
||||
webContents.removeListener("dom-ready", domReadyListener);
|
||||
webContents.removeListener("destroyed", destroyedListener);
|
||||
}
|
||||
@@ -54,9 +68,17 @@ class HooksManager {
|
||||
global.__HUGO_AURA__.hookedWindows.delete(windowKey);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("electron").WebContents} webContents
|
||||
* @param {import("../../types/render/uiHook").UIHookConfigFin} hookConfig
|
||||
* @param {import("../../types/main/core").WindowName} windowName
|
||||
* @returns
|
||||
*/
|
||||
handleWindowHook(webContents, hookConfig, windowName) {
|
||||
if (!hookConfig) return;
|
||||
|
||||
/** @type {import("../../types/main/core").WindowName} */
|
||||
const windowKey = `${hookConfig.windowName || windowName}`;
|
||||
if (global.__HUGO_AURA__.hookedWindows.has(windowKey)) {
|
||||
console.log(
|
||||
|
||||
0
src/aura/init/rendererHook/injection.js
Normal file → Executable file
0
src/aura/init/rendererHook/injection.js
Normal file → Executable file
0
src/aura/init/rendererHook/networkHook.js
Normal file → Executable file
0
src/aura/init/rendererHook/networkHook.js
Normal file → Executable file
0
src/aura/init/shared/configManager.js
Normal file → Executable file
0
src/aura/init/shared/configManager.js
Normal file → Executable file
1
src/aura/init/shared/default.json
Normal file → Executable file
1
src/aura/init/shared/default.json
Normal file → Executable file
@@ -18,5 +18,6 @@
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"plsToken": "66ccff0d000721114514191981023333",
|
||||
"devTools": false
|
||||
}
|
||||
|
||||
0
src/aura/init/zeron/hookWS.js
Normal file → Executable file
0
src/aura/init/zeron/hookWS.js
Normal file → Executable file
Reference in New Issue
Block a user