[ Feat] Customize usbInsertPrompt behaviour (#59)

This commit is contained in:
Minoricew
2025-11-29 15:59:09 +08:00
parent b27b1a6573
commit f7feca7ff2
4 changed files with 167 additions and 17 deletions

View File

@@ -40,6 +40,8 @@ class NetworkHook {
endOfHook: rule.endOfHook || null, endOfHook: rule.endOfHook || null,
hookedContent: rule.hookedContent || null, hookedContent: rule.hookedContent || null,
hookedContentFunc: rule.hookedContentFunc || null, hookedContentFunc: rule.hookedContentFunc || null,
ruleFn: rule.ruleFn || null,
config: ruleConfig || null,
}); });
console.log(`[HugoAura / NetworkHook] Loaded rule: ${rulePath}`); console.log(`[HugoAura / NetworkHook] Loaded rule: ${rulePath}`);
} }
@@ -240,44 +242,49 @@ class NetworkHook {
hookContent + hookContent +
endHook + endHook +
content.substring(endIdx); content.substring(endIdx);
const tempDir = path.join(os.tmpdir(), "hugo-aura-temp");
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
const tempFile = path.join(tempDir, path.basename(normalizedPath));
fs.writeFileSync(tempFile, content, "utf8");
return {
redirectURL: `file://${
process.platform === "win32" ? "/" : ""
}${encodeURI(tempFile.replace(/\\/g, "/"))}`, // Seewo Hugo is still on Node 12 / Electron 8 TwT
};
} else { } else {
console.warn( console.warn(
`[HugoAura / NetworkHook] Could not find match points in file: ${normalizedPath}` `[HugoAura / NetworkHook] Could not find match points in file: ${normalizedPath}`
); );
return undefined; return false;
} }
} else if (rule.ruleFn) {
content = rule.ruleFn(content, rule.config);
} else { } else {
console.error( console.error(
`[HugoAura / NetworkHook] Error processing rule:`, `[HugoAura / NetworkHook] Error processing rule:`,
rule rule,
"No available hook impl found."
); );
return false;
} }
const tempDir = path.join(os.tmpdir(), "hugo-aura-temp");
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
const tempFile = path.join(tempDir, path.basename(normalizedPath));
fs.writeFileSync(tempFile, content, "utf8");
return {
redirectURL: `file://${
process.platform === "win32" ? "/" : ""
}${encodeURI(tempFile.replace(/\\/g, "/"))}`, // Seewo Hugo is still on Node 12 / Electron 8 TwT
};
} else { } else {
console.error( console.error(
`[HugoAura / NetworkHook] Error processing local file: normalizedPath not exists`, `[HugoAura / NetworkHook] Error processing local file: normalizedPath not exists`,
normalizedPath normalizedPath
); );
return false;
} }
} catch (err) { } catch (err) {
console.error( console.error(
`[HugoAura / NetworkHook] Error processing local file:`, `[HugoAura / NetworkHook] Error processing local file:`,
err err
); );
return null; return false;
} }
} }

View File

@@ -24,6 +24,10 @@
}, },
"disableBehaviorAudit": { "disableBehaviorAudit": {
"enabled": true "enabled": true
},
"appearance/switchUsbInsertPromptBtn": {
"enabled": true,
"mode": "switch"
} }
}, },
"ssa": { "ssa": {

View File

@@ -0,0 +1,31 @@
/// Rewrite rules basic config section begins ///
const type = "localResource";
const urlPattern = "usbInsertPrompt.js";
/// End of the rewrite rules basic config section ///
let ruleFn = (originalContent, ruleConfig) => {
if (ruleConfig.mode === "switch") {
originalContent = originalContent.replace(/查杀可预防设备感染,守护设备安全/g, "检测到新的设备插入");
originalContent = originalContent.replace(/开始查杀(推荐)/g, "打开 U 盘");
originalContent = originalContent.replace(
/onClick:this.handleStartVirusKilling/g,
"onClick:this.handleOpen"
);
originalContent = originalContent.replace(
/,D.a.createElement\("p",null,"打开U盘"\)/g,
""
);
} else if (ruleConfig.mode === "hide") {
originalContent = originalContent.replace(/15e3/g, "0");
}
return originalContent;
};
module.exports = {
type,
urlPattern,
ruleFn,
};

View File

@@ -57,6 +57,114 @@ const uxAndAppearanceSettings = [
}, },
], ],
}, },
{
id: 1,
categoryName: "U 盘提示",
child: [
{
index: 0,
id: "switchUsbInsertPromptButton",
type: "switch",
name: '隐藏 U 盘插入提示悬浮窗的 "开始查杀" 按钮',
description: '启用后, "打开 U 盘" 将成为悬浮窗中的 Primary 按钮',
restart: true,
reload: false,
associateVal: [
"networkRewrite.appearance/switchUsbInsertPromptBtn.enabled",
],
auraIf: () => true,
defaultValue: false,
auraDisable: () => {
if (
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode === "hide" &&
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled
) {
return { value: true, tooltip: '禁用 "隐藏 U 盘插入提示" 以继续' };
} else {
return { value: false };
}
},
valueGetter: () => {
return (
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode === "switch" &&
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled
);
},
callbackFn: (newVal) => {
if (typeof newVal !== "boolean") return;
if (newVal === true) {
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode = "switch";
}
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled = newVal;
},
},
{
index: 1,
id: "hideUsbInsertPrompt",
type: "switch",
name: "隐藏 U 盘插入提示",
description: "启用后, 插入 U 盘将不再显示悬浮窗",
restart: true,
reload: false,
associateVal: [
"networkRewrite.appearance/switchUsbInsertPromptBtn.enabled",
],
auraIf: () => true,
defaultValue: false,
auraDisable: () => {
if (
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode === "switch" &&
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled
) {
return {
value: true,
tooltip:
'禁用 "隐藏 U 盘插入提示悬浮窗的 "开始查杀" 按钮" 以继续',
};
} else {
return { value: false };
}
},
valueGetter: () => {
return (
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode === "hide" &&
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled
);
},
callbackFn: (newVal) => {
if (typeof newVal !== "boolean") return;
if (newVal === true) {
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].mode = "hide";
}
global.__HUGO_AURA_CONFIG__.networkRewrite[
"appearance/switchUsbInsertPromptBtn"
].enabled = newVal;
},
},
],
},
]; ];
module.exports = { uxAndAppearanceSettings }; module.exports = { uxAndAppearanceSettings };