mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +08:00
feat(proxy): hideUnAvailableProxies, closes #200
This commit is contained in:
parent
d77626058a
commit
9e556d959e
@ -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>
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -86,4 +86,5 @@ export default {
|
|||||||
active: 'Active',
|
active: 'Active',
|
||||||
closed: 'Closed',
|
closed: 'Closed',
|
||||||
sort: 'Sort',
|
sort: 'Sort',
|
||||||
|
hideUnAvailableProxies: 'Hide UnAvailable Proxies',
|
||||||
}
|
}
|
||||||
|
@ -86,4 +86,5 @@ export default {
|
|||||||
active: '活动',
|
active: '活动',
|
||||||
closed: '已关闭',
|
closed: '已关闭',
|
||||||
sort: '排序',
|
sort: '排序',
|
||||||
|
hideUnAvailableProxies: '隐藏不可用节点',
|
||||||
}
|
}
|
||||||
|
@ -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(
|
||||||
proxyProvider.proxies.map((i) => i.name) ?? [],
|
sortProxiesByOrderingType(
|
||||||
|
proxyProvider.proxies.map((i) => i.name) ?? [],
|
||||||
|
latencyMap(),
|
||||||
|
proxiesOrderingType(),
|
||||||
|
),
|
||||||
latencyMap(),
|
latencyMap(),
|
||||||
proxiesOrderingType(),
|
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(
|
||||||
proxy.all ?? [],
|
sortProxiesByOrderingType(
|
||||||
|
proxy.all ?? [],
|
||||||
|
latencyMap(),
|
||||||
|
proxiesOrderingType(),
|
||||||
|
),
|
||||||
latencyMap(),
|
latencyMap(),
|
||||||
proxiesOrderingType(),
|
hideUnAvailableProxies(),
|
||||||
)
|
)
|
||||||
|
|
||||||
const title = (
|
const title = (
|
||||||
|
@ -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 },
|
||||||
|
Loading…
Reference in New Issue
Block a user