mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-20 23:14:28 +08:00
[🛠️ Fix] Emergency fix for invalid config read logic
1. [/] 紧急修复了上个 commit 中引入的错误路径获取逻辑
This commit is contained in:
@@ -54,6 +54,20 @@ const applyBaseIpcHandler = (ipcMain) => {
|
|||||||
browserWindowIns.close();
|
browserWindowIns.close();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ipcMain.handle(`${methodBase}.getAuraDirAsync`, (_evt, _arg) => {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: global.__HUGO_AURA__.auraDir,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on(`${methodBase}.getAuraDirSync`, (event, _arg) => {
|
||||||
|
event.returnValue = {
|
||||||
|
success: true,
|
||||||
|
data: global.__HUGO_AURA__.auraDir,
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { applyBaseIpcHandler };
|
module.exports = { applyBaseIpcHandler };
|
||||||
|
|||||||
@@ -8,13 +8,6 @@ const __SCOPE = "main";
|
|||||||
*/
|
*/
|
||||||
const applyDebugIpcHandler = (ipcMain) => {
|
const applyDebugIpcHandler = (ipcMain) => {
|
||||||
const methodBase = "$aura.debug";
|
const methodBase = "$aura.debug";
|
||||||
|
|
||||||
ipcMain.handle(`${methodBase}.getLogDirAsync`, (_evt, _arg) => {
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
data: global.__HUGO_AURA__.logDir,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { applyDebugIpcHandler };
|
module.exports = { applyDebugIpcHandler };
|
||||||
|
|||||||
@@ -2,40 +2,13 @@ const path = require("path");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
const RegistryManager = require("../shared/registryManager");
|
|
||||||
|
|
||||||
const getUserDocumentsDirPath = () => {
|
|
||||||
const registryManager = new RegistryManager();
|
|
||||||
const pathInfo = registryManager.readRegKeySync(
|
|
||||||
'"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"',
|
|
||||||
"Personal",
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
/REG_EXPAND_SZ\s+(.+)/
|
|
||||||
);
|
|
||||||
if (pathInfo.success) {
|
|
||||||
const resolvedPath = pathInfo.data.replace(
|
|
||||||
/%([^%]+)%/g,
|
|
||||||
(match, varName) => {
|
|
||||||
return process.env[varName] || match;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return resolvedPath;
|
|
||||||
} else {
|
|
||||||
console.error(
|
|
||||||
"[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val."
|
|
||||||
);
|
|
||||||
return path.join(os.homedir(), "Documents");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import("../aura/types/main/core").WindowName} windowName
|
* @param {import("../aura/types/main/core").WindowName} windowName
|
||||||
*/
|
*/
|
||||||
const initLogger = (windowName) => {
|
const initLogger = (windowName) => {
|
||||||
const logDir = path.join(getUserDocumentsDirPath(), "HugoAura", "logs");
|
const logDir = path.join(global.__HUGO_AURA__.auraDir, "logs");
|
||||||
|
|
||||||
global.__HUGO_AURA__.logDir = logDir;
|
global.__HUGO_AURA__.logDir = logDir;
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const deepMerge = (target, source) => {
|
|||||||
|
|
||||||
class ConfigManager {
|
class ConfigManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.configDir = path.join(global.__HUGO_AURA__.logDir, "..");
|
this.configDir = global.__HUGO_AURA__.auraDir;
|
||||||
this.configPath = path.join(this.configDir, "config.json");
|
this.configPath = path.join(this.configDir, "config.json");
|
||||||
this.encConfigPath = path.join(this.configDir, ".cache_2eafc8d0.dat"); // (雾
|
this.encConfigPath = path.join(this.configDir, ".cache_2eafc8d0.dat"); // (雾
|
||||||
/* ↑ 不使用 .tmp 扩展名, 不然容易真被清理了 */
|
/* ↑ 不使用 .tmp 扩展名, 不然容易真被清理了 */
|
||||||
@@ -99,6 +99,7 @@ class ConfigManager {
|
|||||||
if (this.configDir === path.join(os.homedir(), "Documents", "HugoAura")) {
|
if (this.configDir === path.join(os.homedir(), "Documents", "HugoAura")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldConfigPath = path.join(
|
const oldConfigPath = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
"Documents",
|
"Documents",
|
||||||
@@ -111,6 +112,7 @@ class ConfigManager {
|
|||||||
"HugoAura",
|
"HugoAura",
|
||||||
".cache_2eafc8d0.dat"
|
".cache_2eafc8d0.dat"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fs.existsSync(oldConfigPath)) {
|
if (fs.existsSync(oldConfigPath)) {
|
||||||
fs.copyFileSync(oldConfigPath, this.configPath);
|
fs.copyFileSync(oldConfigPath, this.configPath);
|
||||||
fs.unlinkSync(oldConfigPath);
|
fs.unlinkSync(oldConfigPath);
|
||||||
|
|||||||
2
src/aura/types/shared/global.d.ts
vendored
2
src/aura/types/shared/global.d.ts
vendored
@@ -14,7 +14,7 @@ interface GlobalHugoAuraInfo {
|
|||||||
fsTasks?: MainProcessOnlyVal<FSTasks>;
|
fsTasks?: MainProcessOnlyVal<FSTasks>;
|
||||||
hookedWindows?: MainProcessOnlyVal<HookedWindowsMap>;
|
hookedWindows?: MainProcessOnlyVal<HookedWindowsMap>;
|
||||||
ipcInit?: MainProcessOnlyVal<boolean>;
|
ipcInit?: MainProcessOnlyVal<boolean>;
|
||||||
logDir: MainProcessOnlyVal<string>;
|
auraDir: MainProcessOnlyVal<string>;
|
||||||
plsRules?: Record<any, any> | null;
|
plsRules?: Record<any, any> | null;
|
||||||
plsSettings?: Record<any, any> | null;
|
plsSettings?: Record<any, any> | null;
|
||||||
plsStats?: PLSStatus | null;
|
plsStats?: PLSStatus | null;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const IPC_METHOD_BASE = "$aura.debug";
|
const IPC_METHOD_BASE = "$aura.debug";
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
const debugSettings = [
|
const debugSettings = [
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -18,19 +20,22 @@ const debugSettings = [
|
|||||||
auraIf: () => true,
|
auraIf: () => true,
|
||||||
buttonContent: "打开",
|
buttonContent: "打开",
|
||||||
valueGetter: async () => {
|
valueGetter: async () => {
|
||||||
const ipcRendererRet = await ipcRenderer.invoke(
|
if (
|
||||||
`${IPC_METHOD_BASE}.getLogDirAsync`
|
global.__HUGO_AURA__.auraDir &&
|
||||||
);
|
global.__HUGO_AURA__.auraDir !== ""
|
||||||
if (ipcRendererRet.success && ipcRendererRet.data !== "") {
|
) {
|
||||||
global.__HUGO_AURA__.logDir = ipcRendererRet.data;
|
return (
|
||||||
return "目录位置: " + ipcRendererRet.data;
|
"目录位置: " + path.join(global.__HUGO_AURA__.auraDir, "logs")
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return "未能获取日志目录位置";
|
return "未能获取日志目录位置";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
callbackFn: async (event) => {
|
callbackFn: async (event) => {
|
||||||
const childProc = require("child_process");
|
const childProc = require("child_process");
|
||||||
childProc.spawn(`explorer.exe`, [`${global.__HUGO_AURA__.logDir}`]);
|
childProc.spawn(`explorer.exe`, [
|
||||||
|
`${path.join(global.__HUGO_AURA__.auraDir, "logs")}`,
|
||||||
|
]);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ if (!global.__HUGO_AURA__) {
|
|||||||
configInit: false,
|
configInit: false,
|
||||||
central: () => {},
|
central: () => {},
|
||||||
ipcInit: false,
|
ipcInit: false,
|
||||||
logDir: "",
|
auraDir: "",
|
||||||
plsStats: null,
|
plsStats: null,
|
||||||
plsSettings: null,
|
plsSettings: null,
|
||||||
plsRules: null,
|
plsRules: null,
|
||||||
@@ -37,15 +37,45 @@ if (!global.__HUGO_AURA_CONFIG__) {
|
|||||||
global.__HUGO_AURA_CONFIG__ = {};
|
global.__HUGO_AURA_CONFIG__ = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
|
const os = require("os");
|
||||||
|
|
||||||
const MainProcessHooksManager = require("../aura/init/main/windowHooksManager");
|
const MainProcessHooksManager = require("../aura/init/main/windowHooksManager");
|
||||||
const RendererHooksManager = require("../aura/init/rendererHook/uiHooksManager");
|
const RendererHooksManager = require("../aura/init/rendererHook/uiHooksManager");
|
||||||
const EventBus = require("../aura/utils/eventBus");
|
const EventBus = require("../aura/utils/eventBus");
|
||||||
const NetworkHook = require("../aura/init/rendererHook/networkHook");
|
const NetworkHook = require("../aura/init/rendererHook/networkHook");
|
||||||
const ConfigManager = require("../aura/init/shared/configManager");
|
const ConfigManager = require("../aura/init/shared/configManager");
|
||||||
|
const RegistryManager = require("../aura/init/shared/registryManager");
|
||||||
const { buildIpcMain } = require("../aura/init/main/ipcHandler");
|
const { buildIpcMain } = require("../aura/init/main/ipcHandler");
|
||||||
|
|
||||||
const { initLogger } = require("../aura/init/main/logger");
|
const { initLogger } = require("../aura/init/main/logger");
|
||||||
|
|
||||||
|
const getUserDocumentsDirPath = () => {
|
||||||
|
const registryManager = new RegistryManager();
|
||||||
|
const pathInfo = registryManager.readRegKeySync(
|
||||||
|
'"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"',
|
||||||
|
"Personal",
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
/REG_EXPAND_SZ\s+(.+)/
|
||||||
|
);
|
||||||
|
if (pathInfo.success && pathInfo.data) {
|
||||||
|
const resolvedPath = pathInfo.data.replace(
|
||||||
|
/%([^%]+)%/g,
|
||||||
|
(match, varName) => {
|
||||||
|
return process.env[varName] || match;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return resolvedPath;
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
"[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val."
|
||||||
|
);
|
||||||
|
return path.join(os.homedir(), "Documents");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import("../aura/types/main/core").LauncherArgs} param0
|
* @param {import("../aura/types/main/core").LauncherArgs} param0
|
||||||
@@ -67,6 +97,8 @@ const launcher = ({ central, windowName, config }) => {
|
|||||||
app.exit(0);
|
app.exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
global.__HUGO_AURA__.auraDir = path.join(getUserDocumentsDirPath(), "HugoAura");
|
||||||
|
|
||||||
// >>> Init Logger <<< //
|
// >>> Init Logger <<< //
|
||||||
initLogger(windowName);
|
initLogger(windowName);
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,14 @@ const __AURA_VERSION__ = "0.1.1-pre-IV";
|
|||||||
(() => {
|
(() => {
|
||||||
if (require.main) return; // 如果只是导入 Aura Version, 不运行闭包逻辑
|
if (require.main) return; // 如果只是导入 Aura Version, 不运行闭包逻辑
|
||||||
|
|
||||||
|
const auraDir = require("electron").ipcRenderer.sendSync(
|
||||||
|
"$aura.base.getAuraDirSync"
|
||||||
|
);
|
||||||
|
|
||||||
// >>> Init Global Vars <<< //
|
// >>> Init Global Vars <<< //
|
||||||
if (!global.__HUGO_AURA__) {
|
if (!global.__HUGO_AURA__) {
|
||||||
global.__HUGO_AURA__ = {
|
global.__HUGO_AURA__ = {
|
||||||
|
auraDir: auraDir.data,
|
||||||
configInit: true, // preload 始终比 hook 晚, 默认 config 已初始化
|
configInit: true, // preload 始终比 hook 晚, 默认 config 已初始化
|
||||||
// ↑ 保留此参数的目的 -> 用于 configManager 中, configManager 的行为在 Renderer 和 Main 中是一致的
|
// ↑ 保留此参数的目的 -> 用于 configManager 中, configManager 的行为在 Renderer 和 Main 中是一致的
|
||||||
version: __AURA_VERSION__,
|
version: __AURA_VERSION__,
|
||||||
|
|||||||
Reference in New Issue
Block a user