feat: implement launch at startup functionality in zn-ai

- Added a new setting for "launch at startup" in the GeneralSettingsPanel.
- Integrated the setting with the existing settings store and IPC mechanisms.
- Implemented platform-specific logic for enabling/disabling startup behavior in the main process.
- Created a new service for managing launch at startup settings, including Linux desktop entry creation.
- Added unit tests for the new functionality and ensured existing tests are updated accordingly.
- Updated i18n messages for the new setting in English, Chinese, and Japanese.
This commit is contained in:
duanshuwen
2026-04-20 23:29:10 +08:00
parent 35319e6a1d
commit 301f7d33ed
15 changed files with 924 additions and 3 deletions

View File

@@ -12,6 +12,8 @@ export {
updateLanguage as setLanguage,
updateFontSize as setFontSize,
updateMinimizeToTray as setMinimizeToTray,
updateLaunchAtStartup,
updateLaunchAtStartup as setLaunchAtStartup,
updatePrimaryColor as setPrimaryColor,
updateGatewayAutoStart,
updateGatewayAutoStart as setGatewayAutoStart,

View File

@@ -27,6 +27,7 @@ export interface SettingsState {
primaryColor: string;
fontSize: number;
minimizeToTray: boolean;
launchAtStartup: boolean;
providerId: string | null;
defaultModel: string | null;
gatewayAutoStart: boolean;
@@ -72,6 +73,7 @@ function createInitialState(): SettingsState {
primaryColor: '#1677ff',
fontSize: 14,
minimizeToTray: false,
launchAtStartup: false,
providerId: null,
defaultModel: null,
gatewayAutoStart: true,
@@ -205,11 +207,12 @@ async function hydrate(): Promise<SettingsState> {
const systemTheme = detectSystemTheme();
const systemLanguage = detectSystemLanguage();
const [themeMode, language, fontSize, minimizeToTray, primaryColor, providerId, defaultModel, gatewayAutoStart] = await Promise.all([
const [themeMode, language, fontSize, minimizeToTray, launchAtStartup, primaryColor, providerId, defaultModel, gatewayAutoStart] = await Promise.all([
readThemeMode(),
readConfigValue<LanguageCode>(CONFIG_KEYS.LANGUAGE, systemLanguage),
readConfigValue<number>(CONFIG_KEYS.FONT_SIZE, 14),
readConfigValue<boolean>(CONFIG_KEYS.MINIMIZE_TO_TRAY, false),
readConfigValue<boolean>(CONFIG_KEYS.LAUNCH_AT_STARTUP, false),
readConfigValue<string>(CONFIG_KEYS.PRIMARY_COLOR, '#1677ff'),
readConfigValue<string | null>(CONFIG_KEYS.PROVIDER, null),
readConfigValue<string | null>(CONFIG_KEYS.DEFAULT_MODEL, null),
@@ -231,6 +234,7 @@ async function hydrate(): Promise<SettingsState> {
primaryColor: primaryColor ?? '#1677ff',
fontSize: fontSize ?? 14,
minimizeToTray: Boolean(minimizeToTray),
launchAtStartup: Boolean(launchAtStartup),
providerId: providerId ?? null,
defaultModel: defaultModel ?? null,
gatewayAutoStart: Boolean(gatewayAutoStart),
@@ -306,6 +310,21 @@ async function setMinimizeToTray(minimizeToTray: boolean, persist = true): Promi
return state;
}
async function setLaunchAtStartup(launchAtStartup: boolean, persist = true): Promise<SettingsState> {
const next = Boolean(launchAtStartup);
if (state.launchAtStartup === next && state.initialized) return state;
patchState({
launchAtStartup: next,
});
if (persist) {
await writeConfigValue(CONFIG_KEYS.LAUNCH_AT_STARTUP, next);
}
return state;
}
async function setPrimaryColor(primaryColor: string, persist = true): Promise<SettingsState> {
const next = primaryColor || '#1677ff';
if (state.primaryColor === next && state.initialized) return state;
@@ -353,6 +372,7 @@ export const settingsStore = {
setLanguage,
setFontSize,
setMinimizeToTray,
setLaunchAtStartup,
setPrimaryColor,
setGatewayAutoStart,
hostApiFetch,
@@ -391,6 +411,10 @@ export async function updateMinimizeToTray(minimizeToTray: boolean, persist = tr
return setMinimizeToTray(minimizeToTray, persist);
}
export async function updateLaunchAtStartup(launchAtStartup: boolean, persist = true): Promise<SettingsState> {
return setLaunchAtStartup(launchAtStartup, persist);
}
export async function updateGatewayAutoStart(gatewayAutoStart: boolean, persist = true): Promise<SettingsState> {
return setGatewayAutoStart(gatewayAutoStart, persist);
}