Skip to content

Commit

Permalink
Inline support
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Jan 2, 2025
1 parent 8fe1f4f commit 8e6b5b5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 30 deletions.
49 changes: 25 additions & 24 deletions src/renderer/src/components/resources/proxy-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const ProxyProvider: React.FC = () => {
show: false,
path: '',
type: '',
title: ''
title: '',
privderType: ''
})
useEffect(() => {
if (showDetails.title) {
Expand Down Expand Up @@ -104,7 +105,8 @@ const ProxyProvider: React.FC = () => {
path={showDetails.path}
type={showDetails.type}
title={showDetails.title}
onClose={() => setShowDetails({ show: false, path: '', type: '', title: '' })}
privderType={showDetails.privderType}
onClose={() => setShowDetails({ show: false, path: '', type: '', title: '', privderType: '' })}
/>
)}
<SettingItem title="代理集合" divider>
Expand Down Expand Up @@ -136,28 +138,27 @@ const ProxyProvider: React.FC = () => {
{/* <Button isIconOnly className="ml-2" size="sm">
<IoMdEye className="text-lg" />
</Button> */}
{provider.vehicleType !== 'Inline' && (
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
className="ml-2"
size="sm"
onPress={() => {
setShowDetails({
show: false,
path: provider.name,
type: provider.vehicleType,
title: provider.name
})
}}
>
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
)}
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
className="ml-2"
size="sm"
onPress={() => {
setShowDetails({
show: false,
privderType: 'proxy-providers',
path: provider.name,
type: provider.vehicleType,
title: provider.name
})
}}
>
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
<Button
isIconOnly
title="更新"
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/src/components/resources/rule-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const RuleProvider: React.FC = () => {
path: '',
type: '',
title: '',
format: ''
format: '',
privderType: ''
})
useEffect(() => {
if (showDetails.title) {
Expand Down Expand Up @@ -89,7 +90,8 @@ const RuleProvider: React.FC = () => {
type={showDetails.type}
title={showDetails.title}
format={showDetails.format}
onClose={() => setShowDetails({ show: false, path: '', type: '', title: '', format: '' })}
privderType={showDetails.privderType}
onClose={() => setShowDetails({ show: false, path: '', type: '', title: '', format: '', privderType: '' })}
/>
)}
<SettingItem title="规则集合" divider>
Expand Down Expand Up @@ -117,7 +119,7 @@ const RuleProvider: React.FC = () => {
>
<div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div>
{provider.format !== 'MrsRule' && provider.vehicleType !== 'Inline' && (
{provider.format !== 'MrsRule' && (
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
Expand All @@ -126,6 +128,7 @@ const RuleProvider: React.FC = () => {
onPress={() => {
setShowDetails({
show: false,
privderType: 'rule-providers',
path: provider.name,
type: provider.vehicleType,
title: provider.name,
Expand Down
28 changes: 25 additions & 3 deletions src/renderer/src/components/resources/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,44 @@ import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from
import React, { useEffect, useState } from 'react'
import { BaseEditor } from '../base/base-editor'
import { getFileStr, setFileStr } from '@renderer/utils/ipc'
import yaml from 'js-yaml'
type Language = 'yaml' | 'javascript' | 'css' | 'json' | 'text'

interface Props {
onClose: () => void
path: string
type: string
title: string
privderType: string
format?: string
}
const Viewer: React.FC<Props> = (props) => {
const { type, path, title, format, onClose } = props
const { type, path, title, format, privderType, onClose } = props
const [currData, setCurrData] = useState('')
const language: Language = !format || format === 'YamlRule' ? 'yaml' : 'text'
let language: Language = !format || format === 'YamlRule' ? 'yaml' : 'text'

const getContent = async (): Promise<void> => {
setCurrData(await getFileStr(path))
let fileContent: React.SetStateAction<string>
if (type === 'Inline') {
fileContent = await getFileStr('config.yaml')
language = 'yaml'
} else {
fileContent = await getFileStr(path)
}
try {
const parsedYaml = yaml.load(fileContent)
if (privderType === 'proxy-providers') {
setCurrData(yaml.dump({
'proxies': parsedYaml[privderType][title].payload
}))
} else {
setCurrData(yaml.dump({
'rules': parsedYaml[privderType][title].payload
}))
}
} catch (error) {
setCurrData(fileContent)
}
}

useEffect(() => {
Expand Down

0 comments on commit 8e6b5b5

Please sign in to comment.