default prepend rules and proxies

This commit is contained in:
pompurin404 2024-08-17 21:53:03 +08:00
parent 5b5cbd8130
commit 5b7958f2c7
No known key found for this signature in database
3 changed files with 17 additions and 3 deletions

View File

@ -31,9 +31,20 @@ async function overrideProfile(
case 'js':
profile = runOverrideScript(profile, content)
break
case 'yaml':
profile = deepMerge(profile, yaml.parse(content))
case 'yaml': {
const patch = yaml.parse(content)
if (patch.rules) {
patch.rules = [...patch.rules, ...(profile.rules || [])]
}
if (patch.proxies) {
patch.proxies = [...patch.proxies, ...(profile.proxies || [])]
}
if (patch['proxy-groups']) {
patch['proxy-groups'] = [...patch['proxy-groups'], ...(profile['proxy-groups'] || [])]
}
profile = deepMerge(profile, patch)
break
}
}
}
return profile

View File

@ -1,7 +1,7 @@
import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from '@nextui-org/react'
import React, { useEffect, useState } from 'react'
import { BaseEditor } from '../base/base-editor'
import { getOverride, setOverride } from '@renderer/utils/ipc'
import { getOverride, restartCore, setOverride } from '@renderer/utils/ipc'
interface Props {
id: string
language: 'javascript' | 'yaml'
@ -47,6 +47,7 @@ const EditFileModal: React.FC<Props> = (props) => {
color="primary"
onPress={async () => {
await setOverride(id, language === 'javascript' ? 'js' : 'yaml', currData)
await restartCore()
onClose()
}}
>

View File

@ -14,6 +14,7 @@ import React, { useState } from 'react'
import SettingItem from '../base/base-setting-item'
import dayjs from 'dayjs'
import { useOverrideConfig } from '@renderer/hooks/use-override-config'
import { restartCore } from '@renderer/utils/ipc'
interface Props {
item: IProfileItem
updateProfileItem: (item: IProfileItem) => Promise<void>
@ -27,6 +28,7 @@ const EditInfoModal: React.FC<Props> = (props) => {
const onSave = async (): Promise<void> => {
await updateProfileItem(values)
await restartCore()
onClose()
}