mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-23 01:14:51 +08:00
feat(settings): add option to skip Claude Code first-run confirmation
Add a new setting to automatically skip Claude Code's onboarding screen by writing hasCompletedOnboarding=true to ~/.claude.json. The setting defaults to enabled for better user experience. - Add set/clear_has_completed_onboarding functions in claude_mcp.rs - Add Tauri commands and frontend API integration - Add toggle in WindowSettings with i18n support (en/zh/ja) - Fix hardcoded Chinese text in tests to use i18n keys
This commit is contained in:
@@ -105,6 +105,55 @@ pub fn read_mcp_json() -> Result<Option<String>, AppError> {
|
||||
Ok(Some(content))
|
||||
}
|
||||
|
||||
/// 在 ~/.claude.json 根对象写入 hasCompletedOnboarding=true(用于跳过 Claude Code 初次安装确认)
|
||||
/// 仅增量写入该字段,其他字段保持不变
|
||||
pub fn set_has_completed_onboarding() -> Result<bool, AppError> {
|
||||
let path = user_config_path();
|
||||
let mut root = if path.exists() {
|
||||
read_json_value(&path)?
|
||||
} else {
|
||||
serde_json::json!({})
|
||||
};
|
||||
|
||||
let obj = root
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| AppError::Config("~/.claude.json 根必须是对象".into()))?;
|
||||
|
||||
let already = obj
|
||||
.get("hasCompletedOnboarding")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
if already {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
obj.insert("hasCompletedOnboarding".into(), Value::Bool(true));
|
||||
write_json_value(&path, &root)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// 删除 ~/.claude.json 根对象的 hasCompletedOnboarding 字段(恢复 Claude Code 初次安装确认)
|
||||
/// 仅增量删除该字段,其他字段保持不变
|
||||
pub fn clear_has_completed_onboarding() -> Result<bool, AppError> {
|
||||
let path = user_config_path();
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let mut root = read_json_value(&path)?;
|
||||
let obj = root
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| AppError::Config("~/.claude.json 根必须是对象".into()))?;
|
||||
|
||||
let existed = obj.remove("hasCompletedOnboarding").is_some();
|
||||
if !existed {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
write_json_value(&path, &root)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn upsert_mcp_server(id: &str, spec: Value) -> Result<bool, AppError> {
|
||||
if id.trim().is_empty() {
|
||||
return Err(AppError::InvalidInput("MCP 服务器 ID 不能为空".into()));
|
||||
|
||||
@@ -34,3 +34,15 @@ pub async fn apply_claude_plugin_config(official: bool) -> Result<bool, String>
|
||||
pub async fn is_claude_plugin_applied() -> Result<bool, String> {
|
||||
crate::claude_plugin::is_claude_config_applied().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Claude Code:跳过初次安装确认(写入 ~/.claude.json 的 hasCompletedOnboarding=true)
|
||||
#[tauri::command]
|
||||
pub async fn apply_claude_onboarding_skip() -> Result<bool, String> {
|
||||
crate::claude_mcp::set_has_completed_onboarding().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Claude Code:恢复初次安装确认(删除 ~/.claude.json 的 hasCompletedOnboarding 字段)
|
||||
#[tauri::command]
|
||||
pub async fn clear_claude_onboarding_skip() -> Result<bool, String> {
|
||||
crate::claude_mcp::clear_has_completed_onboarding().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
@@ -585,6 +585,8 @@ pub fn run() {
|
||||
commands::read_claude_plugin_config,
|
||||
commands::apply_claude_plugin_config,
|
||||
commands::is_claude_plugin_applied,
|
||||
commands::apply_claude_onboarding_skip,
|
||||
commands::clear_claude_onboarding_skip,
|
||||
// Claude MCP management
|
||||
commands::get_claude_mcp_status,
|
||||
commands::read_claude_mcp_config,
|
||||
|
||||
@@ -31,6 +31,9 @@ pub struct AppSettings {
|
||||
/// 是否启用 Claude 插件联动
|
||||
#[serde(default)]
|
||||
pub enable_claude_plugin_integration: bool,
|
||||
/// 是否跳过 Claude Code 初次安装确认
|
||||
#[serde(default = "default_true")]
|
||||
pub skip_claude_onboarding: bool,
|
||||
/// 是否开机自启
|
||||
#[serde(default)]
|
||||
pub launch_on_startup: bool,
|
||||
@@ -65,12 +68,17 @@ fn default_minimize_to_tray_on_close() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
show_in_tray: true,
|
||||
minimize_to_tray_on_close: true,
|
||||
enable_claude_plugin_integration: false,
|
||||
skip_claude_onboarding: true,
|
||||
launch_on_startup: false,
|
||||
language: None,
|
||||
claude_config_dir: None,
|
||||
|
||||
Reference in New Issue
Block a user