DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(windows): provision Git in blank environments (#131)
Mao Mre4c55c784c8b
diff --git a/src-tauri/src/bridge/lifecycle.rs b/src-tauri/src/bridge/lifecycle.rsindex 78bf907e..ca8d6f04 100644--- a/src-tauri/src/bridge/lifecycle.rs+++ b/src-tauri/src/bridge/lifecycle.rs@@ -69,6 +69,9 @@ pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String>// 升级后 `installed` 已为 true 会跳过环境安装,捆绑 pnpm 可能从未落盘,// 需一并纳入"已就绪"判定,缺失时由 workflow::install 按任务补齐。let pnpm_ok = download::Pnpm.check_installed(&app_handle);+ // Windows 空白环境还必须有可执行的 Git,才能安装 github:/git+ssh: 插件。+ // 非 Windows 返回 true,保持原有依赖集合不变。+ let git_ok = config::git_runtime_ready(&app_handle);// 启动自愈捷径:记录显示未安装、但运行时文件已全部在盘。常见于桌面端自更新// 安装器强杀进程,或上次启动时核心文件短暂缺失被 workflow::start 复位@@ -77,7 +80,7 @@ pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String>// 误判为真更新,而重下整目录在 Windows 上极易破坏 node_modules(历史 issue:// 重解压后启动报找不到 @deepseek-ai/dsh-client-ui-settings)。真更新一律由// 启动后的 check_dsh_update 提示用户手动安装,启动路径不该自行下载。- if node_ok && dsh_files_ok && pnpm_ok {+ if node_ok && dsh_files_ok && pnpm_ok && git_ok {let setting = config::get_store_dat_setting(&app_handle);if !setting.installed {log::info!(@@ -91,6 +94,22 @@ pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String>}}+ // 老版本升级后 installed 仍为 true,但可能缺少新版新增的 Windows Git 依赖。+ // 其余三项均就绪时直接走本地任务跳过 + Git 补装,不查询 Harness 最新版本,+ // 避免一次依赖自愈意外触发核心更新。+ if node_ok && dsh_files_ok && pnpm_ok && !git_ok {+ log::info!("Git dependency missing, provisioning bundled MinGit without core update check");+ workflow::status::set_status(workflow::status::Status::Installing);+ workflow::status::emit_status(&app_handle);+ if let Err(e) = workflow::install(&app_handle, None).await {+ log::error!("Git dependency installation failed, resetting status: {e}");+ reset_install_status(&app_handle);+ return Err(e);+ }+ sync_cli_link(&app_handle);+ return Ok(false);+ }+let dsh_latest = download::fetch_latest_dsh_pkg_info().await;// 已安装文件在盘时,用 resolve_update 甄别「记录滞后」与「真更新」:@@ -160,7 +179,7 @@ pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String>}};- if node_ok && !dsh_need_install && pnpm_ok {+ if node_ok && !dsh_need_install && pnpm_ok && git_ok {log::info!("Dependencies already installed and up to date, skipping installation");let mut setting = config::get_store_dat_setting(&app_handle);if !setting.installed {@@ -270,7 +289,8 @@ pub fn get_dsh_status() -> workflow::status::Status {workflow::status::get_status()}-/// 运行时文件是否已全部在盘(Node / Dsh / pnpm 三件套,纯本地检查、无网络)。+/// 运行时文件是否已全部在盘(Node / Dsh / pnpm;Windows 还要求 Git 可用,+/// 纯本地检查、无网络)。////// 判定条件与 `install_dependencies` 的「启动自愈」捷径完全一致:桌面端自更新/// (MSI 强杀进程)后 store 可能被复位或损坏显示「未安装」,但运行时文件其实@@ -281,6 +301,7 @@ pub fn runtime_ready(app_handle: AppHandle) -> bool {download::Nodejs.check_installed(&app_handle)&& download::Dsh.check_installed(&app_handle)&& download::Pnpm.check_installed(&app_handle)+ && config::git_runtime_ready(&app_handle)}#[cfg(test)]diff --git a/src-tauri/src/config/constants.rs b/src-tauri/src/config/constants.rsindex e732da34..66de31c4 100644--- a/src-tauri/src/config/constants.rs+++ b/src-tauri/src/config/constants.rs@@ -29,6 +29,18 @@ pub const PNPM_SHA256: &str = "deafa7ec98a1218b6a047289b92fbe2395c1e22d3495bb711/// pnpm 官方 npm registry tarball 下载地址前缀(纯 JS 发行,全平台同一 URL)pub const PNPM_BASE_URL: &str = "https://registry.npmjs.org/pnpm/-/";+/// Windows 空白环境使用的免安装 MinGit 版本。+pub const MINGIT_VERSION: &str = "2.53.0.2";+/// MinGit x64 官方发行包 SHA-256。+pub const MINGIT_X64_SHA256: &str =+ "d4bf83d6a860ccae9af44e508e1e00a39f09db6fa78a9ba5543b94d87ca22a29";+/// MinGit ARM64 官方发行包 SHA-256。+pub const MINGIT_ARM64_SHA256: &str =+ "842d50edc6bbcf39693e60a8ebb9dabb89b96b932b63aae12d218522b3e497f3";+/// Git for Windows 官方发行资产地址前缀。+pub const MINGIT_BASE_URL: &str =+ "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.2/";+/// pnpm 镜像下载地址前缀(npmmirror registry,302 重定向至 cdn.npmmirror.com)pub const PNPM_MIRROR_BASE_URL: &str = "https://registry.npmmirror.com/pnpm/-/";@@ -58,6 +70,10 @@ pub const DSH_MANIFEST_RELATIVE: &str = "package.json";pub const PNPM_CORE_DIR: &str = "pnpm";pub const PNPM_ENTRY_RELATIVE: &str = "bin/pnpm.cjs";+/// Windows 免安装 Git 的安装目录与 CLI 入口(相对安装目录)。+pub const MINGIT_CORE_DIR: &str = "git";+pub const MINGIT_ENTRY_RELATIVE: &str = "cmd/git.exe";+/// 旧版数据目录名:迁移前 $DSH_HOME 位于 `{app_data}/data/dsh`,/// 现仅用于 legacy 路径识别(见 service::migrate)。新 $DSH_HOME = 官方 `~/.dsh`。pub const DSH_DATA_DIR_NAME: &str = "dsh";diff --git a/src-tauri/src/config/runtime.rs b/src-tauri/src/config/runtime.rsindex e0eb00c6..c0db6eb6 100644--- a/src-tauri/src/config/runtime.rs+++ b/src-tauri/src/config/runtime.rs@@ -257,6 +257,111 @@ pub fn get_pnpm_download_url() -> String {format!("{}pnpm-{}.tgz", pnpm_base_url(detect_region()), PNPM_VERSION)}+/// Windows 免安装 Git 的安装目录。+pub fn get_mingit_install_path<R: Runtime>(app_handle: &AppHandle<R>) -> PathBuf {+ get_base_dir(app_handle)+ .join("dependencies")+ .join(MINGIT_CORE_DIR)+}++/// Windows 免安装 Git 的 CLI 入口。+pub fn get_mingit_binary_path<R: Runtime>(app_handle: &AppHandle<R>) -> PathBuf {+ get_mingit_install_path(app_handle).join(MINGIT_ENTRY_RELATIVE)+}++/// Windows MinGit 官方发行包文件名。+fn mingit_pkg_filename(arch: &str) -> Result<String, String> {+ match arch {+ "x86_64" => Ok(format!("MinGit-{MINGIT_VERSION}-64-bit.zip")),+ "aarch64" => Ok(format!("MinGit-{MINGIT_VERSION}-arm64.zip")),+ _ => Err(format!("MINGIT_PLATFORM_UNSUPPORTED: windows {arch}")),+ }+}++/// Windows MinGit 官方发行包下载地址。+pub fn get_mingit_download_url() -> Result<String, String> {+ Ok(format!(+ "{MINGIT_BASE_URL}{}",+ mingit_pkg_filename(env::consts::ARCH)?+ ))+}++/// Windows MinGit 官方发行包固定 SHA-256。+pub fn get_mingit_sha256() -> Result<&'static str, String> {+ match env::consts::ARCH {+ "x86_64" => Ok(MINGIT_X64_SHA256),+ "aarch64" => Ok(MINGIT_ARM64_SHA256),+ arch => Err(format!("MINGIT_PLATFORM_UNSUPPORTED: windows {arch}")),+ }+}++/// 在 PATH 中寻找可直接运行的系统 Git。+#[cfg(windows)]+pub fn find_system_git_binary() -> Option<PathBuf> {+ std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default())+ .filter(|dir| !dir.as_os_str().is_empty())+ .map(|dir| dir.join("git.exe"))+ .find(|candidate| candidate.is_file() && git_binary_works(candidate))+}++/// 运行 Git 并捕获输出;GUI 进程下禁止闪现控制台窗口。+#[cfg(windows)]+fn git_output(binary: &Path, arg: &str) -> Option<std::process::Output> {+ use std::os::windows::process::CommandExt;++ std::process::Command::new(binary)+ .arg(arg)+ .creation_flags(0x08000000) // CREATE_NO_WINDOW+ .output()+ .ok()+}++/// 检查 Git CLI 与 HTTPS transport helper 是否完整,避免 PATH 中只有残缺壳程序+/// (`git --version` 可成功但无法执行 `ls-remote`)阻止自动修复。+#[cfg(windows)]+fn git_binary_works(binary: &Path) -> bool {+ if !git_output(binary, "--version").is_some_and(|output| output.status.success()) {+ return false;+ }+ let Some(output) = git_output(binary, "--exec-path").filter(|output| output.status.success())+ else {+ return false;+ };+ let exec_path = String::from_utf8_lossy(&output.stdout).trim().to_string();+ !exec_path.is_empty() && PathBuf::from(exec_path).join("git-remote-https.exe").is_file()+}++/// 返回桌面端应注入子进程 PATH 的已选 Git `cmd` 目录。+#[cfg(windows)]+pub fn get_git_cmd_dir<R: Runtime>(app_handle: &AppHandle<R>) -> Option<PathBuf> {+ if let Some(system_git) = find_system_git_binary() {+ return system_git.parent().map(Path::to_path_buf);+ }+ let bundled = get_mingit_binary_path(app_handle);+ if bundled.is_file() && git_binary_works(&bundled) {+ return bundled.parent().map(Path::to_path_buf);+ }+ None+}++/// 非 Windows 平台依赖系统 Git,不额外注入目录。+#[cfg(not(windows))]+pub fn get_git_cmd_dir<R: Runtime>(_app_handle: &AppHandle<R>) -> Option<PathBuf> {+ None+}++/// 当前环境是否已有可供插件 Git 依赖使用的 Git。+#[cfg(windows)]+pub fn git_runtime_ready<R: Runtime>(app_handle: &AppHandle<R>) -> bool {+ find_system_git_binary().is_some() || git_binary_works(&get_mingit_binary_path(app_handle))+}++/// 非 Windows 平台不属于本次空白 Windows 环境的自动配置范围。+#[cfg(not(windows))]+pub fn git_runtime_ready<R: Runtime>(_app_handle: &AppHandle<R>) -> bool {+ true+}+/// Harness 发行版清单路径pub fn get_dsh_package_json_path<R: Runtime>(app_handle: &AppHandle<R>) -> PathBuf {get_dsh_install_path(app_handle).join(DSH_MANIFEST_RELATIVE)@@ -456,6 +561,33 @@ mod tests {assert!(dsh.ends_with(".zip"));}+ #[test]+ fn mingit_pkg_filename_covers_supported_windows_architectures() {+ assert_eq!(+ mingit_pkg_filename("x86_64").expect("x64 MinGit asset"),+ format!("MinGit-{MINGIT_VERSION}-64-bit.zip")+ );+ assert_eq!(+ mingit_pkg_filename("aarch64").expect("ARM64 MinGit asset"),+ format!("MinGit-{MINGIT_VERSION}-arm64.zip")+ );+ }++ #[test]+ fn mingit_pkg_filename_rejects_unsupported_architecture() {+ let error = mingit_pkg_filename("x86").expect_err("unsupported MinGit architecture");+ assert_eq!(error, "MINGIT_PLATFORM_UNSUPPORTED: windows x86");+ }++ #[test]+ fn mingit_release_metadata_is_pinned_and_https() {+ assert!(MINGIT_BASE_URL.starts_with("https://github.com/git-for-windows/git/releases/"));+ assert!(MINGIT_BASE_URL.contains("v2.53.0.windows.2"));+ assert_eq!(MINGIT_X64_SHA256.len(), 64);+ assert_eq!(MINGIT_ARM64_SHA256.len(), 64);+ assert_ne!(MINGIT_X64_SHA256, MINGIT_ARM64_SHA256);+ }+#[test]fn node_pkg_filename_covers_all_supported_platforms() {// 与 nodejs.org dist 布局一致(纯函数测试,不受宿主操作系统限制)diff --git a/src-tauri/src/service/cli/shim.rs b/src-tauri/src/service/cli/shim.rsindex d6e15b59..7f7ec2aa 100644--- a/src-tauri/src/service/cli/shim.rs+++ b/src-tauri/src/service/cli/shim.rs@@ -239,6 +239,10 @@ rem DeepSeek Harness Desktop - dsh command shim (generated)rem Do not edit: regenerated by the desktop app on install/startup.setlocalset "APP_DIR={app_dir}"+rem Use bundled MinGit only when system Git lacks its HTTPS transport helper.+set "SYSTEM_GIT_WORKS="+for /f "delims=" %%g in ('git --exec-path 2^>nul') do if exist "%%g\git-remote-https.exe" set "SYSTEM_GIT_WORKS=1"+if not defined SYSTEM_GIT_WORKS if exist "%APP_DIR%\dependencies\git\cmd\git.exe" set "PATH=%APP_DIR%\dependencies\git\cmd;%PATH%"{user_dsh}set "DSH_BIN={dsh_bin}"set "DSH_HOME={dsh_home}"@@ -276,6 +280,18 @@ pub fn build_ps1_shim(app_dir: &Path, dsh_home: &Path) -> String {$ErrorActionPreference = "Stop"$appDir = '{app_dir}'$dshBin = '{dsh_bin}'+# Use bundled MinGit only when system Git lacks its HTTPS transport helper.+$systemGitWorks = $false+try {{+ $gitExecPath = & git --exec-path 2> $null+ $systemGitWorks = ($LASTEXITCODE -eq 0) -and (Test-Path -LiteralPath (Join-Path $gitExecPath 'git-remote-https.exe'))+}} catch {{}}+if (-not $systemGitWorks) {{+ $gitDir = Join-Path $appDir 'dependencies\git\cmd'+ if (Test-Path -LiteralPath (Join-Path $gitDir 'git.exe')) {{+ $env:PATH = $gitDir + ';' + $env:PATH+ }}+}}{user_dsh}$dshHome = '{dsh_home}'$env:DSH_TELEMETRY_DISABLED = '1'@@ -351,6 +367,10 @@ rem Do not edit: regenerated by the desktop app on install/startup.setlocalset "APP_DIR={app_dir}"set "PNPM_BIN={pnpm_bin}"+rem Use bundled MinGit only when system Git lacks its HTTPS transport helper.+set "SYSTEM_GIT_WORKS="+for /f "delims=" %%g in ('git --exec-path 2^>nul') do if exist "%%g\git-remote-https.exe" set "SYSTEM_GIT_WORKS=1"+if not defined SYSTEM_GIT_WORKS if exist "%APP_DIR%\dependencies\git\cmd\git.exe" set "PATH=%APP_DIR%\dependencies\git\cmd;%PATH%"rem App-internal installs (DSH_PREFER_BUNDLED_PNPM=1) use the bundled pnpm,rem falling back to the user's only when the bundled one is missing.@@ -414,6 +434,18 @@ pub fn build_pnpm_ps1_shim(app_dir: &Path) -> String {$ErrorActionPreference = "Stop"$appDir = '{app_dir}'$pnpmBin = '{pnpm_bin}'+# Use bundled MinGit only when system Git lacks its HTTPS transport helper.+$systemGitWorks = $false+try {{+ $gitExecPath = & git --exec-path 2> $null+ $systemGitWorks = ($LASTEXITCODE -eq 0) -and (Test-Path -LiteralPath (Join-Path $gitExecPath 'git-remote-https.exe'))+}} catch {{}}+if (-not $systemGitWorks) {{+ $gitDir = Join-Path $appDir 'dependencies\git\cmd'+ if (Test-Path -LiteralPath (Join-Path $gitDir 'git.exe')) {{+ $env:PATH = $gitDir + ';' + $env:PATH+ }}+}}{node_resolve}@@ -707,6 +739,31 @@ mod tests {assert!(!content.contains(r#"set "APP_DIR=C:\Users\100%test""#));}+ #[cfg(windows)]+ #[test]+ fn windows_shims_configure_bundled_git_without_shadowing_system_git() {+ let dsh_cmd = build_cmd_shim(&sample_app_dir(), &sample_dsh_home());+ let dsh_ps1 = build_ps1_shim(&sample_app_dir(), &sample_dsh_home());+ let pnpm_cmd = build_pnpm_cmd_shim(&sample_app_dir());+ let pnpm_ps1 = build_pnpm_ps1_shim(&sample_app_dir());++ for content in [&dsh_cmd, &pnpm_cmd] {+ assert!(content.contains("git --exec-path 2^>nul"));+ assert!(content.contains("git-remote-https.exe"));+ assert!(content.contains(r"dependencies\git\cmd\git.exe"));+ assert!(content.contains(r"dependencies\git\cmd;%PATH%"));+ let system_probe = content.find("git --exec-path").expect("system Git probe");+ let bundled_git = content.find(r"dependencies\git\cmd").expect("bundled Git path");+ assert!(system_probe < bundled_git);+ }+ for content in [&dsh_ps1, &pnpm_ps1] {+ assert!(content.contains("& git --exec-path 2> $null"));+ assert!(content.contains("git-remote-https.exe"));+ assert!(content.contains(r"dependencies\git\cmd"));+ assert!(content.contains("$env:PATH = $gitDir + ';' + $env:PATH"));+ }+ }+#[test]fn pnpm_cmd_shim_contains_user_precedence() {let content = build_pnpm_cmd_shim(&sample_app_dir());diff --git a/src-tauri/src/service/download/core.rs b/src-tauri/src/service/download/core.rsindex f8939efd..219036dd 100644--- a/src-tauri/src/service/download/core.rs+++ b/src-tauri/src/service/download/core.rs@@ -1062,6 +1062,10 @@ mod tests {fn download_sources_are_https_and_allowlisted() {assert!(validate_download_url("https://nodejs.org/dist/v22/file.zip").is_ok());assert!(validate_download_url("https://registry.npmjs.org/pnpm/-/pnpm.tgz").is_ok());+ assert!(validate_download_url(+ "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.2/MinGit-2.53.0.2-64-bit.zip"+ )+ .is_ok());assert!(validate_download_url("http://nodejs.org/dist/file.zip").is_err());assert!(validate_download_url("https://example.com/file.zip").is_err());// 国内镜像源(含 npmmirror 302 后的最终落地域名)diff --git a/src-tauri/src/service/download/installable.rs b/src-tauri/src/service/download/installable.rsindex dc5ac9c1..a310aee8 100644--- a/src-tauri/src/service/download/installable.rs+++ b/src-tauri/src/service/download/installable.rs@@ -79,3 +79,34 @@ impl Installable for Pnpm {config::get_pnpm_binary_path(app).exists()}}++// --- Windows Git 实现(插件的 git 托管依赖需要) ---+#[cfg(windows)]+pub struct Git;++#[cfg(windows)]+#[async_trait]+impl Installable for Git {+ fn title(&self) -> &str {+ "Git 环境"+ }++ fn get_download_url(&self) -> Result<String, String> {+ config::get_mingit_download_url()+ }++ fn get_install_path(&self, app: &AppHandle) -> PathBuf {+ config::get_mingit_install_path(app)+ }++ fn check_installed(&self, app: &AppHandle) -> bool {+ if let Some(system_git) = config::find_system_git_binary() {+ log::info!(+ "Detected usable system Git ({}), skipping bundled MinGit",+ system_git.display()+ );+ return true;+ }+ config::git_runtime_ready(app)+ }+}diff --git a/src-tauri/src/service/download/mod.rs b/src-tauri/src/service/download/mod.rsindex 91ad2186..3db86a7e 100644--- a/src-tauri/src/service/download/mod.rs+++ b/src-tauri/src/service/download/mod.rs@@ -13,6 +13,8 @@ pub use core::{// 供核心面板切换版本时使用(跨模块内部接口,不进公共 API)pub(crate) use core::{remove_dir_with_retry, rename_with_retry};pub use installable::{Dsh, Installable, Nodejs, Pnpm};+#[cfg(windows)]+pub use installable::Git;pub use progress::ProgressTracker;// GitHub API 限流冷却器:任何访问 api.github.com 的服务都应收敛到这一个入口pub use utils::github_api;diff --git a/src-tauri/src/service/plugin/install.rs b/src-tauri/src/service/plugin/install.rsindex 01936b3b..fab7b98d 100644--- a/src-tauri/src/service/plugin/install.rs+++ b/src-tauri/src/service/plugin/install.rs@@ -311,7 +311,8 @@ fn silent_install_failure_detail(missing: &[(String, PathBuf)], command_output:/// 构建 `dsh plugin` 子进程的环境变量:隔离 $DSH_HOME、关闭遥测与颜色、/// 注入预检解析出的 node 路径(`DSH_NODE`,shim 优先采用,见 shim.rs)、-/// PATH 前置 shim 目录与 node 目录;用户 pnpm 过旧时强制捆绑版(见 ensure_pnpm)。+/// PATH 前置 shim、node 与桌面端自动配置的 Git 目录;用户 pnpm 过旧时强制+/// 捆绑版(见 ensure_pnpm)。////// 供本模块的安装/升级/卸载与 [`super::verify`] 的完整性修复共用:子进程(dsh/// 或 pnpm)都按同一套桌面端环境策略运行,保证 $DSH_HOME / PATH 布局一致。@@ -352,6 +353,11 @@ pub(crate) fn build_plugin_envs(app_handle: &AppHandle, prefer_bundled_pnpm: booif let Some(node_dir) = node_abs.parent() {paths.push(node_dir.to_path_buf());}+ // pnpm 安装 github:/git+ssh: 插件时会直接调用 git。Windows 空白环境使用+ // 桌面端已校验安装的 MinGit,仅对子进程 PATH 生效,不污染用户系统 PATH。+ if let Some(git_dir) = config::get_git_cmd_dir(app_handle) {+ paths.push(git_dir);+ }paths.extend(std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default(),));diff --git a/src-tauri/src/service/workflow/mod.rs b/src-tauri/src/service/workflow/mod.rsindex 384d73df..e373cb0e 100644--- a/src-tauri/src/service/workflow/mod.rs+++ b/src-tauri/src/service/workflow/mod.rs@@ -837,8 +837,9 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {node_abs.to_string_lossy().into_owned(),);- // 扩展 PATH,让 dsh 及其子进程能找到 node;Windows 上再注入 Git Bash 的- // bin 目录:persistent bash(--noprofile --norc)不执行 profile 脚本、PATH+ // 扩展 PATH,让 dsh 及其子进程能找到 node 与桌面端自动配置的 Git;Windows+ // 上再注入 Git Bash 的 bin 目录:persistent bash(--noprofile --norc)不执行+ // profile 脚本、PATH// 完全继承服务进程,若不含 Git 的 usr/bin,ls/sed/find 等 coreutils 全会// `command not found`(MSYS 运行时在部分环境下不会自动补 /usr/bin)。// 前置应用自身的 shim 目录,使市场(dsh-market)及其子进程通过名字解析的@@ -853,6 +854,13 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {}let mut paths = vec![crate::service::cli::get_bin_dir(&app_handle)];paths.push(node_dir.to_path_buf());+ if let Some(git_dir) = config::get_git_cmd_dir(&app_handle) {+ log::debug!(+ "harness service Git PATH prepend: {}",+ git_dir.to_string_lossy()+ );+ paths.push(git_dir);+ }paths.extend(git_dirs);paths.extend(std::env::split_paths(&existing_path));if let Ok(new_path) = std::env::join_paths(paths) {@@ -1036,10 +1044,11 @@ pub fn stop_on_exit(app_handle: tauri::AppHandle, _port: u16) {let _ = fs::remove_file(harness_pid_path(&app_handle));}-/// 安装环境(Node.js 运行时 + 打包的 Harness 发行版)。+/// 安装环境(Node.js 运行时 + 打包的 Harness 发行版 + pnpm;Windows 缺失+/// 系统 Git 时再自动安装免安装 MinGit)。////// 返回是否真正落盘更新了 Harness(dsh 任务实际下载并解压);仅重装-/// Node/pnpm 或全部任务被跳过时返回 false,供调用方决定是否重启页面。+/// Node/pnpm/Git 或全部任务被跳过时返回 false,供调用方决定是否重启页面。pub async fn install(app_handle: &tauri::AppHandle,mut dsh_latest: Option<download::LatestDshPkg>,@@ -1074,13 +1083,17 @@ pub async fn install(.get_webview_window("main").ok_or("Failed to get main window")?;log::debug!("Main window obtained");- // 3 个任务 × 下载/解压 2 个阶段- let mut tracker = download::ProgressTracker::new(&window, 6);- let tasks: Vec<Box<dyn download::Installable>> = vec![+ let mut tasks: Vec<Box<dyn download::Installable>> = vec![Box::new(download::Nodejs),Box::new(download::Dsh),Box::new(download::Pnpm),];+ // Windows Sandbox 等空白环境没有 Git;仅 Windows 加入第 4 项,若系统 Git+ // 可真实执行则 Installable 会跳过,不重复下载也不修改系统 PATH。+ #[cfg(windows)]+ tasks.push(Box::new(download::Git));+ // 每项均有下载/解压两个阶段,按实际平台任务数计算,避免进度提前到 100%。+ let mut tracker = download::ProgressTracker::new(&window, tasks.len() * 2);log::info!("Task list created, {} tasks total", tasks.len());for (index, task) in tasks.iter().enumerate() {@@ -1198,6 +1211,8 @@ pub async fn install(})?}2 => config::PNPM_SHA256.to_string(),+ #[cfg(windows)]+ 3 => config::get_mingit_sha256()?.to_string(),_ => return Err("INSTALL_TASK_INVALID: unknown install task".to_string()),};download::verify_sha256(&buffer, &expected_digest)?;diff --git a/src/store/modules/harness/store.ts b/src/store/modules/harness/store.tsindex a16de6e8..f5a67a6e 100644--- a/src/store/modules/harness/store.ts+++ b/src/store/modules/harness/store.ts@@ -414,12 +414,11 @@ export const harness = defineStore({installed: boolean}>('get_app_config')- // 仅首次使用需要检测环境/安装依赖;之后直接进入页面。- // 桌面端自更新(MSI 强杀进程)后 store 可能被复位/损坏显示未安装,- // 但运行时文件已全部在盘——此时跳过安装/下载界面,install_dependencies- // 内部自愈补记 installed 后直接启动,避免自动重开时闪现误导用户的界面。- if (!config.installed) {- const ready = await invoke<boolean>('runtime_ready')+ // 每次启动都做纯本地运行时检查:旧版本升级后 installed 仍为 true,但新版+ // 可能新增依赖(如 Windows 空白环境需要的 MinGit),必须进入幂等自愈。+ // 已全部就绪时不调用安装命令,因此不会联网,也不会闪现安装界面。+ const ready = await invoke<boolean>('runtime_ready')+ if (!ready || !config.installed) {if (!ready) {this.status = 'installing'this.installer = { ...initialInstaller, title: i18next.t('status.installing') }