feat: add gateway management features and settings

- Implemented new API routes for handling logs and settings related to the gateway.
- Added a new Gateway section in the General Settings panel to manage gateway status and auto-start options.
- Introduced a state management hook for gateway settings, including status, logs, and auto-start functionality.
- Updated configuration service to include gateway auto-start setting.
- Enhanced internationalization support for new gateway-related messages.
- Refactored existing settings store to accommodate new gateway settings.
- Cleaned up code and improved logging functionality.
This commit is contained in:
duanshuwen
2026-04-20 22:22:11 +08:00
parent f7f4ffaee9
commit dfef9c90a5
18 changed files with 1139 additions and 15 deletions

View File

@@ -13,4 +13,6 @@ export {
updateFontSize as setFontSize,
updateMinimizeToTray as setMinimizeToTray,
updatePrimaryColor as setPrimaryColor,
updateGatewayAutoStart,
updateGatewayAutoStart as setGatewayAutoStart,
} from './settings';

View File

@@ -29,6 +29,7 @@ export interface SettingsState {
minimizeToTray: boolean;
providerId: string | null;
defaultModel: string | null;
gatewayAutoStart: boolean;
}
const STORAGE_PREFIX = 'zn-ai-react:';
@@ -73,6 +74,7 @@ function createInitialState(): SettingsState {
minimizeToTray: false,
providerId: null,
defaultModel: null,
gatewayAutoStart: true,
};
}
@@ -203,7 +205,7 @@ async function hydrate(): Promise<SettingsState> {
const systemTheme = detectSystemTheme();
const systemLanguage = detectSystemLanguage();
const [themeMode, language, fontSize, minimizeToTray, primaryColor, providerId, defaultModel] = await Promise.all([
const [themeMode, language, fontSize, minimizeToTray, primaryColor, providerId, defaultModel, gatewayAutoStart] = await Promise.all([
readThemeMode(),
readConfigValue<LanguageCode>(CONFIG_KEYS.LANGUAGE, systemLanguage),
readConfigValue<number>(CONFIG_KEYS.FONT_SIZE, 14),
@@ -211,6 +213,7 @@ async function hydrate(): Promise<SettingsState> {
readConfigValue<string>(CONFIG_KEYS.PRIMARY_COLOR, '#1677ff'),
readConfigValue<string | null>(CONFIG_KEYS.PROVIDER, null),
readConfigValue<string | null>(CONFIG_KEYS.DEFAULT_MODEL, null),
readConfigValue<boolean>(CONFIG_KEYS.GATEWAY_AUTO_START, true),
]);
const resolvedLanguage = resolveSupportedLanguage(language ?? systemLanguage);
@@ -230,6 +233,7 @@ async function hydrate(): Promise<SettingsState> {
minimizeToTray: Boolean(minimizeToTray),
providerId: providerId ?? null,
defaultModel: defaultModel ?? null,
gatewayAutoStart: Boolean(gatewayAutoStart),
});
applyLocale(resolvedLanguage);
@@ -317,6 +321,21 @@ async function setPrimaryColor(primaryColor: string, persist = true): Promise<Se
return state;
}
async function setGatewayAutoStart(gatewayAutoStart: boolean, persist = true): Promise<SettingsState> {
const next = Boolean(gatewayAutoStart);
if (state.gatewayAutoStart === next && state.initialized) return state;
patchState({
gatewayAutoStart: next,
});
if (persist) {
await writeConfigValue(CONFIG_KEYS.GATEWAY_AUTO_START, next);
}
return state;
}
function getSnapshot(): SettingsState {
return state;
}
@@ -335,6 +354,7 @@ export const settingsStore = {
setFontSize,
setMinimizeToTray,
setPrimaryColor,
setGatewayAutoStart,
hostApiFetch,
};
@@ -371,4 +391,8 @@ export async function updateMinimizeToTray(minimizeToTray: boolean, persist = tr
return setMinimizeToTray(minimizeToTray, persist);
}
export async function updateGatewayAutoStart(gatewayAutoStart: boolean, persist = true): Promise<SettingsState> {
return setGatewayAutoStart(gatewayAutoStart, persist);
}
export { i18n };