|
1 | 1 | import { ClashConfig, RuleItem, Subscribe } from '$ui/define'
|
2 |
| -import { ProxyGroupType } from '$ui/define/ClashConfig' |
| 2 | +import { ProxyGroupType, ProxyGroupTypeConfig } from '$ui/define/ClashConfig' |
3 | 3 | import { YAML, pmap } from '$ui/libs'
|
4 | 4 | import { rootActions, rootState } from '$ui/store'
|
5 | 5 | import fse from 'fs-extra'
|
@@ -51,8 +51,14 @@ export function getUsingItems() {
|
51 | 51 | }
|
52 | 52 |
|
53 | 53 | 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 |
56 | 62 | const { subscribeItems, ruleItems } = getUsingItems()
|
57 | 63 |
|
58 | 64 | // the config
|
@@ -144,23 +150,41 @@ export async function genConfig({ forceUpdate = false }: { forceUpdate?: boolean
|
144 | 150 | const subscribeTragets = subscribeItems.map((sub) => sub.name)
|
145 | 151 |
|
146 | 152 | 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 | + |
147 | 171 | const withSuffix = [
|
148 | 172 | {
|
149 |
| - name: `${label}-最快`, |
150 |
| - type: ProxyGroupType.URLTest, |
| 173 | + name: getName(label, ProxyGroupType.UrlTest), |
| 174 | + type: ProxyGroupType.UrlTest, |
151 | 175 | proxies,
|
152 | 176 | url: 'http://www.gstatic.com/generate_204',
|
153 | 177 | interval: 150,
|
154 | 178 | },
|
155 | 179 | {
|
156 |
| - name: `${label}-可用`, |
| 180 | + name: getName(label, ProxyGroupType.Fallback), |
157 | 181 | type: ProxyGroupType.Fallback,
|
158 | 182 | proxies,
|
159 | 183 | url: 'http://www.gstatic.com/generate_204',
|
160 | 184 | interval: 150,
|
161 | 185 | },
|
162 | 186 | {
|
163 |
| - name: `${label}-手选`, |
| 187 | + name: getName(label, ProxyGroupType.Select), |
164 | 188 | type: ProxyGroupType.Select,
|
165 | 189 | proxies,
|
166 | 190 | },
|
|
0 commit comments