mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-22 16:24:27 +08:00
[Feat] New settings passwd UX & Config enc support
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
if (!global.__HUGO_AURA__) {
|
||||
/**
|
||||
* @type {import("../aura/types/main/core").MainProcessGlobal}
|
||||
*/
|
||||
const __HUGO_AURA__ = {
|
||||
hookedWindows: new Map(),
|
||||
hooks: new Map(),
|
||||
configInit: false,
|
||||
central: () => {},
|
||||
ipcInit: false,
|
||||
plsStats: null,
|
||||
plsSettings: null,
|
||||
plsRules: null,
|
||||
uiHooks: new Map(),
|
||||
windowHooks: new Map(),
|
||||
version: require("./preload").__AURA_VERSION__,
|
||||
};
|
||||
global.__HUGO_AURA__ = __HUGO_AURA__;
|
||||
}
|
||||
@@ -26,8 +27,9 @@ const os = require("os");
|
||||
|
||||
const MainProcessHooksManager = require("../aura/init/main/windowHooksManager");
|
||||
const RendererHooksManager = require("../aura/init/rendererHook/uiHooksManager");
|
||||
const EventBus = require("../aura/utils/eventBus");
|
||||
const NetworkHook = require("../aura/init/rendererHook/networkHook");
|
||||
const configManager = require("../aura/init/shared/configManager");
|
||||
const ConfigManager = require("../aura/init/shared/configManager");
|
||||
const { buildIpcMain } = require("../aura/init/main/ipcHandler");
|
||||
|
||||
/**
|
||||
@@ -101,9 +103,11 @@ const initLogger = (windowName) => {
|
||||
* @returns
|
||||
*/
|
||||
const launcher = ({ central, windowName, config }) => {
|
||||
// >>> Init STD <<< //
|
||||
process.stdout.isTTY = true;
|
||||
process.stderr.isTTY = true;
|
||||
|
||||
// >>> Basic Config <<< //
|
||||
/** @type {Electron} */
|
||||
const electron = central(1);
|
||||
const app = electron.app;
|
||||
@@ -114,34 +118,58 @@ const launcher = ({ central, windowName, config }) => {
|
||||
app.exit(0);
|
||||
};
|
||||
|
||||
// >>> Init Logger <<< //
|
||||
initLogger(windowName);
|
||||
|
||||
console.log("[HugoAura / Loaded] Aura is loaded!");
|
||||
console.debug(`[HugoAura / Debug] curWindowName: ${windowName}`);
|
||||
|
||||
// >>> Init EventBus <<< //
|
||||
if (!global.__HUGO_AURA_EVENT_BUS__)
|
||||
global.__HUGO_AURA_EVENT_BUS__ = new EventBus();
|
||||
|
||||
// >>> Init Config <<< //
|
||||
const configManager = new ConfigManager();
|
||||
configManager.side = "main";
|
||||
configManager.ensureConfigExists();
|
||||
const loadedConfig = configManager.loadConfig();
|
||||
if (!global.__HUGO_AURA__.configInit) global.__HUGO_AURA__.configInit = true;
|
||||
if (!global.__HUGO_AURA_CONFIG_MGR__) global.__HUGO_AURA_CONFIG_MGR__ = configManager;
|
||||
|
||||
global.__HUGO_AURA_CONFIG__ = loadedConfig;
|
||||
|
||||
global.__HUGO_AURA_EVENT_BUS__.on("$aura.config.refreshConfig", () => {
|
||||
global.__HUGO_AURA_CONFIG__ = configManager.loadConfig();
|
||||
});
|
||||
|
||||
// >>> Init IPC Main <<< //
|
||||
if (!global.__HUGO_AURA__.ipcInit) {
|
||||
buildIpcMain(electron);
|
||||
global.__HUGO_AURA__.ipcInit = true;
|
||||
}
|
||||
|
||||
// >>> Init Main Process Hooks <<< //
|
||||
const mainProcessHooksManager = new MainProcessHooksManager();
|
||||
|
||||
const _windowHooks = mainProcessHooksManager.loadHooks();
|
||||
|
||||
// >>> Init Renderer Process Hooks <<< //
|
||||
const uiHooksManager = new RendererHooksManager();
|
||||
|
||||
const uiHooks = uiHooksManager.loadHooks();
|
||||
|
||||
// >>> Activate DevTools <<< //
|
||||
if (loadedConfig.devTools && !config.canOpenDevTool) {
|
||||
config.canOpenDevTool = true;
|
||||
}
|
||||
|
||||
// >>> Listeners <<< //
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {any} _event
|
||||
* @param {import("electron").BrowserWindow} browserWindow
|
||||
*/
|
||||
const browserWindowCreatedListener = (_event, browserWindow) => {
|
||||
mainProcessHooksManager.initHookForWindow(
|
||||
windowName,
|
||||
@@ -153,7 +181,7 @@ const launcher = ({ central, windowName, config }) => {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Event} _event
|
||||
* @param {any} _event
|
||||
* @param {import("electron").WebContents} webContents
|
||||
*/
|
||||
const webContentsCreatedListener = (_event, webContents) => {
|
||||
@@ -180,13 +208,10 @@ const launcher = ({ central, windowName, config }) => {
|
||||
};
|
||||
|
||||
app.once("browser-window-created", browserWindowCreatedListener);
|
||||
// @ts-expect-error
|
||||
// ↑ idk why
|
||||
app.once("web-contents-created", webContentsCreatedListener);
|
||||
|
||||
return () => {
|
||||
app.removeListener("browser-window-created", browserWindowCreatedListener);
|
||||
// @ts-expect-error
|
||||
app.removeListener("web-contents-created", webContentsCreatedListener);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
const __AURA_VERSION__ = "0.1.1-pre-II";
|
||||
// @ts-check
|
||||
|
||||
const __AURA_VERSION__ = "0.1.1-pre-III";
|
||||
|
||||
(() => {
|
||||
if (require.main) return; // 如果只是导入 Aura Version, 不运行闭包逻辑
|
||||
|
||||
// >>> Init Global Vars <<< //
|
||||
if (!global.__HUGO_AURA__) {
|
||||
global.__HUGO_AURA__ = {
|
||||
configInit: true, // preload 始终比 hook 晚, 默认 config 已初始化
|
||||
// ↑ 保留此参数的目的 -> 用于 configManager 中, configManager 的行为在 Renderer 和 Main 中是一致的
|
||||
version: __AURA_VERSION__,
|
||||
};
|
||||
}
|
||||
@@ -16,11 +22,29 @@ const __AURA_VERSION__ = "0.1.1-pre-II";
|
||||
global.__HUGO_AURA_UI_REACTIVES__ = {};
|
||||
}
|
||||
|
||||
const configManager = require("../aura/init/shared/configManager");
|
||||
// >>> 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");
|
||||
const WebpackHook = require("../aura/init/preload/webpackHook");
|
||||
|
||||
console.log(`[HugoAura / AppHook / Preload] Preparing...`);
|
||||
const configManager = new ConfigManager();
|
||||
configManager.side = "renderer";
|
||||
if (!global.__HUGO_AURA_CONFIG_MGR__)
|
||||
global.__HUGO_AURA_CONFIG_MGR__ = configManager;
|
||||
|
||||
console.log(`[HugoAura / Preload] Preparing...`);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {any} baseObj
|
||||
* @param {(string | symbol)[]} path
|
||||
* @returns
|
||||
*/
|
||||
const createConfigProxy = (baseObj, path = []) => {
|
||||
return new Proxy(baseObj, {
|
||||
get(target, prop) {
|
||||
@@ -37,24 +61,76 @@ const __AURA_VERSION__ = "0.1.1-pre-II";
|
||||
value,
|
||||
},
|
||||
});
|
||||
const pathName = [...path, prop].join(".");
|
||||
document.dispatchEvent(configUpdateEvent);
|
||||
console.log(
|
||||
`[HugoAura / Config] Config changed at path: ${[...path, prop].join(
|
||||
"."
|
||||
)}, new value: ${value}`
|
||||
);
|
||||
configManager.writeConfig(window.__HUGO_AURA_CONFIG__);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const initialConfig = configManager.readConfig();
|
||||
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();
|
||||
window.__HUGO_AURA_CONFIG__ = createConfigProxy(initialConfig);
|
||||
|
||||
// >>> Init Renderer Hooks <<< //
|
||||
window.__HUGO_AURA_HOOK__ = {};
|
||||
const webpackHook = new WebpackHook();
|
||||
webpackHook.installHook(window, initialConfig);
|
||||
|
||||
// >>> Done <<< //
|
||||
console.log(`[HugoAura / AppHook / DONE] Hooks installed`);
|
||||
console.log(`[HugoAura / Preload / DONE] Preload done`);
|
||||
})();
|
||||
|
||||
module.exports = { __AURA_VERSION__ };
|
||||
|
||||
Reference in New Issue
Block a user