mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-21 15:44:26 +08:00
82 lines
2.1 KiB
JavaScript
Executable File
82 lines
2.1 KiB
JavaScript
Executable File
// @ts-check
|
|
|
|
const __SCOPE = "assistant / rendererCommon";
|
|
|
|
const IPC_METHOD_BASE = "$aura.pls";
|
|
|
|
const updatePlsStatusFromLocal = async () => {
|
|
const plsStatus = (
|
|
await global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.getPlsStats`)
|
|
).data;
|
|
global.__HUGO_AURA__.plsStats = plsStatus;
|
|
return plsStatus;
|
|
};
|
|
|
|
const updatePlsSettingsFromLocal = async () => {
|
|
const plsSettings = (
|
|
await global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.getPlsSettings`)
|
|
).data;
|
|
global.__HUGO_AURA__.plsSettings = plsSettings;
|
|
return plsSettings;
|
|
};
|
|
|
|
const updatePlsRulesFromLocal = async () => {
|
|
const plsRules = (
|
|
await global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.getPlsRules`)
|
|
).data;
|
|
global.__HUGO_AURA__.plsRules = plsRules;
|
|
return plsRules;
|
|
};
|
|
|
|
const { genRandomHex } = require("../../utils/crypto");
|
|
|
|
/**
|
|
*
|
|
* @param {string} configKey
|
|
* @param {any} configValue
|
|
*/
|
|
const updatePlsConfigToRemote = async (configKey, configValue) => {
|
|
const configLevels = configKey.split(".");
|
|
|
|
const plsConfigUpdateEvent = new CustomEvent("onPLSConfigUpdate", {
|
|
detail: {
|
|
path: configLevels,
|
|
value: configValue,
|
|
},
|
|
});
|
|
document.dispatchEvent(plsConfigUpdateEvent);
|
|
const settingsEntries = document.getElementsByClassName(
|
|
"aura-settings-entry"
|
|
);
|
|
if (settingsEntries.length > 0) {
|
|
Array.from(settingsEntries).forEach((entry) => {
|
|
entry.dispatchEvent(plsConfigUpdateEvent);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @type {ClientPLSRequest}
|
|
*/
|
|
const data = {
|
|
method: "config.action.updateConfig",
|
|
data: {
|
|
key: configKey,
|
|
value: configValue,
|
|
},
|
|
eventId: genRandomHex(), // 不用 crypto, 因为会带来不必要的性能开销
|
|
};
|
|
|
|
global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.ws.sendWsMessage`, data);
|
|
global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.syncPlsConfig`, {
|
|
basic: global.__HUGO_AURA__.plsSettings,
|
|
rules: global.__HUGO_AURA__.plsRules,
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
updatePlsRulesFromLocal,
|
|
updatePlsStatusFromLocal,
|
|
updatePlsSettingsFromLocal,
|
|
updatePlsConfigToRemote,
|
|
};
|