Refactor clawx (#344)

Co-authored-by: ashione <skyzlxuan@gmail.com>
This commit is contained in:
paisley
2026-03-09 13:10:42 +08:00
committed by GitHub
Unverified
parent 3d804a9f5e
commit 2c5c82bb74
75 changed files with 7640 additions and 3106 deletions

View File

@@ -5,6 +5,7 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import i18n from '@/i18n';
import { hostApiFetch } from '@/lib/host-api';
import { invokeIpc } from '@/lib/api-client';
type Theme = 'light' | 'dark' | 'system';
@@ -99,7 +100,7 @@ export const useSettingsStore = create<SettingsState>()(
init: async () => {
try {
const settings = await invokeIpc<Partial<typeof defaultSettings>>('settings:getAll');
const settings = await hostApiFetch<Partial<typeof defaultSettings>>('/api/settings');
set((state) => ({ ...state, ...settings }));
if (settings.language) {
i18n.changeLanguage(settings.language);
@@ -111,11 +112,30 @@ export const useSettingsStore = create<SettingsState>()(
},
setTheme: (theme) => set({ theme }),
setLanguage: (language) => { i18n.changeLanguage(language); set({ language }); void invokeIpc('settings:set', 'language', language).catch(() => {}); },
setLanguage: (language) => {
i18n.changeLanguage(language);
set({ language });
void hostApiFetch('/api/settings/language', {
method: 'PUT',
body: JSON.stringify({ value: language }),
}).catch(() => {});
},
setStartMinimized: (startMinimized) => set({ startMinimized }),
setLaunchAtStartup: (launchAtStartup) => set({ launchAtStartup }),
setGatewayAutoStart: (gatewayAutoStart) => { set({ gatewayAutoStart }); void invokeIpc('settings:set', 'gatewayAutoStart', gatewayAutoStart).catch(() => {}); },
setGatewayPort: (gatewayPort) => { set({ gatewayPort }); void invokeIpc('settings:set', 'gatewayPort', gatewayPort).catch(() => {}); },
setGatewayAutoStart: (gatewayAutoStart) => {
set({ gatewayAutoStart });
void hostApiFetch('/api/settings/gatewayAutoStart', {
method: 'PUT',
body: JSON.stringify({ value: gatewayAutoStart }),
}).catch(() => {});
},
setGatewayPort: (gatewayPort) => {
set({ gatewayPort });
void hostApiFetch('/api/settings/gatewayPort', {
method: 'PUT',
body: JSON.stringify({ value: gatewayPort }),
}).catch(() => {});
},
setProxyEnabled: (proxyEnabled) => set({ proxyEnabled }),
setProxyServer: (proxyServer) => set({ proxyServer }),
setProxyHttpServer: (proxyHttpServer) => set({ proxyHttpServer }),