DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(download): intercept downloads and notify the shell
hairyfac9163b2c350
diff --git a/src-tauri/src/bridge/cmd.rs b/src-tauri/src/bridge/cmd.rsindex 6e127e94..c82ab6b3 100644--- a/src-tauri/src/bridge/cmd.rs+++ b/src-tauri/src/bridge/cmd.rs@@ -197,6 +197,13 @@ pub async fn copy_service_url(app_handle: AppHandle) -> Result<(), String> {.map_err(|e| e.to_string())}+/// 在系统文件管理器中定位指定文件(Session 日志下载完成后的"在文件夹中显示")+#[tauri::command]+pub fn reveal_in_folder(path: String) -> Result<(), String> {+ tauri_plugin_opener::reveal_item_in_dir(&path)+ .map_err(|e| format!("REVEAL_FAILED: {e}"))+}+/// 在系统文件管理器中打开数据目录#[tauri::command]pub async fn reveal_data_dir(app_handle: AppHandle) -> Result<(), String> {diff --git a/src-tauri/src/config/mod.rs b/src-tauri/src/config/mod.rsindex 5b8f52a8..53ad539f 100644--- a/src-tauri/src/config/mod.rs+++ b/src-tauri/src/config/mod.rs@@ -11,3 +11,4 @@ pub use format::*;pub use runtime::*;pub use setting::*;pub use theme::*;+pub use utils::*;diff --git a/src-tauri/src/config/utils.rs b/src-tauri/src/config/utils.rsindex e8264ce8..88ebc534 100644--- a/src-tauri/src/config/utils.rs+++ b/src-tauri/src/config/utils.rs@@ -1,4 +1,43 @@-use std::path::PathBuf;+use std::path::{Path, PathBuf};++/// 生成不冲突的下载路径:目标已存在时按 `name (n).ext` 递增命名,+/// 与浏览器下载管理器的重名行为保持一致。+///+/// `destination` 是 WebView2 给出的默认保存路径(系统下载目录 + 文件名),+/// 父目录不存在时回退到 `%USERPROFILE%\Downloads`。+pub fn unique_download_path(destination: &Path) -> PathBuf {+ use std::env;++ let dir = match destination.parent() {+ Some(parent) if parent.is_dir() => parent.to_path_buf(),+ // 下载目录不存在(如被用户删除)时兜底到 USERPROFILE\Downloads+ _ => env::var("USERPROFILE")+ .map(PathBuf::from)+ .map(|home| home.join("Downloads"))+ .unwrap_or_else(|_| PathBuf::from(".")),+ };+ let name = destination+ .file_name()+ .and_then(|n| n.to_str())+ .unwrap_or("download");+ // 拆分主名与扩展名,重名时在扩展名前插入 " (n)"+ let (stem, ext) = match name.rsplit_once('.') {+ Some((stem, ext)) => (stem.to_string(), format!(".{ext}")),+ None => (name.to_string(), String::new()),+ };+ let mut counter = 0usize;+ loop {+ let candidate = if counter == 0 {+ dir.join(name)+ } else {+ dir.join(format!("{stem} ({counter}){ext}"))+ };+ if !candidate.exists() {+ return candidate;+ }+ counter += 1;+ }+}/// 递归搜索 node 二进制文件pub fn search_node_binary(dir: &PathBuf, target: &str) -> Option<PathBuf> {diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex eb4e1735..9ecc4639 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -10,9 +10,22 @@ use tauri::{ipc::Invoke,menu::{Menu, MenuEvent, MenuItem},tray::{MouseButton, TrayIconBuilder, TrayIconEvent},- Manager, Runtime, Wry,+ webview::DownloadEvent,+ Emitter, Manager, Runtime, WebviewUrl, WebviewWindowBuilder, Wry,};+/// 下载完成事件载荷:`on_download` 的 Finished 分支向前端 emit,+/// 由桌面外壳展示"已保存 + 打开文件夹"提示(iframe 内的下载对用户不可见)。+#[derive(Clone, serde::Serialize)]+struct DownloadFinishedPayload {+ /// 原始下载地址(dsh 的 /api/session.export?sessionId=...)+ url: String,+ /// 保存到本地的完整路径;失败或平台拿不到路径时为 None+ path: Option<String>,+ /// 下载是否成功+ success: bool,+}+// setup appfn setup(app_handle: tauri::AppHandle) {// 启动进程监控(tick 检测 dsh 服务状态)@@ -117,6 +130,7 @@ fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {bridge::cmd::open_in_browser,bridge::cmd::copy_service_url,bridge::cmd::reveal_data_dir,+ bridge::cmd::reveal_in_folder,bridge::cmd::read_service_logs,bridge::cmd::clear_service_logs,bridge::cmd::set_language,@@ -128,6 +142,55 @@ fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {// configure tauri builderfn builder() -> tauri::Builder<tauri::Wry> {tauri::Builder::default()+ // 主窗口在这里手动创建(不再从 tauri.conf.json 声明):+ // config 声明的窗口无法挂载 on_download,而内嵌 iframe 的 dsh 页面+ // 触发下载时 WebView2 静默保存、用户零感知,需要接管下载以给出反馈。+ .setup(|app| {+ WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))+ .title("Deepseek Harness Desktop")+ .inner_size(1280.0, 840.0)+ .min_inner_size(860.0, 620.0)+ .resizable(true)+ .decorations(true)+ .on_download(|webview, event| match event {+ DownloadEvent::Requested { url, destination } => {+ // 接管下载:保存到系统下载目录,重名时自动加 " (n)" 后缀+ *destination = config::unique_download_path(destination);+ log::info!(+ "[download] requested {} -> {}",+ url,+ destination.display()+ );+ true+ }+ DownloadEvent::Finished {+ url,+ path,+ success,+ } => {+ let path_str = path.as_ref().map(|p| p.to_string_lossy().to_string());+ let payload = DownloadFinishedPayload {+ url: url.to_string(),+ path: path_str,+ success,+ };+ let _ = webview.emit("harness-download-finished", payload);+ log::info!(+ "[download] finished {} success={} path={:?}",+ url,+ success,+ path+ );+ true+ }+ // DownloadEvent 为 #[non_exhaustive],预留未来变体+ _ => true,+ })+ .build()?;+ tray(&app.handle())?;+ setup(app.handle().clone());+ Ok(())+ })// 点击关闭按钮时隐藏到托盘而不是退出程序.on_window_event(|window, event| {if let tauri::WindowEvent::CloseRequested { api, .. } = event {@@ -151,11 +214,6 @@ pub fn run() {logger::init();builder()- .setup(|app| {- tray(&app.handle()).unwrap();- setup(app.handle().clone());- Ok(())- }).invoke_handler(handler()).build(tauri::generate_context!()).expect("error while building tauri application")diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex b878c69b..a6c4cd33 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -10,20 +10,6 @@"frontendDist": "../dist"},"app": {- "windows": [- {- "title": "Deepseek Harness Desktop",- "width": 1280,- "height": 840,- "minWidth": 860,- "minHeight": 620,- "resizable": true,- "fullscreen": false,- "maximized": false,- "decorations": true,- "dragDropEnabled": false- }- ],"security": {"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost 'self' http://127.0.0.1:* ws://127.0.0.1:*; frame-src http://127.0.0.1:*; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; script-src 'self'"}