refactor(settings): route settings-domain commands through the mutate funnel

Ports port saving, webdav/local backup operations, core change/restart/
upgrade, service install/uninstall/repair flows, the system-proxy toggle
queue, the DNS override toggle, and app lifecycle commands onto the single
funnel. Bespoke flows keep their own error handling via errorNotice:false;
simple flows gain the funnel's default error toast and revalidation.
This commit is contained in:
Tunglies
2026-10-01 14:34:17 +08:00
committed by GitHub
parent 763338dade
commit 3e91458799
15 changed files with 232 additions and 80 deletions
+15 -5
View File
@@ -1,6 +1,7 @@
import { useCallback } from 'react'
import { installService, restartCore } from '@/services/cmds'
import { mutate } from '@/services/mutate'
import { showNotice } from '@/services/notice-service'
const executeWithErrorHandling = async <T>(
@@ -23,14 +24,19 @@ const executeWithErrorHandling = async <T>(
export const useServiceInstaller = () => {
const installServiceAndRestartCore = useCallback(async () => {
const outcome = await executeWithErrorHandling(
() => installService(),
const installResult = await executeWithErrorHandling(
() =>
mutate(() => installService(), {
id: 'install-service',
errorNotice: false,
}),
'settings.statuses.clashService.installing',
)
if (outcome.status === 'sidecar') {
if (!installResult.ok) return
if (installResult.value.status === 'sidecar') {
showNotice.warning(
'settings.feedback.notifications.clashService.permissionFallback',
{ reason: outcome.reason },
{ reason: installResult.value.reason },
0,
)
return
@@ -40,7 +46,11 @@ export const useServiceInstaller = () => {
)
await executeWithErrorHandling(
() => restartCore(),
() =>
mutate(() => restartCore(), {
id: 'restart-core',
errorNotice: false,
}),
'settings.statuses.clash.restarting',
'settings.feedback.notifications.clash.restartSuccess',
)
+10 -4
View File
@@ -1,6 +1,7 @@
import { useCallback } from 'react'
import { uninstallService } from '@/services/cmds'
import { mutate } from '@/services/mutate'
import { showNotice } from '@/services/notice-service'
import { useSystemState } from './use-system-state'
@@ -12,10 +13,15 @@ export const useServiceUninstaller = () => {
let uninstallError: unknown
showNotice.info('settings.statuses.clashService.uninstalling')
try {
await uninstallService()
showNotice.success(
'settings.feedback.notifications.clashService.uninstallSuccess',
)
const result = await mutate(() => uninstallService(), {
id: 'uninstall-service',
errorNotice: false,
})
if (result.ok) {
showNotice.success(
'settings.feedback.notifications.clashService.uninstallSuccess',
)
}
} catch (error) {
uninstallError = error
}
+9 -2
View File
@@ -9,6 +9,7 @@ import {
getEmbeddedServerPort,
patchVergeConfig,
} from '@/services/cmds'
import { mutate } from '@/services/mutate'
import {
removeCacheData,
revalidateQueries,
@@ -64,10 +65,16 @@ export const useSystemProxyState = () => {
while (pendingRef.current !== null) {
const target = pendingRef.current
pendingRef.current = null
await patchVergeConfig({ enable_system_proxy: target })
await mutate(() => patchVergeConfig({ enable_system_proxy: target }), {
id: 'toggle-system-proxy',
errorNotice: false,
})
confirmed = target
if (!target && verge?.auto_close_connection) {
await closeAllConnections().catch(() => {})
await mutate(() => closeAllConnections(), {
id: 'close-all-connections',
errorNotice: false,
}).catch(() => {})
}
}
} catch (error) {