diff --git a/src/aura/init/rendererHook/networkHook.js b/src/aura/init/rendererHook/networkHook.js index 965239b..26752e8 100755 --- a/src/aura/init/rendererHook/networkHook.js +++ b/src/aura/init/rendererHook/networkHook.js @@ -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,44 +242,49 @@ class NetworkHook { hookContent + endHook + 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 { console.warn( `[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 { console.error( `[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 { 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; } } diff --git a/src/aura/init/shared/default.json b/src/aura/init/shared/default.json index eb210b9..9ca7c48 100755 --- a/src/aura/init/shared/default.json +++ b/src/aura/init/shared/default.json @@ -24,6 +24,10 @@ }, "disableBehaviorAudit": { "enabled": true + }, + "appearance/switchUsbInsertPromptBtn": { + "enabled": true, + "mode": "switch" } }, "ssa": { diff --git a/src/aura/jsRewrite/network/appearance/switchUsbInsertPromptBtn.js b/src/aura/jsRewrite/network/appearance/switchUsbInsertPromptBtn.js new file mode 100644 index 0000000..f266300 --- /dev/null +++ b/src/aura/jsRewrite/network/appearance/switchUsbInsertPromptBtn.js @@ -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, +}; diff --git a/src/aura/ui/pages/configSubPages/disableLimitations/settings/uxAppearance.js b/src/aura/ui/pages/configSubPages/disableLimitations/settings/uxAppearance.js index 9126ce9..463bb0a 100644 --- a/src/aura/ui/pages/configSubPages/disableLimitations/settings/uxAppearance.js +++ b/src/aura/ui/pages/configSubPages/disableLimitations/settings/uxAppearance.js @@ -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 };