Release version 0.2.6

非活跃连接在 1 分钟内没有活动就会被自动断开;
临时会话被顶替后立即断开连接;
设置界面支持版本控制、github账号管理、Git服务器管理;
增强git凭据处理,现在需要认证时会弹框来支持凭据自动处理。
This commit is contained in:
xintaofei
2026-03-21 15:47:17 +08:00
parent d6098df1a8
commit 06b6f43f28
3 changed files with 121 additions and 80 deletions

View File

@@ -9,16 +9,24 @@ use crate::terminal::error::TerminalError;
use crate::terminal::manager::{SpawnOptions, TerminalManager};
use crate::terminal::types::TerminalInfo;
/// Build extra env vars and a temp credential file for the terminal session.
/// Temp files created for a terminal credential session.
struct TerminalCredFiles {
cred_file: std::path::PathBuf,
helper_script: std::path::PathBuf,
}
/// Build extra env vars and temp credential files for the terminal session.
///
/// Uses `GIT_ASKPASS` with a terminal-specific askpass script that reads from
/// a credential store file. This approach does NOT override the user's
/// existing `credential.helper` configuration (e.g. macOS Keychain).
/// Uses `credential.helper` with a custom credential helper script that speaks
/// git's structured credential protocol (host/protocol on stdin, username/password
/// on stdout). This is added via `GIT_CONFIG_COUNT` which APPENDS to the user's
/// existing credential helpers (e.g. macOS Keychain) for multi-valued keys.
/// Our helper is tried first; if it has no match, git falls through to existing helpers.
async fn prepare_credential_env(
db: &AppDatabase,
app_data_dir: &std::path::Path,
terminal_id: &str,
) -> (Option<HashMap<String, String>>, Option<std::path::PathBuf>) {
) -> (Option<HashMap<String, String>>, Option<TerminalCredFiles>) {
let accounts = match git_credential::load_github_accounts(&db.conn).await {
Some(s) if !s.accounts.is_empty() => s.accounts,
_ => return (None, None),
@@ -30,23 +38,40 @@ async fn prepare_credential_env(
return (None, None);
}
let askpass_script =
match git_credential::create_terminal_askpass_script(app_data_dir, &cred_file) {
Ok(p) => p,
Err(e) => {
eprintln!("[TERM] failed to create terminal askpass script: {}", e);
let _ = std::fs::remove_file(&cred_file);
return (None, None);
}
};
let helper_script = match git_credential::create_credential_helper_script(
app_data_dir,
&cred_file,
terminal_id,
) {
Ok(p) => p,
Err(e) => {
eprintln!("[TERM] failed to create credential helper script: {}", e);
let _ = std::fs::remove_file(&cred_file);
return (None, None);
}
};
let helper_path_str = helper_script.to_string_lossy().to_string();
// GIT_CONFIG_COUNT adds config entries that are tried BEFORE file-based config.
// For multi-valued keys like credential.helper, this means our helper runs first;
// if it exits 0 with no output, git falls through to the user's existing helpers.
let mut env = HashMap::new();
env.insert("GIT_CONFIG_COUNT".to_string(), "1".to_string());
env.insert(
"GIT_ASKPASS".to_string(),
askpass_script.to_string_lossy().to_string(),
"GIT_CONFIG_KEY_0".to_string(),
"credential.helper".to_string(),
);
env.insert(
"GIT_CONFIG_VALUE_0".to_string(),
helper_path_str,
);
(Some(env), Some(cred_file))
let files = TerminalCredFiles {
cred_file,
helper_script,
};
(Some(env), Some(files))
}
#[tauri::command]
@@ -66,9 +91,13 @@ pub async fn terminal_spawn(
.app_data_dir()
.map_err(|e| TerminalError::SpawnFailed(e.to_string()))?;
let (extra_env, cred_file) =
let (extra_env, cred_files) =
prepare_credential_env(&db, &app_data_dir, &terminal_id).await;
let temp_files = cred_files
.map(|f| vec![f.cred_file, f.helper_script])
.unwrap_or_default();
manager.spawn_with_id(
SpawnOptions {
terminal_id,
@@ -76,7 +105,7 @@ pub async fn terminal_spawn(
owner_window_label: window.label().to_string(),
initial_command,
extra_env,
credential_file: cred_file,
temp_files,
},
app_handle,
)