Skip to content

Commit b60f3ea

Browse files
committed
feat: add new option generatedGroupNameEmoji & generatedGroupNameLang
1 parent c9bdf06 commit b60f3ea

File tree

6 files changed

+125
-9
lines changed

6 files changed

+125
-9
lines changed

packages/ui/src/common/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ export const getAssetsDir = reusePromise(
2727
},
2828
{ memorize: true },
2929
)
30+
31+
export const __DEV__ = import.meta.env.DEV
32+
export const __PROD__ = import.meta.env.PROD

packages/ui/src/define/ClashConfig.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,38 @@ export interface ProxyGroup {
5050
}
5151

5252
export enum ProxyGroupType {
53+
UrlTest = 'url-test',
5354
Fallback = 'fallback',
5455
Select = 'select',
55-
URLTest = 'url-test',
56+
}
57+
58+
/**
59+
// 最快 / 可用 / 手选
60+
// Fastest / Available / Select
61+
generatedGroupNameLocale: 'zh-CN', // possible: zh-CN | en-US
62+
63+
// 🚀 ✅ ✋🏻
64+
generatedGroupNameEmoji: true,
65+
*/
66+
export const ProxyGroupTypeConfig: Record<
67+
ProxyGroupType,
68+
{ emoji: string; nameZh: string; nameEn: string }
69+
> = {
70+
[ProxyGroupType.UrlTest]: {
71+
emoji: '🚀',
72+
nameZh: '最快',
73+
nameEn: 'Fastest',
74+
},
75+
[ProxyGroupType.Fallback]: {
76+
emoji: '✅',
77+
nameZh: '可用',
78+
nameEn: 'Available',
79+
},
80+
[ProxyGroupType.Select]: {
81+
emoji: '✋',
82+
nameZh: '手选',
83+
nameEn: 'Select',
84+
},
5685
}
5786

5887
export interface ProxyProviders {

packages/ui/src/modules/current-config/index.tsx

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ProxyGroupTypeConfig } from '$ui/define/ClashConfig'
12
import { runGenerate } from '$ui/modules/commands/run'
23
import { message } from '$ui/store'
34
import { DEFAULT_NAME, getConfigFile, getConfigFileDisplay } from '$ui/utility/gen'
@@ -11,7 +12,14 @@ import styles from './index.module.less'
1112
import { state } from './model'
1213

