mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-22 08:14:26 +08:00
[Init] First production version
This commit is contained in:
47
src/core/hook.js
Normal file
47
src/core/hook.js
Normal file
@@ -0,0 +1,47 @@
|
||||
if (!global.__HUGO_AURA__) {
|
||||
global.__HUGO_AURA__ = {
|
||||
hookedWindows: new Map(),
|
||||
hooks: null,
|
||||
configInit: false,
|
||||
};
|
||||
}
|
||||
|
||||
const HooksManager = require("../aura/init/hook/hooksManager");
|
||||
const configManager = require("../aura/init/shared/configManager");
|
||||
|
||||
module.exports = function ({ central, windowName, config }) {
|
||||
process.stdout.isTTY = true;
|
||||
process.stderr.isTTY = true;
|
||||
|
||||
const electron = central(0);
|
||||
const app = electron.app;
|
||||
|
||||
console.log("[HugoAura / Loaded] Aura is loaded!");
|
||||
|
||||
const hooksManager = new HooksManager();
|
||||
configManager.ensureConfigExists();
|
||||
const loadedConfig = configManager.loadConfig();
|
||||
if (!global.__HUGO_AURA__.configInit) global.__HUGO_AURA__.configInit = true;
|
||||
const hooks = hooksManager.loadHooks();
|
||||
|
||||
if (loadedConfig.devTools && !config.canOpenDevTool) {
|
||||
config.canOpenDevTool = true;
|
||||
}
|
||||
|
||||
const webContentsCreatedListener = (_event, webContents) => {
|
||||
const hookConfig = hooks.get(windowName);
|
||||
if (hookConfig) {
|
||||
hooksManager.handleWindowHook(webContents, hookConfig, windowName);
|
||||
} else {
|
||||
console.debug(
|
||||
`[HugoAura / Init] Window ${windowName} has no corresponding hook, ignoring...`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
app.once("web-contents-created", webContentsCreatedListener);
|
||||
|
||||
return () => {
|
||||
app.removeListener("web-contents-created", webContentsCreatedListener);
|
||||
};
|
||||
};
|
||||
41
src/core/preload.js
Normal file
41
src/core/preload.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(() => {
|
||||
if (!global.__HUGO_AURA__) {
|
||||
global.__HUGO_AURA__ = {
|
||||
configInit: true,
|
||||
};
|
||||
}
|
||||
const configManager = require("../aura/init/shared/configManager");
|
||||
const WebpackHook = require("../aura/init/preload/webpackHook");
|
||||
|
||||
console.log(`[HugoAura / AppHook / Preload] Preparing...`);
|
||||
|
||||
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;
|
||||
console.log(
|
||||
`[HugoAura / Config] Config changed at path: ${[...path, prop].join(
|
||||
"."
|
||||
)}`
|
||||
);
|
||||
configManager.writeConfig(window.__HUGO_AURA_CONFIG__);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const initialConfig = configManager.readConfig();
|
||||
window.__HUGO_AURA_CONFIG__ = createConfigProxy(initialConfig);
|
||||
|
||||
window.__HUGO_AURA_HOOK__ = {};
|
||||
const webpackHook = new WebpackHook();
|
||||
webpackHook.installHook(window, initialConfig);
|
||||
|
||||
console.log(`[HugoAura / AppHook / DONE] Hooks installed`);
|
||||
})();
|
||||
Reference in New Issue
Block a user