feat(proxy): hideUnAvailableProxies, closes #200

This commit is contained in:
kunish 2023-09-15 23:56:14 +08:00
parent d77626058a
commit 9e556d959e
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
6 changed files with 56 additions and 8 deletions

View File

@ -4,10 +4,12 @@ import { ConfigTitle } from '~/components'
import { MODAL, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants' import { MODAL, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants'
import { import {
autoCloseConns, autoCloseConns,
hideUnAvailableProxies,
latencyTestTimeoutDuration, latencyTestTimeoutDuration,
proxiesOrderingType, proxiesOrderingType,
proxiesPreviewType, proxiesPreviewType,
setAutoCloseConns, setAutoCloseConns,
setHideUnAvailableProxies,
setLatencyTestTimeoutDuration, setLatencyTestTimeoutDuration,
setProxiesOrderingType, setProxiesOrderingType,
setProxiesPreviewType, setProxiesPreviewType,
@ -82,6 +84,19 @@ export const ProxiesSettingsModal = () => {
</select> </select>
</div> </div>
<div>
<ConfigTitle withDivider>{t('hideUnAvailableProxies')}</ConfigTitle>
<div class="flex w-full justify-center">
<input
class="toggle"
type="checkbox"
checked={hideUnAvailableProxies()}
onChange={(e) => setHideUnAvailableProxies(e.target.checked)}
/>
</div>
</div>
<div> <div>
<ConfigTitle withDivider>{t('proxiesPreviewType')}</ConfigTitle> <ConfigTitle withDivider>{t('proxiesPreviewType')}</ConfigTitle>

View File

@ -78,3 +78,14 @@ export const sortProxiesByOrderingType = (
} }
}) })
} }
export const filterProxiesByAvailability = (
proxyNames: string[],
proxyLatencyMap: Record<string, number>,
enabled?: boolean,
) =>
enabled
? proxyNames.filter(
(name) => proxyLatencyMap[name] !== latencyQualityMap().NOT_CONNECTED,
)
: proxyNames

View File

@ -86,4 +86,5 @@ export default {
active: 'Active', active: 'Active',
closed: 'Closed', closed: 'Closed',
sort: 'Sort', sort: 'Sort',
hideUnAvailableProxies: 'Hide UnAvailable Proxies',
} }

View File

@ -86,4 +86,5 @@ export default {
active: '活动', active: '活动',
closed: '已关闭', closed: '已关闭',
sort: '排序', sort: '排序',
hideUnAvailableProxies: '隐藏不可用节点',
} }

View File

@ -17,11 +17,16 @@ import {
} from '~/components' } from '~/components'
import { MODAL } from '~/constants' import { MODAL } from '~/constants'
import { import {
filterProxiesByAvailability,
formatTimeFromNow, formatTimeFromNow,
sortProxiesByOrderingType, sortProxiesByOrderingType,
useStringBooleanMap, useStringBooleanMap,
} from '~/helpers' } from '~/helpers'
import { proxiesOrderingType, useProxies } from '~/signals' import {
hideUnAvailableProxies,
proxiesOrderingType,
useProxies,
} from '~/signals'
import type { Proxy } from '~/types' import type { Proxy } from '~/types'
enum ActiveTab { enum ActiveTab {
@ -99,7 +104,7 @@ export default () => {
<div class="flex h-full flex-col gap-2"> <div class="flex h-full flex-col gap-2">
<Show when={proxyProviders().length > 0}> <Show when={proxyProviders().length > 0}>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<div class="tabs tabs-boxed gap-2"> <div class="tabs-boxed tabs gap-2">
<For each={tabs()}> <For each={tabs()}>
{(tab) => ( {(tab) => (
<button <button
@ -151,10 +156,14 @@ export default () => {
<Show when={activeTab() === ActiveTab.proxyProviders}> <Show when={activeTab() === ActiveTab.proxyProviders}>
<ForTwoColumns <ForTwoColumns
subChild={proxyProviders().map((proxyProvider) => { subChild={proxyProviders().map((proxyProvider) => {
const sortedProxyNames = sortProxiesByOrderingType( const sortedProxyNames = filterProxiesByAvailability(
sortProxiesByOrderingType(
proxyProvider.proxies.map((i) => i.name) ?? [], proxyProvider.proxies.map((i) => i.name) ?? [],
latencyMap(), latencyMap(),
proxiesOrderingType(), proxiesOrderingType(),
),
latencyMap(),
hideUnAvailableProxies(),
) )
const title = ( const title = (
@ -232,10 +241,14 @@ export default () => {
<Show when={activeTab() === ActiveTab.proxies}> <Show when={activeTab() === ActiveTab.proxies}>
<ForTwoColumns <ForTwoColumns
subChild={proxies().map((proxy) => { subChild={proxies().map((proxy) => {
const sortedProxyNames = sortProxiesByOrderingType( const sortedProxyNames = filterProxiesByAvailability(
sortProxiesByOrderingType(
proxy.all ?? [], proxy.all ?? [],
latencyMap(), latencyMap(),
proxiesOrderingType(), proxiesOrderingType(),
),
latencyMap(),
hideUnAvailableProxies(),
) )
const title = ( const title = (

View File

@ -20,6 +20,13 @@ export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted(
createSignal(PROXIES_ORDERING_TYPE.NATURAL), createSignal(PROXIES_ORDERING_TYPE.NATURAL),
{ name: 'proxiesOrderingType', storage: localStorage }, { name: 'proxiesOrderingType', storage: localStorage },
) )
export const [hideUnAvailableProxies, setHideUnAvailableProxies] =
makePersisted(createSignal(false), {
name: 'hideUnAvailableProxies',
storage: localStorage,
})
export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted( export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
createSignal('https://www.gstatic.com/generate_204'), createSignal('https://www.gstatic.com/generate_204'),
{ name: 'urlForLatencyTest', storage: localStorage }, { name: 'urlForLatencyTest', storage: localStorage },