1314
export default function ConfigList() {
14-
const { name, clashMeta, generateAllProxyGroup, generateSubNameProxyGroup } = useSnapshot(state)
15+
const {
16+
name,
17+
clashMeta,
18+
generateAllProxyGroup,
19+
generateSubNameProxyGroup,
20+
generatedGroupNameEmoji,
21+
generatedGroupNameLang,
22+
} = useSnapshot(state)
1523

1624
const onGenConfigClick = useMemoizedFn(async () => {
1725
return runGenerate()
@@ -128,6 +136,39 @@ export default function ConfigList() {
128136
>
129137
生成 <Tag style={{ marginRight: 0 }}>订阅名同名</Tag>
130138
</Checkbox>
139+
140+
<Checkbox
141+
checked={generatedGroupNameEmoji}
142+
onChange={(e) => {
143+
state.generatedGroupNameEmoji = e.target.checked
144+
}}
145+
>
146+
<Tag style={{ marginRight: 0 }}>订阅组</Tag> emoji
147+
</Checkbox>
148+
149+
<Checkbox
150+
checked={generatedGroupNameLang === 'zh'}
151+
onChange={(e) => {
152+
const lang = e.target.checked ? 'zh' : 'en'
153+
state.generatedGroupNameLang = lang
154+
}}
155+
>
156+
<Tooltip
157+
overlayInnerStyle={{ width: 'max-content' }}
158+
title={
159+
<>
160+
✅ 使用中文: {ProxyGroupTypeConfig['url-test'].nameZh} /{' '}
161+
{ProxyGroupTypeConfig['fallback'].nameZh} /{' '}
162+
{ProxyGroupTypeConfig['select'].nameZh}
163+
<br />❎ 使用英文: {ProxyGroupTypeConfig['url-test'].nameEn} /{' '}
164+
{ProxyGroupTypeConfig['fallback'].nameEn} /{' '}
165+
{ProxyGroupTypeConfig['select'].nameEn}
166+
</>
167+
}
168+
>
169+
<Tag style={{ marginRight: 0 }}>订阅组</Tag> 中文
170+
</Tooltip>
171+
</Checkbox>
131172
</Space>
132173
</Row>
133174

packages/ui/src/modules/current-config/model.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { __DEV__ } from '$ui/common'
12
import { ConfigItem, RuleItem, Subscribe } from '$ui/define'
23
import { onInit, onReload } from '$ui/modules/global-model'
34
import storage from '$ui/storage'
@@ -12,6 +13,8 @@ interface IState {
1213
clashMeta: boolean
1314
generateAllProxyGroup: boolean
1415
generateSubNameProxyGroup: boolean
16+
generatedGroupNameLang: string
17+
generatedGroupNameEmoji: boolean
1518
}
1619

1720
const defaultState: IState = {
@@ -20,6 +23,8 @@ const defaultState: IState = {
2023
generateAllProxyGroup: false,
2124
generateSubNameProxyGroup: false,
2225
clashMeta: false,
26+
generatedGroupNameLang: 'zh',
27+
generatedGroupNameEmoji: true,
2328
}
2429

2530
const allowedKeys = Object.keys(defaultState)
@@ -34,6 +39,13 @@ const { state, load, init } = valtioState<IState>(
3439
}
3540
},
3641
persist(val) {
42+
if (__DEV__) {
43+
// hot-reload 之后都消失了
44+
if (!val.list.length) {
45+
return
46+
}
47+
}
48+
3749
storage.set(CURRENT_CONFIG_STORAGE_KEY, _.pick(val, allowedKeys))
3850
},
3951
},

packages/ui/src/storage/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const storage = new Store({
2424
name: 'clash-config-manager',
2525
generateAllProxyGroup: false,
2626
generateSubNameProxyGroup: false,
27+
28+
// 最快 / 可用 / ✋🏻手选
29+
// Fastest / Available / Select
30+
generatedGroupNameLang: 'zh', // possible: zh | en
31+
32+
// 🚀 ✅ ✋🏻
33+
generatedGroupNameEmoji: true,
2734
},
2835

2936
preference: {

packages/ui/src/utility/gen.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ClashConfig, RuleItem, Subscribe } from '$ui/define'
2-
import { ProxyGroupType } from '$ui/define/ClashConfig'
2+
import { ProxyGroupType, ProxyGroupTypeConfig } from '$ui/define/ClashConfig'
33
import { YAML, pmap } from '$ui/libs'
44
import { rootActions, rootState } from '$ui/store'
55
import fse from 'fs-extra'
@@ -51,8 +51,14 @@ export function getUsingItems() {
5151
}
5252

5353
export async function genConfig({ forceUpdate = false }: { forceUpdate?: boolean } = {}) {
54-
const { name, clashMeta, generateAllProxyGroup, generateSubNameProxyGroup } =
55-
rootState.currentConfig
54+
const {
55+
name,
56+
clashMeta,
57+
generateAllProxyGroup,
58+
generateSubNameProxyGroup,
59+
generatedGroupNameEmoji,
60+
generatedGroupNameLang,
61+
} = rootState.currentConfig
5662
const { subscribeItems, ruleItems } = getUsingItems()
5763

5864
// the config
@@ -144,23 +150,41 @@ export async function genConfig({ forceUpdate = false }: { forceUpdate?: boolean
144150
const subscribeTragets = subscribeItems.map((sub) => sub.name)
145151

146152
const genGroupsForSubscribe = (label: string, proxies: string[]) => {
153+
const getName = (label: string, type: ProxyGroupType) => {
154+
const emoji = generatedGroupNameEmoji ? ProxyGroupTypeConfig[type].emoji + ' ' : ''
155+
156+
type AllowedLang = 'zh' | 'en'
157+
const lang: AllowedLang = (() => {
158+
const _default = 'zh'
159+
const allowed: AllowedLang[] = ['zh', 'en']
160+
if (!generatedGroupNameLang) return _default
161+
if (!allowed.includes(generatedGroupNameLang)) return _default
162+
return generatedGroupNameLang as AllowedLang
163+
})()
164+
165+
const typeText =
166+
lang === 'zh' ? ProxyGroupTypeConfig[type].nameZh : ProxyGroupTypeConfig[type].nameEn
167+
168+
return `${emoji}${label} ${typeText}`
169+
}
170+
147171
const withSuffix = [
148172
{
149-
name: `${label}-最快`,
150-
type: ProxyGroupType.URLTest,
173+
name: getName(label, ProxyGroupType.UrlTest),
174+
type: ProxyGroupType.UrlTest,
151175
proxies,
152176
url: 'http://www.gstatic.com/generate_204',
153177
interval: 150,
154178
},
155179
{
156-
name: `${label}-可用`,
180+
name: getName(label, ProxyGroupType.Fallback),
157181
type: ProxyGroupType.Fallback,
158182
proxies,
159183
url: 'http://www.gstatic.com/generate_204',
160184
interval: 150,
161185
},
162186
{
163-
name: `${label}-手选`,
187+
name: getName(label, ProxyGroupType.Select),
164188
type: ProxyGroupType.Select,
165189
proxies,
166190
},

0 commit comments

Comments
 (0)