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': case 'js':
profile = runOverrideScript(profile, content) profile = runOverrideScript(profile, content)
break break
case 'yaml': case 'yaml': {
profile = deepMerge(profile, yaml.parse(content)) 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 break
}
} }
} }
return profile return profile

View File

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

View File

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