use delete to unfixed proxy

This commit is contained in:
pompurin404 2024-09-27 21:38:09 +08:00
parent 91395d4b31
commit 09815f9614
No known key found for this signature in database
4 changed files with 12 additions and 6 deletions

View File

@ -149,6 +149,10 @@ export const mihomoChangeProxy = async (group: string, proxy: string): Promise<I
return await mihomoHttp('PUT', `/proxies/${encodeURIComponent(group)}`, { name: proxy })
}
export const mihomoUnfixedProxy = async (group: string): Promise<void> => {
return await mihomoHttp('DELETE', `/proxies/${encodeURIComponent(group)}`)
}
export const mihomoUpgradeGeo = async (): Promise<void> => {
return await mihomoHttp('POST', '/configs/geo')
}

View File

@ -10,6 +10,7 @@ import {
mihomoProxyProviders,
mihomoRuleProviders,
mihomoRules,
mihomoUnfixedProxy,
mihomoUpdateProxyProviders,
mihomoUpdateRuleProviders,
mihomoUpgrade,
@ -120,6 +121,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('mihomoChangeProxy', (_e, group, proxy) =>
ipcErrorWrapper(mihomoChangeProxy)(group, proxy)
)
ipcMain.handle('mihomoUnfixedProxy', (_e, group) => ipcErrorWrapper(mihomoUnfixedProxy)(group))
ipcMain.handle('mihomoUpgradeGeo', ipcErrorWrapper(mihomoUpgradeGeo))
ipcMain.handle('mihomoUpgrade', ipcErrorWrapper(mihomoUpgrade))
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) =>

View File

@ -1,5 +1,5 @@
import { Button, Card, CardBody } from '@nextui-org/react'
import { mihomoGroupDelay } from '@renderer/utils/ipc'
import { mihomoUnfixedProxy } from '@renderer/utils/ipc'
import React, { useMemo, useState } from 'react'
import { FaMapPin } from 'react-icons/fa6'
@ -24,7 +24,6 @@ const ProxyItem: React.FC<Props> = (props) => {
}, [proxy])
const [loading, setLoading] = useState(false)
const [unfixing, setUnfixing] = useState(false)
function delayColor(delay: number): 'primary' | 'success' | 'warning' | 'danger' {
if (delay === -1) return 'primary'
if (delay === 0) return 'danger'
@ -74,13 +73,10 @@ const ProxyItem: React.FC<Props> = (props) => {
<Button
isIconOnly
title="取消固定"
isLoading={unfixing}
color="danger"
onPress={async () => {
setUnfixing(true)
await mihomoGroupDelay(group.name)
await mihomoUnfixedProxy(group.name)
mutateProxies()
setUnfixing(false)
}}
variant="light"
className="h-[20px] p-0 text-sm"

View File

@ -59,6 +59,10 @@ export async function mihomoChangeProxy(group: string, proxy: string): Promise<I
)
}
export async function mihomoUnfixedProxy(group: string): Promise<IMihomoProxy> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUnfixedProxy', group))
}
export async function mihomoUpgradeGeo(): Promise<void> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUpgradeGeo'))
}