import { Tabs, Tab } from '@heroui/react' import { useAppConfig } from '@renderer/hooks/use-app-config' import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config' import { useGroups } from '@renderer/hooks/use-groups' import { mihomoCloseAllConnections, patchMihomoConfig, updateTrayIcon } from '@renderer/utils/ipc' import { Key } from 'react' import { useTranslation } from 'react-i18next' interface Props { iconOnly?: boolean expanded?: boolean } const OutboundModeSwitcher: React.FC = ({ iconOnly, expanded = false }: Props) => { const { t } = useTranslation() const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() const { mutate: mutateGroups } = useGroups() const { appConfig } = useAppConfig() const { autoCloseConnection = true, disableAnimations = false } = appConfig || {} const { mode } = controledMihomoConfig || {} const onChangeMode = async (mode: OutboundMode): Promise => { await patchControledMihomoConfig({ mode }) await patchMihomoConfig({ mode }) if (autoCloseConnection) { await mihomoCloseAllConnections() } mutateGroups() window.electron.ipcRenderer.send('updateTrayMenu') await updateTrayIcon() } if (!mode) return null if (iconOnly) { return ( onChangeMode(key as OutboundMode)} > {(['rule', 'global', 'direct'] as const).map((value) => ( {value[0].toUpperCase()} {t(`sider.cards.outbound.${value}`)} } /> ))} ) } return ( onChangeMode(key as OutboundMode)} > ) } export default OutboundModeSwitcher