Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(desktop): 支持 dsh:// 深链(成功页「打开应用」按钮)

hairyf73eeebe11318
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 6111887f..c08ec3c3 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -724,6 +724,26 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "const-random"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359"
+dependencies = [
+ "const-random-macro",
+]
+
+[[package]]
+name = "const-random-macro"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
+dependencies = [
+ "getrandom 0.2.17",
+ "once_cell",
+ "tiny-keccak",
+]
+
[[package]]
name = "constant_time_eq"
version = "0.1.5"
@@ -1047,6 +1067,7 @@ dependencies = [
"tauri",
"tauri-build",
"tauri-plugin-autostart",
+ "tauri-plugin-deep-link",
"tauri-plugin-fs",
"tauri-plugin-http",
"tauri-plugin-notification",
@@ -1238,6 +1259,15 @@ dependencies = [
"syn 2.0.119",
]
+[[package]]
+name = "dlv-list"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f"
+dependencies = [
+ "const-random",
+]
+
[[package]]
name = "document-features"
version = "0.2.12"
@@ -2060,6 +2090,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+[[package]]
+name = "hashbrown"
+version = "0.14.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
+
[[package]]
name = "hashbrown"
version = "0.15.5"
@@ -2239,7 +2275,7 @@ dependencies = [
"tokio",
"tower-service",
"tracing",
- "windows-registry",
+ "windows-registry 0.6.1",
]
[[package]]
@@ -3362,6 +3398,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
+[[package]]
+name = "ordered-multimap"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79"
+dependencies = [
+ "dlv-list",
+ "hashbrown 0.14.5",
+]
+
[[package]]
name = "ordered-stream"
version = "0.2.0"
@@ -4158,6 +4204,16 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "rust-ini"
+version = "0.21.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7"
+dependencies = [
+ "cfg-if",
+ "ordered-multimap",
+]
+
[[package]]
name = "rustc-hash"
version = "2.1.3"
@@ -5084,6 +5140,27 @@ dependencies = [
"thiserror 2.0.20",
]
+[[package]]
+name = "tauri-plugin-deep-link"
+version = "2.4.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92d489b8ecceae1cd09f6e1f7606f2095ac721cc8d54cf2f0e6bb377cc52cff6"
+dependencies = [
+ "dunce",
+ "plist",
+ "rust-ini",
+ "serde",
+ "serde_json",
+ "tauri",
+ "tauri-plugin",
+ "tauri-utils",
+ "thiserror 2.0.20",
+ "tracing",
+ "url",
+ "windows-registry 0.5.3",
+ "windows-result 0.3.4",
+]
+
[[package]]
name = "tauri-plugin-fs"
version = "2.5.2"
@@ -5200,6 +5277,7 @@ dependencies = [
"serde",
"serde_json",
"tauri",
+ "tauri-plugin-deep-link",
"thiserror 2.0.20",
"tokio",
"tracing",
@@ -5480,6 +5558,15 @@ dependencies = [
"time-core",
]
+[[package]]
+name = "tiny-keccak"
+version = "2.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
+dependencies = [
+ "crunchy",
+]
+
[[package]]
name = "tinystr"
version = "0.8.4"
@@ -6513,6 +6600,17 @@ dependencies = [
"windows-link 0.1.3",
]
+[[package]]
+name = "windows-registry"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e"
+dependencies = [
+ "windows-link 0.1.3",
+ "windows-result 0.3.4",
+ "windows-strings 0.4.2",
+]
+
[[package]]
name = "windows-registry"
version = "0.6.1"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index d7f2e066..3d129bc3 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -29,7 +29,12 @@ tauri = { version = "2", features = [
# E2E:应用内嵌 WebDriver server(Tauri 官方推荐的 WebdriverIO 驱动方式)。
# 仅当进程环境带 TAURI_WEBDRIVER_PORT 时监听,正常运行不开放端口。
tauri-plugin-wdio-webdriver = "1"
-tauri-plugin-single-instance = "2"
+# `deep-link` feature:二次启动携带的 `dsh://` URL 会被转发给**主实例**并派发 open-url
+# (官方成功页「打开应用」按钮的落点)。
+tauri-plugin-single-instance = { version = "2", features = [ "deep-link" ] }
+# 深链协议注册:Windows/Linux 运行期注册、macOS 走 Info.plist(见 tauri.conf.json 的
+# `plugins.deep-link.desktop.schemes`)。官方 Electron 版用 setAsDefaultProtocolClient('dsh')。
+tauri-plugin-deep-link = "2"
tauri-plugin-opener = "2"
tauri-plugin-fs = "2"
tauri-plugin-store = "2"
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 0957c4b9..03b9dc0f 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -144,6 +144,11 @@ pub fn setup(app_handle: tauri::AppHandle) {
// 启动进程监控(tick 检测 dsh 服务状态)
crate::service::scheduler::start(&app_handle);
+ // `dsh://` 深链(成功页「打开应用」按钮):仅打包态注册协议并接管 open-url
+ // (debug 注册会把系统 `dsh:` 指向调试产物)。
+ #[cfg(not(debug_assertions))]
+ crate::desktop::deep_link::init(&app_handle);
+
// 开机自启动:已安装且开启 auto_start 时拉起服务
let app_for_start = app_handle.clone();
tauri::async_runtime::spawn(async move {
@@ -1149,6 +1154,8 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {
// 仅在生产环境(release)启用:debug 开发调试时若启用单例,
// 二次启动的调试进程会被吞掉(例如 tauri dev 多实例调试),
// 因此开发环境跳过该插件。
+ // `deep-link` feature 只在单例在场时起作用:把二次启动携带的 `dsh://` URL
+ // (成功页「打开应用」按钮)转发给主实例派发 open-url。
#[cfg(not(debug_assertions))]
let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
crate::utils::show_main_window(app);
@@ -1161,7 +1168,7 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {
#[cfg(windows)]
let builder = builder.plugin(crate::desktop::tauri_internals::shim());
- builder
+ let builder = builder
// 官方跨平台登录启动实现:Windows HKCU Run、macOS LaunchAgent、Linux XDG。
.plugin(
tauri_plugin_autostart::Builder::new()
@@ -1182,5 +1189,12 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {
.plugin(tauri_plugin_store::Builder::new().build())
// OS plugin:前端据此判断系统版本(macOS 10.15 没有 `WKWebView.pageZoom`,
// 不能把缩放应用到 WebView),见 `hooks/use-zoom-factor.ts`。
- .plugin(tauri_plugin_os::init())
+ .plugin(tauri_plugin_os::init());
+
+ // `dsh://` 深链(成功页「打开应用」按钮)只在打包态启用:debug 注册会把系统
+ // `dsh:` 指向调试产物,与官方 Electron 的 `app.isPackaged` 门禁一致。
+ #[cfg(not(debug_assertions))]
+ let builder = builder.plugin(tauri_plugin_deep_link::init());
+
+ builder
}
diff --git a/src-tauri/src/desktop/deep_link.rs b/src-tauri/src/desktop/deep_link.rs
new file mode 100644
index 00000000..91bf22f2
--- /dev/null
+++ b/src-tauri/src/desktop/deep_link.rs
@@ -0,0 +1,52 @@
+//! `dsh://` 深链:官方账号成功页的「打开应用」按钮走的就是它。
+//!
+//! 与官方 Electron 版逐字对齐:
+//! - 协议注册 `app.setAsDefaultProtocolClient('dsh')`(仅在打包态);
+//! - `open-url` 处理里**只**认 `dsh://open`(含尾斜杠)→ 把主窗口拉到前台,不做其它动作;
+//! - OAuth 回调不走深链(那是 `http://127.0.0.1:<port>/oauth/callback`)。
+//!
+//! Windows/Linux 的协议注册在运行期完成(`register_all`),因此开发态也能直接验证按钮;
+//! 打包安装器的注册由 `tauri.conf.json` 的 `plugins.deep-link.desktop.schemes` 驱动。
+
+use tauri::AppHandle;
+use tauri_plugin_deep_link::DeepLinkExt;
+
+/// 官方唯一使用的深链动作(尾斜杠形式等价)。
+pub fn is_open_request(url: &str) -> bool {
+ url == "dsh://open" || url == "dsh://open/"
+}
+
+/// 注册 `dsh` 协议并接管打开事件。最佳努力:失败只告警,不阻断启动。
+pub fn init(app: &AppHandle) {
+ #[cfg(any(windows, target_os = "linux"))]
+ if let Err(e) = app.deep_link().register_all() {
+ log::warn!("deep link register_all failed: {e}");
+ }
+
+ let handle = app.clone();
+ app.deep_link().on_open_url(move |event| {
+ for url in event.urls() {
+ if is_open_request(url.as_str()) {
+ crate::utils::show_main_window(&handle);
+ }
+ }
+ });
+}
+
+#[cfg(test)]
+mod tests {
+ use super::is_open_request;
+
+ #[test]
+ fn recognizes_the_official_open_requests() {
+ assert!(is_open_request("dsh://open"));
+ assert!(is_open_request("dsh://open/"));
+ }
+
+ #[test]
+ fn ignores_other_urls() {
+ assert!(!is_open_request("dsh://oauth/callback"));
+ assert!(!is_open_request("https://platform.deepseek.com/dsh/authorized?login_source=desktop"));
+ assert!(!is_open_request(""));
+ }
+}
diff --git a/src-tauri/src/desktop/mod.rs b/src-tauri/src/desktop/mod.rs
index 4c11e080..e9f66a4e 100644
--- a/src-tauri/src/desktop/mod.rs
+++ b/src-tauri/src/desktop/mod.rs
@@ -2,6 +2,7 @@ pub mod activation;
pub mod autostart;
pub mod builder;
pub mod compat;
+pub mod deep_link;
#[cfg(target_os = "linux")]
pub mod linux_tray;
pub mod notification;
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 82e9ff4c..9e9078cc 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -16,6 +16,13 @@
"devCsp": "default-src 'self'; connect-src 'self' ipc: http://ipc.localhost http://localhost:1420 ws://localhost:1421; img-src 'self' asset: http://asset.localhost data: blob: https://*.githubusercontent.com; media-src 'self' data: blob: https://*.githubusercontent.com; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self'; frame-src http://127.0.0.1:*"
}
},
+ "plugins": {
+ "deep-link": {
+ "desktop": {
+ "schemes": ["dsh"]
+ }
+ }
+ },
"bundle": {
"active": true,
"targets": "all",