2025-06-05 00:35:50 +08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
const __AURA_VERSION__ = "0.1.1-pre-III";
|
2025-04-18 19:20:46 +08:00
|
|
|
|
2024-11-28 01:47:04 +08:00
|
|
|
(() => {
|
2025-06-05 00:35:50 +08:00
|
|
|
if (require.main) return; // 如果只是导入 Aura Version, 不运行闭包逻辑
|
|
|
|
|
|
|
|
|
|
// >>> Init Global Vars <<< //
|
2024-11-28 01:47:04 +08:00
|
|
|
if (!global.__HUGO_AURA__) {
|
|
|
|
|
global.__HUGO_AURA__ = {
|
2025-04-18 19:20:46 +08:00
|
|
|
configInit: true, // preload 始终比 hook 晚, 默认 config 已初始化
|
2025-06-05 00:35:50 +08:00
|
|
|
// ↑ 保留此参数的目的 -> 用于 configManager 中, configManager 的行为在 Renderer 和 Main 中是一致的
|
2025-04-18 19:20:46 +08:00
|
|
|
version: __AURA_VERSION__,
|
2024-11-28 01:47:04 +08:00
|
|
|
};
|
|
|
|
|
}
|
2025-04-18 19:20:46 +08:00
|
|
|
|
|
|
|
|
if (!global.__HUGO_AURA_UI_FUNCTIONS__) {
|
|
|
|
|
global.__HUGO_AURA_UI_FUNCTIONS__ = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!global.__HUGO_AURA_UI_REACTIVES__) {
|
|
|
|
|
global.__HUGO_AURA_UI_REACTIVES__ = {};
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
// >>> Init EventBus <<< //
|
|
|
|
|
const EventBus = require("../aura/utils/eventBus");
|
|
|
|
|
if (!global.__HUGO_AURA_EVENT_BUS__) {
|
|
|
|
|
global.__HUGO_AURA_EVENT_BUS__ = new EventBus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// >>> Load Modules <<< //
|
|
|
|
|
const ConfigManager = require("../aura/init/shared/configManager");
|
2024-11-28 01:47:04 +08:00
|
|
|
const WebpackHook = require("../aura/init/preload/webpackHook");
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
const configManager = new ConfigManager();
|
|
|
|
|
configManager.side = "renderer";
|
|
|
|
|
if (!global.__HUGO_AURA_CONFIG_MGR__)
|
|
|
|
|
global.__HUGO_AURA_CONFIG_MGR__ = configManager;
|
2024-11-28 01:47:04 +08:00
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
console.log(`[HugoAura / Preload] Preparing...`);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {any} baseObj
|
|
|
|
|
* @param {(string | symbol)[]} path
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2024-11-28 01:47:04 +08:00
|
|
|
const createConfigProxy = (baseObj, path = []) => {
|
|
|
|
|
return new Proxy(baseObj, {
|
|
|
|
|
get(target, prop) {
|
|
|
|
|
if (typeof target[prop] === "object" && target[prop] !== null) {
|
|
|
|
|
return createConfigProxy(target[prop], [...path, prop]);
|
|
|
|
|
}
|
|
|
|
|
return target[prop];
|
|
|
|
|
},
|
|
|
|
|
set(target, prop, value) {
|
|
|
|
|
target[prop] = value;
|
2025-04-18 19:20:46 +08:00
|
|
|
const configUpdateEvent = new CustomEvent("onHugoAuraConfigUpdate", {
|
|
|
|
|
detail: {
|
|
|
|
|
path: [...path, prop],
|
|
|
|
|
value,
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-06-05 00:35:50 +08:00
|
|
|
const pathName = [...path, prop].join(".");
|
2025-04-18 19:20:46 +08:00
|
|
|
document.dispatchEvent(configUpdateEvent);
|
2024-11-28 01:47:04 +08:00
|
|
|
console.log(
|
|
|
|
|
`[HugoAura / Config] Config changed at path: ${[...path, prop].join(
|
|
|
|
|
"."
|
2025-04-18 19:20:46 +08:00
|
|
|
)}, new value: ${value}`
|
2024-11-28 01:47:04 +08:00
|
|
|
);
|
2025-06-05 00:35:50 +08:00
|
|
|
|
|
|
|
|
const isEditingEncSettings = pathName.includes(
|
|
|
|
|
"auraSettings.settingsPassword"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
isEditingEncSettings &&
|
|
|
|
|
global.__HUGO_AURA_CONFIG__.auraSettings.encryptConfig
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!configManager.useEncConfig) {
|
|
|
|
|
configManager.writeConfig(window.__HUGO_AURA_CONFIG__); // 仅非加密 Config 使用即时写入, 否则会导致性能问题
|
|
|
|
|
} else {
|
|
|
|
|
if (global.__HUGO_AURA_UI_REACTIVES__.config) {
|
|
|
|
|
global.__HUGO_AURA_UI_REACTIVES__.config.isConfigPendingWrite = true;
|
|
|
|
|
}
|
|
|
|
|
if (global.__HUGO_AURA_UI_FUNCTIONS__.config?.handleACSNShow) {
|
|
|
|
|
global.__HUGO_AURA_UI_FUNCTIONS__.config.handleACSNShow();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-28 01:47:04 +08:00
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
const getConfig = () => {
|
|
|
|
|
/*
|
|
|
|
|
if (configManager.useEncConfig) {
|
|
|
|
|
if (!ipcRenderer) ipcRenderer = require("electron").ipcRenderer;
|
|
|
|
|
const result = ipcRenderer.sendSync("$aura.config.getConfigFromMainSync");
|
|
|
|
|
if (result.success) {
|
|
|
|
|
configManager.isConfigReadFailed = false;
|
|
|
|
|
return result.data;
|
|
|
|
|
} else {
|
|
|
|
|
configManager.isConfigReadFailed = true;
|
|
|
|
|
return configManager.getDefaultConfig();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const result = configManager.readConfig();
|
|
|
|
|
configManager.isConfigReadFailed = false;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
// ↑ IPC Renderer 在 Preload 时无法访问, 因此无法从主进程拉取配置
|
|
|
|
|
const result = configManager.readConfig();
|
|
|
|
|
configManager.isConfigReadFailed = false;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// >>> Init Config <<< //
|
|
|
|
|
const initialConfig = getConfig();
|
2024-11-28 01:47:04 +08:00
|
|
|
window.__HUGO_AURA_CONFIG__ = createConfigProxy(initialConfig);
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
// >>> Init Renderer Hooks <<< //
|
2024-11-28 01:47:04 +08:00
|
|
|
window.__HUGO_AURA_HOOK__ = {};
|
|
|
|
|
const webpackHook = new WebpackHook();
|
|
|
|
|
webpackHook.installHook(window, initialConfig);
|
|
|
|
|
|
2025-06-05 00:35:50 +08:00
|
|
|
// >>> Done <<< //
|
2024-11-28 01:47:04 +08:00
|
|
|
console.log(`[HugoAura / AppHook / DONE] Hooks installed`);
|
2025-06-05 00:35:50 +08:00
|
|
|
console.log(`[HugoAura / Preload / DONE] Preload done`);
|
2024-11-28 01:47:04 +08:00
|
|
|
})();
|
2025-06-05 00:35:50 +08:00
|
|
|
|
|
|
|
|
module.exports = { __AURA_VERSION__ };
|