Skip to content

Commit

Permalink
feat: hide Global group for singbox
Browse files Browse the repository at this point in the history
  • Loading branch information
CHIZI-0618 committed Sep 8, 2024
1 parent f3d772c commit 4784540
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/store/proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ClashAPIConfig } from 'src/types';

import * as connAPI from '../api/connections';
import * as proxiesAPI from '../api/proxies';
import { fetchVersion } from 'src/api/version'; // 导入 fetchVersion
import { getAutoCloseOldConns, getLatencyTestUrl } from './app';

export const initialState: StateProxies = {
Expand Down Expand Up @@ -67,6 +68,8 @@ function mapLatency(names: string[], getProxy: (name: string) => { history: Late

export function fetchProxies(apiConfig: ClashAPIConfig) {
return async (dispatch: any, getState: any) => {
const { meta, premium } = await fetchVersion('/version', apiConfig);

const [proxiesData, providersData] = await Promise.all([
proxiesAPI.fetchProxies(apiConfig),
proxiesAPI.fetchProviderProxies(apiConfig),
Expand All @@ -75,7 +78,7 @@ export function fetchProxies(apiConfig: ClashAPIConfig) {
const { proxyProviders, providerProxyRecord } = formatProxyProviders(providersData.providers);

const proxies = { ...providerProxyRecord, ...proxiesData.proxies };
const [groupNames, proxyNames] = retrieveGroupNamesFrom(proxies);
const [groupNames, proxyNames] = retrieveGroupNamesFrom(proxies, { meta, premium });

const delayNext = {
...getDelay(getState()),
Expand Down Expand Up @@ -357,13 +360,19 @@ export function requestDelayAll(apiConfig: ClashAPIConfig) {
};
}

function retrieveGroupNamesFrom(proxies: Record<string, ProxyItem>) {
function retrieveGroupNamesFrom(
proxies: Record<string, ProxyItem>,
version: { meta: boolean; premium: boolean }
) {
let groupNames = [];
let globalAll: string[];
const proxyNames = [];
for (const prop in proxies) {
const p = proxies[prop];
if (p.all && Array.isArray(p.all)) {
if (prop === 'GLOBAL' && version.meta && version.premium) {
continue;
}
groupNames.push(prop);
if (prop === 'GLOBAL') {
globalAll = Array.from(p.all);
Expand Down

0 comments on commit 4784540

Please sign in to comment.