Revert "feat(settings): add auto-launch on system startup feature"

This reverts commit ba336fc416.

Reason: Found issues that need to be addressed before reintroducing
the auto-launch feature. Will reimplement with fixes.
This commit is contained in:
Jason
2025-11-21 23:30:56 +08:00
parent ba336fc416
commit eb46ac8592
14 changed files with 0 additions and 178 deletions

41
src-tauri/Cargo.lock generated
View File

@@ -291,17 +291,6 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "auto-launch"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
dependencies = [
"dirs 4.0.0",
"thiserror 1.0.69",
"winreg 0.10.1",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.5.0" version = "1.5.0"
@@ -609,7 +598,6 @@ name = "cc-switch"
version = "3.7.0" version = "3.7.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"auto-launch",
"chrono", "chrono",
"dirs 5.0.1", "dirs 5.0.1",
"futures", "futures",
@@ -994,15 +982,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "dirs"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys 0.3.7",
]
[[package]] [[package]]
name = "dirs" name = "dirs"
version = "5.0.1" version = "5.0.1"
@@ -1021,17 +1000,6 @@ dependencies = [
"dirs-sys 0.5.0", "dirs-sys 0.5.0",
] ]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users 0.4.6",
"winapi",
]
[[package]] [[package]]
name = "dirs-sys" name = "dirs-sys"
version = "0.4.1" version = "0.4.1"
@@ -6429,15 +6397,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.52.0" version = "0.52.0"

View File

@@ -34,7 +34,6 @@ tauri-plugin-updater = "2"
tauri-plugin-dialog = "2" tauri-plugin-dialog = "2"
tauri-plugin-store = "2" tauri-plugin-store = "2"
tauri-plugin-deep-link = "2" tauri-plugin-deep-link = "2"
auto-launch = "0.5"
dirs = "5.0" dirs = "5.0"
toml = "0.8" toml = "0.8"
toml_edit = "0.22" toml_edit = "0.22"

View File

@@ -1,39 +0,0 @@
use crate::error::AppError;
use auto_launch::AutoLaunch;
/// 初始化 AutoLaunch 实例
fn get_auto_launch() -> Result<AutoLaunch, AppError> {
let app_name = "CC Switch";
let app_path = std::env::current_exe().map_err(AppError::AutoLaunchPathError)?;
let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), false, &[] as &[&str]);
Ok(auto_launch)
}
/// 启用开机自启
pub fn enable_auto_launch() -> Result<(), AppError> {
let auto_launch = get_auto_launch()?;
auto_launch
.enable()
.map_err(|e| AppError::AutoLaunchEnableError(e.to_string()))?;
log::info!("Auto-launch enabled");
Ok(())
}
/// 禁用开机自启
pub fn disable_auto_launch() -> Result<(), AppError> {
let auto_launch = get_auto_launch()?;
auto_launch
.disable()
.map_err(|e| AppError::AutoLaunchDisableError(e.to_string()))?;
log::info!("Auto-launch disabled");
Ok(())
}
/// 检查是否已启用开机自启
pub fn is_auto_launch_enabled() -> Result<bool, AppError> {
let auto_launch = get_auto_launch()?;
auto_launch
.is_enabled()
.map_err(|e| AppError::AutoLaunchCheckError(e.to_string()))
}

View File

@@ -37,20 +37,3 @@ pub async fn set_app_config_dir_override(
crate::app_store::set_app_config_dir_to_store(&app, path.as_deref())?; crate::app_store::set_app_config_dir_to_store(&app, path.as_deref())?;
Ok(true) Ok(true)
} }
/// 设置开机自启
#[tauri::command]
pub async fn set_auto_launch(enabled: bool) -> Result<bool, String> {
if enabled {
crate::auto_launch::enable_auto_launch().map_err(|e| e.to_string())?;
} else {
crate::auto_launch::disable_auto_launch().map_err(|e| e.to_string())?;
}
Ok(true)
}
/// 获取开机自启状态
#[tauri::command]
pub async fn get_auto_launch_status() -> Result<bool, String> {
crate::auto_launch::is_auto_launch_enabled().map_err(|e| e.to_string())
}

View File

