mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-20 23:14:28 +08:00
[✨ Feat] Customize usbInsertPrompt behaviour (#59)
This commit is contained in:
@@ -40,6 +40,8 @@ class NetworkHook {
|
||||
endOfHook: rule.endOfHook || null,
|
||||
hookedContent: rule.hookedContent || null,
|
||||
hookedContentFunc: rule.hookedContentFunc || null,
|
||||
ruleFn: rule.ruleFn || null,
|
||||
config: ruleConfig || null,
|
||||
});
|
||||
console.log(`[HugoAura / NetworkHook] Loaded rule: ${rulePath}`);
|
||||
}
|
||||
@@ -240,6 +242,22 @@ class NetworkHook {
|
||||
hookContent +
|
||||
endHook +
|
||||
content.substring(endIdx);
|
||||
} else {
|
||||
console.warn(
|
||||
`[HugoAura / NetworkHook] Could not find match points in file: ${normalizedPath}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if (rule.ruleFn) {
|
||||
content = rule.ruleFn(content, rule.config);
|
||||
} else {
|
||||
console.error(
|
||||
`[HugoAura / NetworkHook] Error processing rule:`,
|
||||
rule,
|
||||
"No available hook impl found."
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const tempDir = path.join(os.tmpdir(), "hugo-aura-temp");
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
@@ -254,30 +272,19 @@ class NetworkHook {
|
||||
process.platform === "win32" ? "/" : ""
|
||||
}${encodeURI(tempFile.replace(/\\/g, "/"))}`, // Seewo Hugo is still on Node 12 / Electron 8 TwT
|
||||
};
|
||||
} else {
|
||||
console.warn(
|
||||
`[HugoAura / NetworkHook] Could not find match points in file: ${normalizedPath}`
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
console.error(
|
||||
`[HugoAura / NetworkHook] Error processing rule:`,
|
||||
rule
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.error(
|
||||
`[HugoAura / NetworkHook] Error processing local file: normalizedPath not exists`,
|
||||
normalizedPath
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`[HugoAura / NetworkHook] Error processing local file:`,
|
||||
err
|
||||
);
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
},
|
||||
"disableBehaviorAudit": {
|
||||
"enabled": true
|
||||
},
|
||||
"appearance/switchUsbInsertPromptBtn": {
|
||||
"enabled": true,
|
||||
"mode": "switch"
|
||||
}
|
||||
},
|
||||
"ssa": {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user