Skip to content

Commit feb9592

Browse files
committed
refactor(settings): extract GeneralSettings into modular subcomponents
1 parent f0b3f5d commit feb9592

35 files changed

+526
-604
lines changed

frontend/src/constant/app.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
PluginTrigger,
55
RequestMethod,
66
ScheduledTasksType,
7+
Theme,
78
View,
9+
WebviewGpuPolicy,
10+
WindowStartState,
811
} from '@/enums/app'
912

1013
export const LocalesFilePath = 'data/locales'
@@ -78,6 +81,63 @@ export const RequestMethodOptions = [
7881
{ label: RequestMethod.Patch, value: RequestMethod.Patch },
7982
]
8083

84+
export const ThemeOptions = [
85+
{
86+
label: 'settings.theme.dark',
87+
value: Theme.Dark,
88+
},
89+
{
90+
label: 'settings.theme.light',
91+
value: Theme.Light,
92+
},
93+
{
94+
label: 'settings.theme.auto',
95+
value: Theme.Auto,
96+
},
97+
]
98+
99+
export const ColorOptions = [
100+
{
101+
label: 'settings.color.default',
102+
value: Color.Default,
103+
},
104+
{
105+
label: 'settings.color.orange',
106+
value: Color.Orange,
107+
},
108+
{
109+
label: 'settings.color.pink',
110+
value: Color.Pink,
111+
},
112+
{
113+
label: 'settings.color.red',
114+
value: Color.Red,
115+
},
116+
{
117+
label: 'settings.color.skyblue',
118+
value: Color.Skyblue,
119+
},
120+
{
121+
label: 'settings.color.green',
122+
value: Color.Green,
123+
},
124+
{
125+
label: 'settings.color.purple',
126+
value: Color.Purple,
127+
},
128+
]
129+
130+
export const WindowStateOptions = [
131+
{ label: 'settings.windowState.normal', value: WindowStartState.Normal },
132+
{ label: 'settings.windowState.minimised', value: WindowStartState.Minimised },
133+
]
134+
135+
export const WebviewGpuPolicyOptions = [
136+
{ label: 'settings.webviewGpuPolicy.always', value: WebviewGpuPolicy.Always },
137+
{ label: 'settings.webviewGpuPolicy.onDemand', value: WebviewGpuPolicy.OnDemand },
138+
{ label: 'settings.webviewGpuPolicy.never', value: WebviewGpuPolicy.Never },
139+
]
140+
81141
// vue-draggable-plus config
82142
export const DraggableOptions = {
83143
animation: 150,

frontend/src/constant/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/src/stores/kernelApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed, ref, watch } from 'vue'
33

44
import { getConfigs, setConfigs, getProxies, Api } from '@/api/kernel'
55
import { ProcessInfo, KillProcess, ExecBackground, ReadFile, WriteFile, RemoveFile } from '@/bridge'
6-
import { CorePidFilePath, CoreStopOutputKeyword, CoreWorkingDirectory } from '@/constant'
6+
import { CorePidFilePath, CoreStopOutputKeyword, CoreWorkingDirectory } from '@/constant/kernel'
77
import { Branch } from '@/enums/app'
88
import { RuleType } from '@/enums/kernel'
99
import {

frontend/src/stores/profiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed, ref } from 'vue'
33
import { parse } from 'yaml'
44

55
import { ReadFile, WriteFile } from '@/bridge'
6-
import { ProfilesFilePath } from '@/constant'
6+
import { ProfilesFilePath } from '@/constant/app'
77
import * as Defaults from '@/constant/profile'
88
import { ProxyGroup, RulesetBehavior, RulesetFormat, RuleType } from '@/enums/kernel'
99
import { useAppSettingsStore } from '@/stores'

frontend/src/stores/rulesets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { ref } from 'vue'
33
import { parse } from 'yaml'
44

55
import { CopyFile, ReadFile, WriteFile, HttpGet, Download } from '@/bridge'
6-
import { RulesetsFilePath, EmptyRuleSet, RulesetHubFilePath } from '@/constant'
6+
import { RulesetsFilePath, RulesetHubFilePath } from '@/constant/app'
7+
import { EmptyRuleSet } from '@/constant/kernel'
78
import { RulesetBehavior, RulesetFormat } from '@/enums/kernel'
89
import {
910
isValidPaylodYAML,

frontend/src/stores/subscribes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ref } from 'vue'
33
import { parse } from 'yaml'
44