@@ -50,14 +50,6 @@ pub enum AppError {
zh: String, zh: String,
en: String, en: String,
}, },
#[error("Failed to get application path for auto-launch: {0}")]
AutoLaunchPathError(#[source] std::io::Error),
#[error("Failed to enable auto-launch: {0}")]
AutoLaunchEnableError(String),
#[error("Failed to disable auto-launch: {0}")]
AutoLaunchDisableError(String),
#[error("Failed to check auto-launch status: {0}")]
AutoLaunchCheckError(String),
} }
impl AppError { impl AppError {

View File

@@ -1,6 +1,5 @@
mod app_config; mod app_config;
mod app_store; mod app_store;
mod auto_launch;
mod claude_mcp; mod claude_mcp;
mod claude_plugin; mod claude_plugin;
mod codex_config; mod codex_config;
@@ -560,30 +559,6 @@ pub fn run() {
// 启动阶段不再无条件保存,避免意外覆盖用户配置。 // 启动阶段不再无条件保存,避免意外覆盖用户配置。
// 同步开机自启状态:以 settings.json 为准,保持系统项一致
{
let settings = crate::settings::get_settings();
let system_enabled = crate::auto_launch::is_auto_launch_enabled().unwrap_or(false);
if settings.launch_on_startup != system_enabled {
log::info!(
"开机自启状态不一致settings={}, system={},以 settings 为准",
settings.launch_on_startup,
system_enabled
);
let sync_result = if settings.launch_on_startup {
crate::auto_launch::enable_auto_launch()
} else {
crate::auto_launch::disable_auto_launch()
};
if let Err(e) = sync_result {
log::warn!("同步开机自启状态失败: {}", e);
}
}
}
// 注册 deep-link URL 处理器(使用正确的 DeepLinkExt API // 注册 deep-link URL 处理器(使用正确的 DeepLinkExt API
log::info!("=== Registering deep-link URL handler ==="); log::info!("=== Registering deep-link URL handler ===");
@@ -678,8 +653,6 @@ pub fn run() {
commands::get_settings, commands::get_settings,
commands::save_settings, commands::save_settings,
commands::restart_app, commands::restart_app,
commands::set_auto_launch,
commands::get_auto_launch_status,
commands::check_for_updates, commands::check_for_updates,
commands::is_portable_mode, commands::is_portable_mode,
commands::get_claude_plugin_status, commands::get_claude_plugin_status,

View File

@@ -49,9 +49,6 @@ pub struct AppSettings {
pub gemini_config_dir: Option<String>, pub gemini_config_dir: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub language: Option<String>, pub language: Option<String>,
/// 是否开机自启
#[serde(default)]
pub launch_on_startup: bool,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub security: Option<SecuritySettings>, pub security: Option<SecuritySettings>,
/// Claude 自定义端点列表 /// Claude 自定义端点列表
@@ -80,7 +77,6 @@ impl Default for AppSettings {
codex_config_dir: None, codex_config_dir: None,
gemini_config_dir: None, gemini_config_dir: None,
language: None, language: None,
launch_on_startup: false,
security: None, security: None,
custom_endpoints_claude: HashMap::new(), custom_endpoints_claude: HashMap::new(),
custom_endpoints_codex: HashMap::new(), custom_endpoints_codex: HashMap::new(),

View File

@@ -19,13 +19,6 @@ export function WindowSettings({ settings, onChange }: WindowSettingsProps) {
</p> </p>
</header> </header>
<ToggleRow
title={t("settings.launchOnStartup")}
description={t("settings.launchOnStartupDescription")}
checked={!!settings.launchOnStartup}
onCheckedChange={(value) => onChange({ launchOnStartup: value })}
/>
<ToggleRow <ToggleRow
title={t("settings.minimizeToTray")} title={t("settings.minimizeToTray")}
description={t("settings.minimizeToTrayDescription")} description={t("settings.minimizeToTrayDescription")}

View File

@@ -126,7 +126,6 @@ export function useSettings(): UseSettingsResult {
const previousClaudeDir = sanitizeDir(data?.claudeConfigDir); const previousClaudeDir = sanitizeDir(data?.claudeConfigDir);
const previousCodexDir = sanitizeDir(data?.codexConfigDir); const previousCodexDir = sanitizeDir(data?.codexConfigDir);
const previousGeminiDir = sanitizeDir(data?.geminiConfigDir); const previousGeminiDir = sanitizeDir(data?.geminiConfigDir);
const previousAutoLaunch = data?.launchOnStartup ?? false;
const payload: Settings = { const payload: Settings = {
...settings, ...settings,
@@ -140,20 +139,6 @@ export function useSettings(): UseSettingsResult {
await settingsApi.setAppConfigDirOverride(sanitizedAppDir ?? null); await settingsApi.setAppConfigDirOverride(sanitizedAppDir ?? null);
// 如果开机自启状态改变,调用系统 API
if (payload.launchOnStartup !== previousAutoLaunch) {
try {
await settingsApi.setAutoLaunch(payload.launchOnStartup);
} catch (error) {
console.error("Failed to update auto-launch:", error);
toast.error(
t("settings.autoLaunchFailed", {
defaultValue: "设置开机自启失败",
}),
);
}
}
try { try {
if (payload.enableClaudePluginIntegration) { if (payload.enableClaudePluginIntegration) {
await settingsApi.applyClaudePluginConfig({ official: false }); await settingsApi.applyClaudePluginConfig({ official: false });

View File

@@ -82,7 +82,6 @@ export function useSettingsForm(): UseSettingsFormResult {
minimizeToTrayOnClose: data.minimizeToTrayOnClose ?? true, minimizeToTrayOnClose: data.minimizeToTrayOnClose ?? true,
enableClaudePluginIntegration: enableClaudePluginIntegration:
data.enableClaudePluginIntegration ?? false, data.enableClaudePluginIntegration ?? false,
launchOnStartup: data.launchOnStartup ?? false,
claudeConfigDir: sanitizeDir(data.claudeConfigDir), claudeConfigDir: sanitizeDir(data.claudeConfigDir),
codexConfigDir: sanitizeDir(data.codexConfigDir), codexConfigDir: sanitizeDir(data.codexConfigDir),
language: normalizedLanguage, language: normalizedLanguage,
@@ -102,7 +101,6 @@ export function useSettingsForm(): UseSettingsFormResult {
showInTray: true, showInTray: true,
minimizeToTrayOnClose: true, minimizeToTrayOnClose: true,
enableClaudePluginIntegration: false, enableClaudePluginIntegration: false,
launchOnStartup: false,
language: readPersistedLanguage(), language: readPersistedLanguage(),
} as SettingsFormState); } as SettingsFormState);
@@ -137,7 +135,6 @@ export function useSettingsForm(): UseSettingsFormResult {
minimizeToTrayOnClose: serverData.minimizeToTrayOnClose ?? true, minimizeToTrayOnClose: serverData.minimizeToTrayOnClose ?? true,
enableClaudePluginIntegration: enableClaudePluginIntegration:
serverData.enableClaudePluginIntegration ?? false, serverData.enableClaudePluginIntegration ?? false,
launchOnStartup: serverData.launchOnStartup ?? false,
claudeConfigDir: sanitizeDir(serverData.claudeConfigDir), claudeConfigDir: sanitizeDir(serverData.claudeConfigDir),
codexConfigDir: sanitizeDir(serverData.codexConfigDir), codexConfigDir: sanitizeDir(serverData.codexConfigDir),
language: normalizedLanguage, language: normalizedLanguage,

View File

@@ -166,9 +166,6 @@
"languageOptionEnglish": "English", "languageOptionEnglish": "English",
"windowBehavior": "Window Behavior", "windowBehavior": "Window Behavior",
"windowBehaviorHint": "Configure window minimize and Claude plugin integration policies.", "windowBehaviorHint": "Configure window minimize and Claude plugin integration policies.",
"launchOnStartup": "Launch on Startup",
"launchOnStartupDescription": "Automatically run CC Switch when system starts",
"autoLaunchFailed": "Failed to set auto-launch",
"minimizeToTray": "Minimize to tray on close", "minimizeToTray": "Minimize to tray on close",
"minimizeToTrayDescription": "When checked, clicking the close button will hide to system tray, otherwise the app will exit directly.", "minimizeToTrayDescription": "When checked, clicking the close button will hide to system tray, otherwise the app will exit directly.",
"enableClaudePluginIntegration": "Apply to Claude Code extension", "enableClaudePluginIntegration": "Apply to Claude Code extension",

View File

@@ -166,9 +166,6 @@
"languageOptionEnglish": "English", "languageOptionEnglish": "English",
"windowBehavior": "窗口行为", "windowBehavior": "窗口行为",
"windowBehaviorHint": "配置窗口最小化与 Claude 插件联动策略。", "windowBehaviorHint": "配置窗口最小化与 Claude 插件联动策略。",
"launchOnStartup": "开机自启",
"launchOnStartupDescription": "随系统启动自动运行 CC Switch",
"autoLaunchFailed": "设置开机自启失败",
"minimizeToTray": "关闭时最小化到托盘", "minimizeToTray": "关闭时最小化到托盘",
"minimizeToTrayDescription": "勾选后点击关闭按钮会隐藏到系统托盘,取消则直接退出应用。", "minimizeToTrayDescription": "勾选后点击关闭按钮会隐藏到系统托盘,取消则直接退出应用。",
"enableClaudePluginIntegration": "应用到 Claude Code 插件", "enableClaudePluginIntegration": "应用到 Claude Code 插件",

View File

@@ -107,12 +107,4 @@ export const settingsApi = {
} }
await invoke("open_external", { url }); await invoke("open_external", { url });
}, },
async setAutoLaunch(enabled: boolean): Promise<boolean> {
return await invoke("set_auto_launch", { enabled });
},
async getAutoLaunchStatus(): Promise<boolean> {
return await invoke("get_auto_launch_status");
},
}; };

View File

@@ -101,8 +101,6 @@ export interface Settings {
geminiConfigDir?: string; geminiConfigDir?: string;
// 首选语言(可选,默认中文) // 首选语言(可选,默认中文)
language?: "en" | "zh"; language?: "en" | "zh";
// 是否开机自启
launchOnStartup?: boolean;
// Claude 自定义端点列表 // Claude 自定义端点列表
customEndpointsClaude?: Record<string, CustomEndpoint>; customEndpointsClaude?: Record<string, CustomEndpoint>;
// Codex 自定义端点列表 // Codex 自定义端点列表