Skip to content

Commit

Permalink
feat: proxy group hide & config for automatic disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Dec 1, 2024
1 parent 0d09a78 commit 8b48f45
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/components/proxies/ProxyGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div class="collapse collapse-arrow bg-base-100 shadow-lg">
<div class="collapse-title">
<div class="flex items-center gap-2">
<img
v-if="proxyGroup.icon"
class="w-5"
:src="proxyGroup.icon"
/>
<div class="text-lg font-medium sm:text-xl">
<div class="flex items-center gap-1 text-lg font-medium sm:text-xl">
<img
v-if="proxyGroup.icon"
class="w-5"
:src="proxyGroup.icon"
/>
{{ proxyGroup.name }}
</div>
<div class="text-xs sm:text-sm">
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SpeedCharts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<script setup lang="ts">
import { prettyBytesHelper } from '@/helper'
import { downloadSpeedHistory, uploadSpeedHistory } from '@/store/statistics.ts'
import { downloadSpeedHistory, uploadSpeedHistory } from '@/store/statistics'
import { useElementSize } from '@vueuse/core'
import * as echarts from 'echarts'
import { debounce } from 'lodash'
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
latencydesc: 'Latency Desc',
latencyasc: 'Latency Asc',
language: 'Language',
automaticDisconnection: 'Automatic Disconnection',
[LANG.EN_US]: 'English',
[LANG.ZH_CN]: '中文',
}
1 change: 1 addition & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
latencydesc: '按延迟降序',
latencyasc: '按延迟升序',
language: '语言',
automaticDisconnection: '自动断开连接',
[LANG.EN_US]: 'English',
[LANG.ZH_CN]: '中文',
}
1 change: 1 addition & 0 deletions src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const proxySortType = useStorage<PROXY_SORT_TYPE>(
PROXY_SORT_TYPE.DEFAULT,
)
export const proxiesTabShow = ref(PROXY_TAB_TYPE.PROXIES)
export const automaticDisconnection = useStorage('config/automatic-disconnection', true)

// connections
export const useConnectionCard = useStorage('config/use-connecticon-card', false)
Expand Down
13 changes: 8 additions & 5 deletions src/store/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import type { Proxy, ProxyProvider } from '@/types'
import { last } from 'lodash'
import { ref } from 'vue'
import { speedtestTimeout, speedtestUrl } from './config'
import { automaticDisconnection, speedtestTimeout, speedtestUrl } from './config'
import { activeConnections } from './connections'

export const GLOBAL = 'GLOBAL'
Expand All @@ -29,7 +29,7 @@ export const fetchProxies = async () => {

proxyMap.value = proxyData.proxies
proxyGroupList.value = Object.values(proxyData.proxies)
.filter((proxy) => proxy.all?.length && proxy.name !== GLOBAL)
.filter((proxy) => proxy.all?.length && proxy.name !== GLOBAL && !proxy?.hide)
.sort((prev, next) => sortIndex.indexOf(prev.name) - sortIndex.indexOf(next.name))
.map((proxy) => proxy.name)

Expand All @@ -44,9 +44,12 @@ export const fetchProxies = async () => {
export const selectProxy = async (proxyGroup: string, name: string) => {
await selectProxyAPI(proxyGroup, name)
proxyMap.value[proxyGroup].now = name
activeConnections.value
.filter((c) => c.chains.includes(proxyGroup))
.forEach((c) => disconnectByIdAPI(c.id))

if (automaticDisconnection.value) {
activeConnections.value
.filter((c) => c.chains.includes(proxyGroup))
.forEach((c) => disconnectByIdAPI(c.id))
}
}

export const proxyLatencyTest = async (proxyName: string) => {
Expand Down
6 changes: 2 additions & 4 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export type Proxy = {
udp: boolean
now: string
icon: string
}

export type ProxyGroup = Proxy & {
all: string[]
hide?: boolean
all?: string[]
}

export type SubscriptionInfo = {
Expand Down
9 changes: 9 additions & 0 deletions src/views/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
{{ $t('proxies') }}
</div>
<div class="card-body">
<div class="flex items-center gap-2">
{{ $t('automaticDisconnection') }}:
<input
class="toggle"
type="checkbox"
v-model="automaticDisconnection"
/>
</div>
<div class="flex items-center gap-2">
{{ $t('showGlobalProxy') }}:
<input
Expand Down Expand Up @@ -148,6 +156,7 @@ import BackendSwitch from '@/components/settings/BackendSwitch.vue'
import { LANG } from '@/config'
import { i18n } from '@/i18n'
import {
automaticDisconnection,
compactConnectionCard,
language,
showGlobalProxy,
Expand Down

0 comments on commit 8b48f45

Please sign in to comment.