55
import { ReadFile, WriteFile, Requests } from '@/bridge'
6-
import { DefaultSubscribeScript, SubscribesFilePath } from '@/constant'
6+
import { DefaultSubscribeScript, SubscribesFilePath } from '@/constant/app'
77
import { PluginTriggerEvent, RequestMethod } from '@/enums/app'
88
import { usePluginsStore, useProfilesStore } from '@/stores'
99
import {

frontend/src/utils/command.ts

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ExitApp, RestartApp, WindowReloadApp } from '@/bridge'
2-
import { Color, PluginTrigger, PluginTriggerEvent, Theme } from '@/enums/app'
3-
import { ClashMode } from '@/enums/kernel'
2+
import { ColorOptions, ThemeOptions } from '@/constant/app'
3+
import { ModeOptions } from '@/constant/kernel'
4+
import { PluginTrigger, PluginTriggerEvent } from '@/enums/app'
45
import useI18n from '@/lang'
56
import {
67
useAppSettingsStore,
@@ -92,23 +93,11 @@ export const getCommands = () => {
9293
{
9394
label: 'kernel.mode',
9495
cmd: 'Kernel Mode',
95-
children: [
96-
{
97-
label: 'kernel.global',
98-
cmd: 'Global',
99-
handler: () => handleChangeMode(ClashMode.Global),
100-
},
101-
{
102-
label: 'kernel.rule',
103-
cmd: 'Rule',
104-
handler: () => handleChangeMode(ClashMode.Rule),
105-
},
106-
{
107-
label: 'kernel.direct',
108-
cmd: 'Direct',
109-
handler: () => handleChangeMode(ClashMode.Direct),
110-
},
111-
],
96+
children: ModeOptions.map((mode) => ({
97+
label: mode.label,
98+
cmd: mode.value,
99+
handler: () => handleChangeMode(mode.value),
100+
})),
112101
},
113102
],
114103
},
@@ -154,64 +143,20 @@ export const getCommands = () => {
154143
{
155144
label: 'settings.theme.name',
156145
cmd: 'Theme',
157-
children: [
158-
{
159-
label: 'settings.theme.light',
160-
cmd: 'Light',
161-
handler: () => (appSettings.app.theme = Theme.Light),
162-
},
163-
{
164-
label: 'settings.theme.dark',
165-
cmd: 'Dark',
166-
handler: () => (appSettings.app.theme = Theme.Dark),
167-
},
168-
{
169-
label: 'settings.theme.auto',
170-
cmd: 'Auto',
171-
handler: () => (appSettings.app.theme = Theme.Auto),
172-
},
173-
],
146+
children: ThemeOptions.map((theme) => ({
147+
label: theme.label,
148+
cmd: theme.value,
149+
handler: () => (appSettings.app.theme = theme.value),
150+
})),
174151
},
175152
{
176153
label: 'settings.color.name',
177154
cmd: 'Color',
178-
children: [
179-
{
180-
label: 'settings.color.default',
181-
cmd: 'Default',
182-
handler: () => (appSettings.app.color = Color.Default),
183-
},
184-
{
185-
label: 'settings.color.orange',
186-
cmd: 'Orange',
187-
handler: () => (appSettings.app.color = Color.Orange),
188-
},
189-
{
190-
label: 'settings.color.pink',
191-
cmd: 'Pink',
192-
handler: () => (appSettings.app.color = Color.Pink),
193-
},
194-
{
195-
label: 'settings.color.red',
196-
cmd: 'Red',
197-
handler: () => (appSettings.app.color = Color.Red),
198-
},
199-
{
200-
label: 'settings.color.skyblue',
201-
cmd: 'Skyblue',
202-
handler: () => (appSettings.app.color = Color.Skyblue),
203-
},
204-
{
205-
label: 'settings.color.green',
206-
cmd: 'Green',
207-
handler: () => (appSettings.app.color = Color.Green),
208-
},
209-
{
210-
label: 'settings.color.purple',
211-
cmd: 'Purple',
212-
handler: () => (appSettings.app.color = Color.Purple),
213-
},
214-
],
155+
children: ColorOptions.map((color) => ({
156+
label: color.label,
157+
cmd: color.value,
158+
handler: () => (appSettings.app.color = color.value),
159+
})),
215160
},
216161
{
217162
label: 'titlebar.reload',

frontend/src/utils/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse } from 'yaml'
22

33
import { deleteConnection, getConnections, useProxy } from '@/api/kernel'
44
import { AbsolutePath, Exec, ExitApp, ReadFile, WriteFile } from '@/bridge'
5-
import { CoreWorkingDirectory } from '@/constant'
5+
import { CoreWorkingDirectory } from '@/constant/kernel'
66
import { ProxyGroupType, RulesetBehavior, RulesetFormat } from '@/enums/kernel'
77
import i18n from '@/lang'
88
import {

frontend/src/utils/restorer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { stringify } from 'yaml'
22

3+
import { BuiltInOutbound } from '@/constant/kernel'
34
import {
45
AdvancedConfigDefaults,
56
DnsConfigDefaults,
67
GeneralConfigDefaults,
78
TunConfigDefaults,
89
MixinConfigDefaults,
910
ScriptConfigDefaults,
10-
BuiltInOutbound,
11-
} from '@/constant'
11+
} from '@/constant/profile'
1212
import { RulesetBehavior, RulesetFormat, RuleType } from '@/enums/kernel'
1313
import { deepAssign, sampleID } from '@/utils'
1414

frontend/src/utils/tray.ts

Lines changed: 21 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
UpdateTrayMenus,
88
ShowMainWindow,
99
} from '@/bridge'
10-
import { BuiltInOutbound } from '@/constant'
11-
import { Theme, Color } from '@/enums/app'
12-
import { ClashMode, ProxyGroupType } from '@/enums/kernel'
10+
import { ColorOptions, ThemeOptions } from '@/constant/app'
11+
import { BuiltInOutbound, ModeOptions } from '@/constant/kernel'
12+
import { ProxyGroupType } from '@/enums/kernel'
1313
import i18n from '@/lang'
1414
import { useAppSettingsStore, useKernelApiStore, useEnvStore, usePluginsStore } from '@/stores'
1515
import {
@@ -183,26 +183,12 @@ const getTrayMenus = () => {
183183
type: 'item',
184184
text: 'kernel.mode',
185185
hidden: !kernelApiStore.running,
186-
children: [
187-
{
188-
type: 'item',
189-
text: 'kernel.global',
190-
checked: kernelApiStore.config.mode === ClashMode.Global,
191-
event: () => handleChangeMode(ClashMode.Global),
192-
},
193-
{
194-
type: 'item',
195-
text: 'kernel.rule',
196-
checked: kernelApiStore.config.mode === ClashMode.Rule,
197-
event: () => handleChangeMode(ClashMode.Rule),
198-
},
199-
{
200-
type: 'item',
201-
text: 'kernel.direct',
202-
checked: kernelApiStore.config.mode === ClashMode.Direct,
203-
event: () => handleChangeMode(ClashMode.Direct),
204-
},
205-
],
186+
children: ModeOptions.map((mode) => ({
187+
type: 'item',
188+
text: mode.label,
189+
checked: kernelApiStore.config.mode === mode.value,
190+
event: () => handleChangeMode(mode.value),
191+
})),
206192
},
207193
{
208194
type: 'item',
@@ -283,74 +269,22 @@ const getTrayMenus = () => {
283269
{
284270
type: 'item',
285271
text: 'settings.theme.name',
286-
children: [
287-
{
288-
type: 'item',
289-
text: 'settings.theme.dark',
290-
checked: appSettings.app.theme === Theme.Dark,
291-
event: () => (appSettings.app.theme = Theme.Dark),
292-
},
293-
{
294-
type: 'item',
295-
text: 'settings.theme.light',
296-
checked: appSettings.app.theme === Theme.Light,
297-
event: () => (appSettings.app.theme = Theme.Light),
298-
},
299-
{
300-
type: 'item',
301-
text: 'settings.theme.auto',
302-
checked: appSettings.app.theme === Theme.Auto,
303-
event: () => (appSettings.app.theme = Theme.Auto),
304-
},
305-
],
272+
children: ThemeOptions.map((theme) => ({
273+
type: 'item',
274+
text: theme.label,
275+
checked: appSettings.app.theme === theme.value,
276+
event: () => (appSettings.app.theme = theme.value),
277+
})),
306278
},
307279
{
308280
type: 'item',
309281
text: 'settings.color.name',
310-
children: [
311-
{
312-
type: 'item',
313-
text: 'settings.color.default',
314-
checked: appSettings.app.color === Color.Default,
315-
event: () => (appSettings.app.color = Color.Default),
316-
},
317-
{
318-
type: 'item',
319-
text: 'settings.color.orange',
320-
checked: appSettings.app.color === Color.Orange,
321-
event: () => (appSettings.app.color = Color.Orange),
322-
},
323-
{
324-
type: 'item',
325-
text: 'settings.color.pink',
326-
checked: appSettings.app.color === Color.Pink,
327-
event: () => (appSettings.app.color = Color.Pink),
328-
},
329-
{
330-
type: 'item',
331-
text: 'settings.color.red',
332-
checked: appSettings.app.color === Color.Red,
333-
event: () => (appSettings.app.color = Color.Red),
334-
},
335-
{
336-
type: 'item',
337-
text: 'settings.color.skyblue',
338-
checked: appSettings.app.color === Color.Skyblue,
339-
event: () => (appSettings.app.color = Color.Skyblue),
340-
},
341-
{
342-
type: 'item',
343-
text: 'settings.color.green',
344-
checked: appSettings.app.color === Color.Green,
345-
event: () => (appSettings.app.color = Color.Green),
346-
},
347-
{
348-
type: 'item',
349-
text: 'settings.color.purple',
350-
checked: appSettings.app.color === Color.Purple,
351-
event: () => (appSettings.app.color = Color.Purple),
352-
},
353-
],
282+
children: ColorOptions.map((color) => ({
283+
type: 'item',
284+
text: color.label,
285+
checked: appSettings.app.color === color.value,
286+
event: () => (appSettings.app.color = color.value),
287+
})),
354288
},
355289
{
356290
type: 'item',

0 commit comments

Comments
 (0)