From 5e1d2db8ce1d7df3b5f126fd1e2348910159f743 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Wed, 11 Sep 2024 23:59:56 +0800 Subject: [PATCH] support global override --- changelog.md | 9 +- src/main/core/factory.ts | 7 +- .../components/override/edit-info-modal.tsx | 12 ++- .../src/components/override/override-item.tsx | 93 ++++++++++--------- .../components/profiles/edit-info-modal.tsx | 30 ++++-- src/shared/types.d.ts | 1 + 6 files changed, 93 insertions(+), 59 deletions(-) diff --git a/changelog.md b/changelog.md index ba33b4a..3994f40 100644 --- a/changelog.md +++ b/changelog.md @@ -4,9 +4,6 @@ ### New Features -- 支持自动开启轻量模式 - -### Bug Fixes - -- 修复日志等级为静默时无法正常启动的问题 -- 修复后台运行时的内存泄漏问题 +- 代理组图标支持SVG格式 +- 优化覆写启用逻辑 +- 覆写支持全局启用 diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index a7c1bde..9d7b90f 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -4,7 +4,8 @@ import { getProfile, getProfileItem, getOverride, - getOverrideItem + getOverrideItem, + getOverrideConfig } from '../config' import { mihomoWorkConfigPath, overridePath } from '../utils/dirs' import yaml from 'yaml' @@ -32,8 +33,10 @@ async function overrideProfile( current: string | undefined, profile: IMihomoConfig ): Promise { + const { items = [] } = (await getOverrideConfig()) || {} + const globalOverride = items.filter((item) => item.global).map((item) => item.id) const { override = [] } = (await getProfileItem(current)) || {} - for (const ov of override) { + for (const ov of globalOverride.concat(override)) { const item = await getOverrideItem(ov) const content = await getOverride(ov, item?.ext || 'js') switch (item?.ext) { diff --git a/src/renderer/src/components/override/edit-info-modal.tsx b/src/renderer/src/components/override/edit-info-modal.tsx index 20dc346..ba9a5e4 100644 --- a/src/renderer/src/components/override/edit-info-modal.tsx +++ b/src/renderer/src/components/override/edit-info-modal.tsx @@ -5,7 +5,8 @@ import { ModalBody, ModalFooter, Button, - Input + Input, + Switch } from '@nextui-org/react' import React, { useState } from 'react' import SettingItem from '../base/base-setting-item' @@ -57,6 +58,15 @@ const EditInfoModal: React.FC = (props) => { /> )} + + { + setValues({ ...values, global: v }) + }} + /> + + + ) + })} {values.override?.map((i) => { if (!overrideItems.find((t) => t.id === i)) return null + if (overrideItems.find((t) => t.id === i)?.global) return null return (