DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor(bridge): split monolithic command module into domain modules
hairyfa02b0b1bb5bd
diff --git a/src-tauri/src/bridge/app_config.rs b/src-tauri/src/bridge/app_config.rsnew file mode 100644index 00000000..f814ad39--- /dev/null+++ b/src-tauri/src/bridge/app_config.rs@@ -0,0 +1,76 @@+//! 应用全局配置、系统偏好与 CLI Link 集成。+//!+//! 桌面端自身设置(端口/自启/语言/主题/侧边栏)的读写,以及命令行集成的+//! 状态查询;命令行集成开关的落库顺序与 CLI Link 的文件/PATH 操作绑定。++use crate::config;+use crate::service::cli;+use tauri::AppHandle;++/// 当前桌面端配置+#[tauri::command]+pub async fn get_app_config(app_handle: AppHandle) -> Result<config::Setting, String> {+ Ok(config::get_store_dat_setting(&app_handle))+}++/// 更新桌面端配置+#[tauri::command]+pub async fn update_app_config(+ app_handle: AppHandle,+ port: Option<u16>,+ auto_start: Option<bool>,+ cli_link_enabled: Option<bool>,+) -> Result<config::Setting, String> {+ let mut setting = config::get_store_dat_setting(&app_handle);+ if let Some(port) = port {+ if port == 0 {+ return Err("port must be a positive number".to_string());+ }+ setting.port = port;+ }+ if let Some(auto_start) = auto_start {+ setting.auto_start = auto_start;+ }+ // 命令行集成:先执行文件系统/PATH 操作,成功后再持久化开关,+ // 失败时配置保持不变,避免"开关已开但 shim 未生成"的不一致状态。+ if let Some(enabled) = cli_link_enabled {+ if enabled {+ cli::ensure(&app_handle)?;+ } else {+ cli::remove(&app_handle)?;+ }+ setting.cli_link_enabled = enabled;+ }+ config::set_store_dat_setting(&app_handle, setting.clone());+ Ok(setting)+}++/// 命令行集成状态(shim 文件与 PATH 注册情况)+#[tauri::command]+pub fn get_cli_link_status(app_handle: AppHandle) -> Result<cli::CliLinkStatus, String> {+ Ok(cli::get_status(&app_handle))+}++/// 保存界面语言偏好+#[tauri::command]+pub fn set_language(app_handle: AppHandle, lang: String) {+ let mut setting = config::get_store_dat_setting(&app_handle);+ setting.language = lang.clone();+ config::set_store_dat_setting(&app_handle, setting);+ config::i18n::set_language(match lang.as_str() {+ "en" | "en-US" => config::i18n::Lang::En,+ _ => config::i18n::Lang::Zh,+ });+}++/// 切换侧边栏(布局状态保存在前端,保留该命令以对齐参考实现)+#[tauri::command]+pub async fn toggle_sidebar() -> Result<bool, String> {+ Ok(true)+}++/// 当前 dsh 主题偏好(light/dark/system),用于让桌面外壳跟随内嵌页面主题+#[tauri::command]+pub fn get_dsh_theme(app_handle: AppHandle) -> config::DshTheme {+ config::get_dsh_theme(&app_handle)+}diff --git a/src-tauri/src/bridge/cmd.rs b/src-tauri/src/bridge/cmd.rsdeleted file mode 100644index 02b4e247..00000000--- a/src-tauri/src/bridge/cmd.rs+++ /dev/null@@ -1,755 +0,0 @@-use crate::config;-use crate::service::cli;-use crate::service::core;-use crate::service::download::{self, Installable};-use crate::service::plugin;-use crate::service::profile;-use crate::service::update;-use crate::service::workflow;-use tauri::AppHandle;-use tauri_plugin_clipboard_manager::ClipboardExt;-use tauri_plugin_opener::OpenerExt;--/// 按当前设置同步命令行集成(shim + PATH 注册)。-///-/// 安装/更新流程的收尾步骤,失败只记日志、不阻断主流程。-fn sync_cli_link(app_handle: &AppHandle) {- let setting = config::get_store_dat_setting(app_handle);- let result = if setting.cli_link_enabled {- cli::ensure(app_handle)- } else {- cli::remove(app_handle)- };- if let Err(e) = result {- log::warn!("cli link sync failed: {e}");- }-}--/// 一键安装依赖(Node.js 运行时 + 打包的 Harness 发行版)-///-/// 返回是否真正执行了安装/更新:`true` 表示本次调用落盘了运行时(前端-/// 需重启服务以加载新版本),`false` 表示未发生任何安装(已是最新、记录-/// 自愈,或 GitHub 限流无法校验完整性而保持本地安装——此时前端不应重启、-/// 也不应丢弃“有新版本”提示,而应提示稍后重试)。-///-/// 启动逻辑由前端显式调用 `launch_harness` 完成,避免重复拉起进程。-#[tauri::command]-pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String> {- if workflow::status::get_status() == workflow::status::Status::Installing {- log::info!("Installation process already running, skipping");- return Ok(false);- }-- // 以实际安装状态为准:本地安装与 GitHub 最新 release 的 commit hash- // 不一致时,说明上游 pkg 有更新/修复,需要自动重新下载。- let node_ok = download::Nodejs.check_installed(&app_handle);- let dsh_files_ok = download::Dsh.check_installed(&app_handle);- // pnpm 是 dsh plugin 子命令的运行时依赖(v0.3.0 起随环境安装);老版本- // 升级后 `installed` 已为 true 会跳过环境安装,捆绑 pnpm 可能从未落盘,- // 需一并纳入"已就绪"判定,缺失时由 workflow::install 按任务补齐。- let pnpm_ok = download::Pnpm.check_installed(&app_handle);-- // 启动自愈捷径:记录显示未安装、但运行时文件已全部在盘。常见于桌面端自更新- // 安装器强杀进程,或上次启动时核心文件短暂缺失被 workflow::start 复位- // `installed`(一旦复位,此后每次启动都会走进安装分支)。此时直接补记- // installed 收尾:不做联网核对、绝不整包重下——联网核对可能把「记录滞后」- // 误判为真更新,而重下整目录在 Windows 上极易破坏 node_modules(历史 issue:- // 重解压后启动报找不到 @deepseek-ai/dsh-client-ui-settings)。真更新一律由- // 启动后的 check_dsh_update 提示用户手动安装,启动路径不该自行下载。- if node_ok && dsh_files_ok && pnpm_ok {- let setting = config::get_store_dat_setting(&app_handle);- if !setting.installed {- log::info!(- "Runtime files already present although store says not installed, healing installed flag"- );- let mut setting = config::get_store_dat_setting(&app_handle);- setting.installed = true;- config::set_store_dat_setting(&app_handle, setting);- sync_cli_link(&app_handle);- return Ok(false);- }- }-- let dsh_latest = download::fetch_latest_dsh_pkg_info().await;-- // 已安装文件在盘时,用 resolve_update 甄别「记录滞后」与「真更新」:- // 记录滞后(HealUpToDate)只修正 store 记录、绝不整包重下。否则会把一个- // 可用的 node_modules 整目录删除重解压,Windows 上原生模块 DLL 锁/重解压- // 很容易留下破损安装,导致启动报找不到 @deepseek-ai/dsh-client-ui-settings- // 或 HARNESS_NOT_FOUND。仅在真更新(UpdateAvailable)时才允许重新下载。- let dsh_need_install = match &dsh_latest {- Ok(latest) if dsh_files_ok => {- let record_commit = config::get_dsh_pkg_commit(&app_handle);- let record_tag = config::get_dsh_pkg_tag(&app_handle);- let installed_version = config::get_dsh_version(&app_handle);- // 老记录没有 tag,反查 pkg 仓库 tags 列表确认记录对应的发布版本;- // 反查失败时由 resolve_update 回退到“以实际文件为准”的保守分支- let legacy_tags = if record_tag.is_none() {- download::fetch_dsh_pkg_tags().await.unwrap_or_default()- } else {- Vec::new()- };- match download::resolve_update(- record_commit.as_deref(),- record_tag.as_deref(),- installed_version.as_deref(),- latest,- &legacy_tags,- ) {- // 安装文件已是最新 release,只是记录滞后:修正记录后下次- // 启动直接走 commit 快速比对,不再误判、也绝不整包重下- download::UpdateCheck::UpToDate- | download::UpdateCheck::HealUpToDate => {- if record_commit.as_deref() != Some(latest.commit.as_str()) {- log::info!(- "Installed Harness files already at latest release, healing stale record: {} ({})",- latest.tag,- latest.commit- );- config::set_dsh_pkg_commit(&app_handle, latest.commit.clone());- config::set_dsh_pkg_tag(&app_handle, latest.tag.clone());- }- false- }- download::UpdateCheck::UpdateAvailable => {- // 有新版但 GitHub API 限流拿不到可信源码摘要时,不自动整包重下- // (无法校验完整性,Windows 上重解压还易损坏 node_modules)。- // 保持本地安装,更新提示由启动后的 check_dsh_update 给出,稍后可重试。- if latest.digest.is_none() {- log::warn!(- "New dsh release {} found but trusted digest unavailable (API rate-limited), keeping local install",- latest.tag- );- false- } else {- true- }- }- }- }- // 核心文件缺失(首次安装或目录被清空)→ 需要安装- Ok(_) => true,- Err(e) => {- // 网络不可用或 GitHub API 限流时保留本地安装,不阻塞启动- log::warn!(- "Failed to check latest dsh release info, keeping local install: {}",- e- );- !dsh_files_ok- }- };-- if node_ok && !dsh_need_install && pnpm_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 {- setting.installed = true;- config::set_store_dat_setting(&app_handle, setting);- }- sync_cli_link(&app_handle);- return Ok(false);- }-- log::info!("Dependencies missing or outdated, starting installation process");- workflow::status::set_status(workflow::status::Status::Installing);- workflow::status::emit_status(&app_handle);- // 返回 dsh 是否真正落盘更新:仅重装 Node/pnpm 或全部任务被跳过(例如- // 版本相同仅记录滞后)时为 false,前端据此决定是否重启页面/保留更新提示- let updated = workflow::install(&app_handle, dsh_latest.ok()).await?;- log::debug!("Installation completed, marked as installed");- let mut setting = config::get_store_dat_setting(&app_handle);- setting.installed = true;- config::set_store_dat_setting(&app_handle, setting);- sync_cli_link(&app_handle);- Ok(updated)-}--/// 静默检查是否有新版 Harness 可用(只查不装,供进入页面后后台调用)-///-/// 以“实际安装文件”为准核对,而不是只看本地记录:记录可能因安装时 API-/// 失败或外围途径更新而滞后于文件,此时修正记录并免打扰;同版本热修-/// (版本相同但 commit 不同)仍正常提示。-#[tauri::command]-pub async fn check_dsh_update(- app_handle: AppHandle,-) -> Result<Option<download::LatestDshPkg>, String> {- // 本地没有安装时无需提示更新- let dsh_files_ok = download::Dsh.check_installed(&app_handle);- if !dsh_files_ok {- return Ok(None);- }-- let latest = download::fetch_latest_dsh_pkg_info().await?;- let record_commit = config::get_dsh_pkg_commit(&app_handle);- let record_tag = config::get_dsh_pkg_tag(&app_handle);- let installed_version = config::get_dsh_version(&app_handle);-- // 老记录没有 tag,反查 pkg 仓库 tags 列表确认记录对应的发布版本;- // 反查失败时由 resolve_update 回退到“以实际文件为准”的保守分支- let legacy_tags = if record_tag.is_none() {- download::fetch_dsh_pkg_tags().await.unwrap_or_default()- } else {- Vec::new()- };-- match download::resolve_update(- record_commit.as_deref(),- record_tag.as_deref(),- installed_version.as_deref(),- &latest,- &legacy_tags,- ) {- download::UpdateCheck::UpToDate => Ok(None),- download::UpdateCheck::UpdateAvailable => Ok(Some(latest)),- download::UpdateCheck::HealUpToDate => {- // 安装文件已是最新 release,只是记录滞后:修正记录后下次启动- // 直接走 commit 比对快速路径,不再误报- log::info!(- "Installed Harness files already at latest release, healing stale record: {} ({})",- latest.tag,- latest.commit- );- config::set_dsh_pkg_commit(&app_handle, latest.commit.clone());- config::set_dsh_pkg_tag(&app_handle, latest.tag.clone());- Ok(None)- }- }-}--/// 启动 Harness 服务-#[tauri::command]-pub async fn launch_harness(app_handle: AppHandle) -> Result<(), String> {- workflow::launch(app_handle).await-}--/// 停止 Harness 服务-#[tauri::command]-pub async fn shutdown_harness(app_handle: AppHandle) -> Result<(), String> {- workflow::stop(app_handle).await-}--/// 重启 Harness 服务-#[tauri::command]-pub async fn restart_harness(app_handle: AppHandle) -> Result<(), String> {- workflow::restart(app_handle).await-}--/// 获取当前 Harness 服务状态-#[tauri::command]-pub fn get_dsh_status() -> workflow::status::Status {- workflow::status::get_status()-}--/// 获取预装插件列表(含已安装检测结果),首次启动引导界面渲染用-#[tauri::command]-pub async fn get_preinstall_plugins(- app_handle: AppHandle,-) -> Result<Vec<plugin::PreinstallPlugin>, String> {- Ok(plugin::list(&app_handle))-}--/// 安装选中的预装插件(`dsh plugin --profile web add <ids...>`),-/// 进程输出实时通过 `preinstall-log` 事件推送;成功后标记引导完成并记录预设指纹。-#[tauri::command]-pub async fn install_preinstall_plugins(- app_handle: AppHandle,- ids: Vec<String>,-) -> Result<(), String> {- plugin::install(&app_handle, &ids).await?;- let mut setting = config::get_store_dat_setting(&app_handle);- setting.preinstall_done = true;- if let Some(hash) = plugin::current_preset_hash(&app_handle) {- setting.preset_hash = Some(hash);- }- config::set_store_dat_setting(&app_handle, setting);- Ok(())-}--/// 取消正在进行的预装插件安装(网络抖动/限流卡住时用户点“取消”)。-#[tauri::command]-pub async fn cancel_preinstall_plugins(app_handle: AppHandle) {- plugin::cancel(&app_handle).await;-}--/// 跳过预装插件引导:记录状态与预设指纹,之后不再弹出(除非清单内容变更)-#[tauri::command]-pub async fn skip_preinstall_plugins(app_handle: AppHandle) -> Result<(), String> {- let mut setting = config::get_store_dat_setting(&app_handle);- setting.preinstall_done = true;- if let Some(hash) = plugin::current_preset_hash(&app_handle) {- setting.preset_hash = Some(hash);- }- config::set_store_dat_setting(&app_handle, setting);- Ok(())-}--/// 是否有新的预装插件需要引导:预设清单内容与上次记录不一致(或老用户无基线)。-/// 资源文件每次安装都被强制覆盖不可比对,只能比对 app-data 里记录的内容指纹。-#[tauri::command]-pub fn get_preinstall_pending(app_handle: AppHandle) -> Result<bool, String> {- Ok(plugin::preinstall_pending(&app_handle))-}--/// 在系统浏览器中打开预装插件的仓库地址(仅允许预装清单内的 id)-#[tauri::command]-pub async fn open_preinstall_repo(app_handle: AppHandle, id: String) -> Result<(), String> {- let url = plugin::repo_url_of(&app_handle, &id)- .ok_or_else(|| format!("PREINSTALL_INVALID_ID: {id}"))?;- app_handle- .opener()- .open_url(url, None::<&str>)- .map_err(|e| e.to_string())-}--/// 当前 profile 已安装插件列表(含解析后的元信息),`use-dsh-plugins` 首次加载用;-/// 之后 Rust 侧监控插件文件,变化时通过 `dsh-plugins-updated` 事件实时推送。-#[tauri::command]-pub fn get_dsh_plugins(app_handle: AppHandle) -> Vec<plugin::DshPlugin> {- plugin::watch::list(&app_handle)-}--/// 升级单个已安装插件:`dsh plugin --profile <当前档案> update <id>`,-/// 进程输出通过 `preinstall-log` 事件实时推送。-#[tauri::command]-pub async fn update_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), String> {- plugin::update(&app_handle, &id).await?;- plugin::watch::force_emit(&app_handle);- Ok(())-}--/// 卸载单个已安装插件:`dsh plugin --profile <当前档案> remove <id>`,-/// 进程输出通过 `preinstall-log` 事件实时推送。-#[tauri::command]-pub async fn remove_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), String> {- plugin::remove(&app_handle, &id).await?;- plugin::watch::force_emit(&app_handle);- Ok(())-}--/// 上报插件运行期异常(内嵌页面 / dsh-tauri 桥调用),记录后立即推送新列表。-#[tauri::command]-pub fn report_plugin_error(- app_handle: AppHandle,- id: String,- error: String,- action: Option<String>,-) -> Result<(), String> {- plugin::errors::record(&app_handle, &id, action.as_deref().unwrap_or("runtime"), &error)?;- plugin::watch::force_emit(&app_handle);- Ok(())-}--/// 档案列表($DSH_HOME/profiles 下的目录,含 active/default 标记)-#[tauri::command]-pub fn get_profiles(app_handle: AppHandle) -> Vec<profile::Profile> {- profile::list(&app_handle)-}--/// 新建档案(初始化 $DSH_HOME/profiles/<id>,web 模板)-#[tauri::command]-pub fn create_profile(app_handle: AppHandle, name: String) -> Result<profile::Profile, String> {- profile::create(&app_handle, &name)-}--/// 切换当前使用中的档案(持久化;重启服务后生效,由前端触发)-#[tauri::command]-pub fn set_active_profile(- app_handle: AppHandle,- id: String,-) -> Result<profile::Profile, String> {- profile::set_active(&app_handle, &id)-}--/// 删除档案(默认档案与使用中的档案不可删除)-#[tauri::command]-pub fn remove_profile(app_handle: AppHandle, id: String) -> Result<(), String> {- profile::remove(&app_handle, &id)-}--/// 核心列表:本地 CLI 核心 + 预打包各版本(含 active 标记与 cli path)。-/// 版本行数据源为 GitHub tags,拉取失败时降级为磁盘扫描(离线/限流仍可用)。-#[tauri::command]-pub async fn get_cores(app_handle: AppHandle) -> Vec<core::HarnessCore> {- core::list(&app_handle).await-}--/// 切换活动核心(id: `local` | `app` | `app-<tag>`;持久化 + 预打包版本目录-/// 互换;自动重启由前端负责)-#[tauri::command]-pub async fn set_active_core(- app_handle: AppHandle,- id: String,-) -> Result<core::HarnessCore, String> {- core::set_active(&app_handle, &id).await-}--/// 下载指定 tag 的预打包核心到历史槽位(不激活;切换由 `set_active_core` 完成)-#[tauri::command]-pub async fn download_core(- app_handle: AppHandle,- tag: String,-) -> Result<core::HarnessCore, String> {- core::download_version(&app_handle, &tag).await-}--/// 卸载已下载的历史版本(激活中的版本不可卸载)-#[tauri::command]-pub async fn remove_core(app_handle: AppHandle, id: String) -> Result<(), String> {- core::remove_version(&app_handle, &id).await-}--/// 通过用户包管理器 CLI 更新本地核心(npm `install -g @latest` /-/// pnpm `add -g @latest`),返回更新后的版本号。-#[tauri::command]-pub async fn update_local_core(app_handle: AppHandle) -> Result<String, String> {- core::update_local_core(app_handle).await-}---/// 健康检查(通过 Rust 代理,避免 WebView CORS 问题)-#[tauri::command]-pub async fn proxy_health_check(app_handle: AppHandle) -> Result<String, String> {- let port = config::get_store_dat_setting(&app_handle).port;- workflow::proxy_health_check(port).await-}--/// 运行时/版本/诊断信息(侧边栏展示)-#[tauri::command]-pub async fn get_runtime_info(app_handle: AppHandle) -> Result<config::RuntimeInfo, String> {- let port = config::get_store_dat_setting(&app_handle).port;- Ok(config::runtime_info(&app_handle, port))-}--/// 运行时文件是否已全部在盘(Node / Dsh / pnpm 三件套,纯本地检查、无网络)。-///-/// 判定条件与 `install_dependencies` 的「启动自愈」捷径完全一致:桌面端自更新-/// (MSI 强杀进程)后 store 可能被复位或损坏显示「未安装」,但运行时文件其实-/// 已就绪——此时前端跳过安装/下载界面,交给 install_dependencies 内部自愈-/// 补记 installed 后直接启动,避免自动重开时闪现误导用户的安装界面。-#[tauri::command]-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)-}--/// 当前桌面端配置-#[tauri::command]-pub async fn get_app_config(app_handle: AppHandle) -> Result<config::Setting, String> {- Ok(config::get_store_dat_setting(&app_handle))-}--/// 更新桌面端配置-#[tauri::command]-pub async fn update_app_config(- app_handle: AppHandle,- port: Option<u16>,- auto_start: Option<bool>,- cli_link_enabled: Option<bool>,-) -> Result<config::Setting, String> {- let mut setting = config::get_store_dat_setting(&app_handle);- if let Some(port) = port {- if port == 0 {- return Err("port must be a positive number".to_string());- }- setting.port = port;- }- if let Some(auto_start) = auto_start {- setting.auto_start = auto_start;- }- // 命令行集成:先执行文件系统/PATH 操作,成功后再持久化开关,- // 失败时配置保持不变,避免"开关已开但 shim 未生成"的不一致状态。- if let Some(enabled) = cli_link_enabled {- if enabled {- cli::ensure(&app_handle)?;- } else {- cli::remove(&app_handle)?;- }- setting.cli_link_enabled = enabled;- }- config::set_store_dat_setting(&app_handle, setting.clone());- Ok(setting)-}--/// 命令行集成状态(shim 文件与 PATH 注册情况)-#[tauri::command]-pub fn get_cli_link_status(app_handle: AppHandle) -> Result<cli::CliLinkStatus, String> {- Ok(cli::get_status(&app_handle))-}--/// 在系统浏览器中打开 Harness 界面-#[tauri::command]-pub async fn open_in_browser(app_handle: AppHandle) -> Result<(), String> {- let url = config::get_dsh_service_url(config::get_store_dat_setting(&app_handle).port);- app_handle- .opener()- .open_url(url, None::<&str>)- .map_err(|e| e.to_string())-}--/// 复制 Harness 服务地址到剪贴板-#[tauri::command]-pub async fn copy_service_url(app_handle: AppHandle) -> Result<(), String> {- let url = config::get_dsh_service_url(config::get_store_dat_setting(&app_handle).port);- app_handle- .clipboard()- .write_text(url)- .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}"))-}--/// 在系统文件管理器中打开指定目录(核心版本「打开目录」按钮;目录用 open 而非-/// reveal——reveal 是定位父目录,open 是直接打开该目录本身)。-#[tauri::command]-pub fn open_dir(path: String) -> Result<(), String> {- tauri_plugin_opener::open_path(&path, None::<&str>)- .map_err(|e| format!("OPEN_DIR_FAILED: {e}"))-}--/// 在系统文件管理器中打开数据目录(官方 $DSH_HOME,即 ~/.dsh)-#[tauri::command]-pub async fn reveal_data_dir(app_handle: AppHandle) -> Result<(), String> {- let dsh_home = config::get_dsh_data_path(&app_handle);- // 目录可能尚未创建(全新安装),先建好再打开,避免资源管理器报路径不存在- std::fs::create_dir_all(&dsh_home).map_err(|e| e.to_string())?;-- if cfg!(windows) {- std::process::Command::new("explorer")- .arg(&dsh_home)- .spawn()- .map_err(|e| e.to_string())?;- } else if cfg!(target_os = "macos") {- std::process::Command::new("open")- .arg(&dsh_home)- .spawn()- .map_err(|e| e.to_string())?;- } else {- std::process::Command::new("xdg-open")- .arg(&dsh_home)- .spawn()- .map_err(|e| e.to_string())?;- }- Ok(())-}--/// 前端日志透传:前端 `console.*` 劫持经此命令落盘到 `desktop.frontdesk.log`-/// (与持有后端 + `dsh` target 的 `desktop.log` 分离),见 `logger/mod.rs`。-#[tauri::command]-pub fn log_frontend(level: String, target: String, message: String) {- let lvl = crate::logger::FrontendLevel::from_str(&level);- crate::logger::log_frontend(lvl, &target, &message);-}--/// 读取 dsh 服务日志-#[tauri::command]-pub async fn read_service_logs(- app_handle: AppHandle,- max_bytes: Option<usize>,-) -> Result<String, String> {- let log_path = config::get_service_log_path(&app_handle);- if !log_path.exists() {- return Ok(String::new());- }-- let content = std::fs::read_to_string(&log_path).map_err(|e| e.to_string())?;- let max_bytes = max_bytes.unwrap_or(64 * 1024);- if content.len() <= max_bytes {- Ok(content)- } else {- Ok(content[content.len() - max_bytes..].to_string())- }-}--/// 清空 dsh 服务日志-#[tauri::command]-pub async fn clear_service_logs(app_handle: AppHandle) -> Result<(), String> {- let log_path = config::get_service_log_path(&app_handle);- std::fs::write(&log_path, "").map_err(|e| e.to_string())-}--/// 读取运行日志(DSH 服务日志 + 桌面端 Rust 运行日志),格式化为便于-/// 反馈/报障复制的纯文本块:`### 环境信息`、`### 服务日志`、`### 前台日志`-/// 与 `### 后台日志` 四段。-///-/// 服务日志来自 `logs/dsh-web.log`(debug 构建为 `logs/dsh-web.dev.log`);-/// 运行日志来自 `logs/desktop.log`(桌面端自身 `logger::init` 每次启动落盘,-/// 见 logger/mod.rs)。前端 `console.*` 已在 logger 的文件层按 `target: "frontend"`-/// 跳过、不会写入 `desktop.log`(见 logger/mod.rs),因此「后台日志」取的是纯后端-/// `log::*`;仅对旧版本已落盘、尚未轮转掉的 `frontend:` 行做一次兜底剔除。据此把-/// 「运行日志」拆成:-/// - `### 前台日志`:取自前端独立文件 `logs/desktop.frontdesk.log`-/// (`logger::init` 单独落盘,见 logger/mod.rs),仅含前端 `console.*`;-/// - `### 后台日志`:取自 `logs/desktop.log`,剔除残余 `target: "frontend"` 行,-/// 仅保留后端 `log::*`。-/// 每段取末尾最多 `MAX_LINES` 行(前端日志量大,仅取一半 `FRONTEND_MAX_LINES`),-/// 避免粘贴内容超出 GitHub issue 长度上限。-#[tauri::command]-pub async fn read_run_logs(app_handle: AppHandle) -> Result<String, String> {- const MAX_LINES: usize = 100;- // 前端日志量大,复制的行数减半(避免粘贴内容过长);后端仍取满 MAX_LINES- const FRONTEND_MAX_LINES: usize = MAX_LINES / 2;-- let base = config::get_base_dir(&app_handle);- let service = config::get_service_log_path(&app_handle);- let desktop = base.join("logs").join("desktop.log");- let frontend = base.join("logs").join("desktop.frontdesk.log");-- let read_tail = |path: &std::path::Path, max_lines: usize| -> String {- if !path.exists() {- return String::new();- }- let content = std::fs::read_to_string(path).unwrap_or_default();- let lines: Vec<&str> = content.lines().collect();- let start = lines.len().saturating_sub(max_lines);- lines[start..].join("\n")- };-- // 后端尾行:先剔除 `target: "frontend"` 的行,再取末尾,避免前端日志把后端日志挤没- let read_backend_tail = |path: &std::path::Path, max_lines: usize| -> String {- if !path.exists() {- return String::new();- }- let content = std::fs::read_to_string(path).unwrap_or_default();- let lines: Vec<&str> = content- .lines()- .filter(|line| !is_frontend_log_line(line))- .collect();- let start = lines.len().saturating_sub(max_lines);- lines[start..].join("\n")- };-- // 环境信息:桌面端应用版本、dsh 发行版本、Node 版本与系统平台/架构,便于报障时快速定位环境差异- let dsh_version = config::get_dsh_version(&app_handle)- .map(|v| format!("dsh: {v}\n"))- .unwrap_or_default();- let env_text = format!(- "app: {}\n{}node: {}\nos: {} ({})",- app_handle.package_info().version,- dsh_version,- config::get_active_node_version(),- std::env::consts::OS,- std::env::consts::ARCH,- );-- let service_text = read_tail(&service, MAX_LINES);- let frontend_text = read_tail(&frontend, FRONTEND_MAX_LINES);- let backend_text = read_backend_tail(&desktop, MAX_LINES);-- Ok(format!(- "### 环境信息\n\n{}\n\n### 服务日志\n\n```\n{}\n```\n\n### 前台日志\n\n```\n{}\n```\n\n### 后台日志\n\n```\n{}\n```",- env_text,- service_text.trim_end(),- frontend_text.trim_end(),- backend_text.trim_end()- ))-}--/// 判断某行是否为前端日志(`target: "frontend"`)。-/// 日志行格式见 logger/mod.rs:`[ts] LEVEL target: message`(时间戳可能含空格)。-/// 前端行的 target 恒为 `frontend`,紧跟 LEVEL 之后;用「LEVEL + frontend:」定位,-/// 避免把消息正文里出现的 "frontend" 误判为前端日志。-fn is_frontend_log_line(line: &str) -> bool {- const LEVELS: [&str; 5] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];- let trimmed = line.trim_start();- LEVELS- .iter()- .any(|lvl| trimmed.contains(&format!("{lvl} frontend:")))-}--/// 保存界面语言偏好-#[tauri::command]-pub fn set_language(app_handle: AppHandle, lang: String) {- let mut setting = config::get_store_dat_setting(&app_handle);- setting.language = lang.clone();- config::set_store_dat_setting(&app_handle, setting);- config::i18n::set_language(match lang.as_str() {- "en" | "en-US" => config::i18n::Lang::En,- _ => config::i18n::Lang::Zh,- });-}--/// 切换侧边栏(布局状态保存在前端,保留该命令以对齐参考实现)-#[tauri::command]-pub async fn toggle_sidebar() -> Result<bool, String> {- Ok(true)-}--/// 当前 dsh 主题偏好(light/dark/system),用于让桌面外壳跟随内嵌页面主题-#[tauri::command]-pub fn get_dsh_theme(app_handle: AppHandle) -> config::DshTheme {- config::get_dsh_theme(&app_handle)-}--/// 检查桌面端自身是否有新版本(含安装包是否已下载)-#[tauri::command]-pub async fn check_desktop_update(- app_handle: AppHandle,-) -> Result<Option<update::DesktopUpdateInfo>, String> {- update::check(&app_handle).await-}--/// 下载桌面端新版本安装包;已下载则直接返回。进度通过 `desktop-update-progress` 事件推送-#[tauri::command]-pub async fn download_desktop_update(- app_handle: AppHandle,-) -> Result<update::DesktopUpdateInfo, String> {- update::download(&app_handle).await-}--/// 打开已下载的桌面端安装包(exe/msi/dmg...,交给系统默认处理器)-#[tauri::command]-pub async fn open_desktop_installer(app_handle: AppHandle, path: String) -> Result<(), String> {- update::open_installer(&app_handle, path).await-}--/// 关于对话框信息(版本 / 发布时间 / 版权 / 仓库)-#[tauri::command]-pub async fn get_desktop_about() -> Result<update::DesktopAboutInfo, String> {- Ok(update::about().await)-}--/// 在系统浏览器中打开任意 http(s) 链接(更新说明 / 关于对话框仓库链接等)-#[tauri::command]-pub async fn open_external_url(app_handle: AppHandle, url: String) -> Result<(), String> {- if !(url.starts_with("https://") || url.starts_with("http://")) {- return Err(format!("EXTERNAL_URL_INVALID: {url}"));- }- app_handle- .opener()- .open_url(url, None::<&str>)- .map_err(|e| e.to_string())-}--#[cfg(test)]-mod tests {- use super::is_frontend_log_line;-- #[test]- fn frontend_line_detected() {- // tracing 文件层(desktop.log)与前端独立文件(desktop.frontdesk.log)两种时间戳格式都应命中- assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z INFO frontend: [tag] message"));- assert!(is_frontend_log_line("[2024-06-01 12:00:00.123Z] INFO frontend: message"));- assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z WARN frontend: something"));- assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z ERROR frontend: boom"));- }-- #[test]- fn backend_line_not_detected() {- // 后端(dsh 等 target)不应误判为前端;消息正文里出现 "frontend" 也不应命中- assert!(!is_frontend_log_line("2024-06-01 12:00:00.123Z INFO dsh: starting server"));- assert!(!is_frontend_log_line("[2024-06-01 12:00:00.123Z] INFO dsh: emit to frontend: 3"));- assert!(!is_frontend_log_line("2024-06-01 12:00:00.123Z DEBUG reqwest: GET /ping"));- }-- #[test]- fn frontend_level_padding_and_extra_spaces() {- // 级别可能带前导空格(`{:>5}` 或 tracing 层多空格),frontend 目标仍应命中- assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z INFO frontend: padded"));- }-}diff --git a/src-tauri/src/bridge/core.rs b/src-tauri/src/bridge/core.rsnew file mode 100644index 00000000..df511965--- /dev/null+++ b/src-tauri/src/bridge/core.rs@@ -0,0 +1,46 @@+//! Harness Core 多版本与本地核心切换。+//!+//! 管理本地 CLI 核心与预打包的各个发布版本,支持切换活动核心、下载历史版本+//! 到槽位、卸载已下载的历史版本,以及通过用户包管理器 CLI 更新本地核心。++use crate::service::core;+use tauri::AppHandle;++/// 核心列表:本地 CLI 核心 + 预打包各版本(含 active 标记与 cli path)。+/// 版本行数据源为 GitHub tags,拉取失败时降级为磁盘扫描(离线/限流仍可用)。+#[tauri::command]+pub async fn get_cores(app_handle: AppHandle) -> Vec<core::HarnessCore> {+ core::list(&app_handle).await+}++/// 切换活动核心(id: `local` | `app` | `app-<tag>`;持久化 + 预打包版本目录+/// 互换;自动重启由前端负责)+#[tauri::command]+pub async fn set_active_core(+ app_handle: AppHandle,+ id: String,+) -> Result<core::HarnessCore, String> {+ core::set_active(&app_handle, &id).await+}++/// 下载指定 tag 的预打包核心到历史槽位(不激活;切换由 `set_active_core` 完成)+#[tauri::command]+pub async fn download_core(+ app_handle: AppHandle,+ tag: String,+) -> Result<core::HarnessCore, String> {+ core::download_version(&app_handle, &tag).await+}++/// 卸载已下载的历史版本(激活中的版本不可卸载)+#[tauri::command]+pub async fn remove_core(app_handle: AppHandle, id: String) -> Result<(), String> {+ core::remove_version(&app_handle, &id).await+}++/// 通过用户包管理器 CLI 更新本地核心(npm `install -g @latest` /+/// pnpm `add -g @latest`),返回更新后的版本号。+#[tauri::command]+pub async fn update_local_core(app_handle: AppHandle) -> Result<String, String> {+ core::update_local_core(app_handle).await+}diff --git a/src-tauri/src/bridge/lifecycle.rs b/src-tauri/src/bridge/lifecycle.rsnew file mode 100644index 00000000..bd8e6f02--- /dev/null+++ b/src-tauri/src/bridge/lifecycle.rs@@ -0,0 +1,253 @@+//! 依赖安装、自愈与 Harness 服务生命周期管理。+//!+//! 覆盖三块:依赖(Node.js / 打包 Harness / pnpm)的安装与「记录滞后」自愈、+//! Harness 服务进程的启停与状态查询,以及运行时三件套的就绪判断。++use crate::config;+use crate::service::cli;+use crate::service::download::{self, Installable};+use crate::service::workflow;+use tauri::AppHandle;++/// 按当前设置同步命令行集成(shim + PATH 注册)。+///+/// 安装/更新流程的收尾步骤,失败只记日志、不阻断主流程。+fn sync_cli_link(app_handle: &AppHandle) {+ let setting = config::get_store_dat_setting(app_handle);+ let result = if setting.cli_link_enabled {+ cli::ensure(app_handle)+ } else {+ cli::remove(app_handle)+ };+ if let Err(e) = result {+ log::warn!("cli link sync failed: {e}");+ }+}++/// 一键安装依赖(Node.js 运行时 + 打包的 Harness 发行版)+///+/// 返回是否真正执行了安装/更新:`true` 表示本次调用落盘了运行时(前端+/// 需重启服务以加载新版本),`false` 表示未发生任何安装(已是最新、记录+/// 自愈,或 GitHub 限流无法校验完整性而保持本地安装——此时前端不应重启、+/// 也不应丢弃“有新版本”提示,而应提示稍后重试)。+///+/// 启动逻辑由前端显式调用 `launch_harness` 完成,避免重复拉起进程。+#[tauri::command]+pub async fn install_dependencies(app_handle: AppHandle) -> Result<bool, String> {+ if workflow::status::get_status() == workflow::status::Status::Installing {+ log::info!("Installation process already running, skipping");+ return Ok(false);+ }++ // 以实际安装状态为准:本地安装与 GitHub 最新 release 的 commit hash+ // 不一致时,说明上游 pkg 有更新/修复,需要自动重新下载。+ let node_ok = download::Nodejs.check_installed(&app_handle);+ let dsh_files_ok = download::Dsh.check_installed(&app_handle);+ // pnpm 是 dsh plugin 子命令的运行时依赖(v0.3.0 起随环境安装);老版本+ // 升级后 `installed` 已为 true 会跳过环境安装,捆绑 pnpm 可能从未落盘,+ // 需一并纳入"已就绪"判定,缺失时由 workflow::install 按任务补齐。+ let pnpm_ok = download::Pnpm.check_installed(&app_handle);++ // 启动自愈捷径:记录显示未安装、但运行时文件已全部在盘。常见于桌面端自更新+ // 安装器强杀进程,或上次启动时核心文件短暂缺失被 workflow::start 复位+ // `installed`(一旦复位,此后每次启动都会走进安装分支)。此时直接补记+ // installed 收尾:不做联网核对、绝不整包重下——联网核对可能把「记录滞后」+ // 误判为真更新,而重下整目录在 Windows 上极易破坏 node_modules(历史 issue:+ // 重解压后启动报找不到 @deepseek-ai/dsh-client-ui-settings)。真更新一律由+ // 启动后的 check_dsh_update 提示用户手动安装,启动路径不该自行下载。+ if node_ok && dsh_files_ok && pnpm_ok {+ let setting = config::get_store_dat_setting(&app_handle);+ if !setting.installed {+ log::info!(+ "Runtime files already present although store says not installed, healing installed flag"+ );+ let mut setting = config::get_store_dat_setting(&app_handle);+ setting.installed = true;+ config::set_store_dat_setting(&app_handle, setting);+ sync_cli_link(&app_handle);+ return Ok(false);+ }+ }++ let dsh_latest = download::fetch_latest_dsh_pkg_info().await;++ // 已安装文件在盘时,用 resolve_update 甄别「记录滞后」与「真更新」:+ // 记录滞后(HealUpToDate)只修正 store 记录、绝不整包重下。否则会把一个+ // 可用的 node_modules 整目录删除重解压,Windows 上原生模块 DLL 锁/重解压+ // 很容易留下破损安装,导致启动报找不到 @deepseek-ai/dsh-client-ui-settings+ // 或 HARNESS_NOT_FOUND。仅在真更新(UpdateAvailable)时才允许重新下载。+ let dsh_need_install = match &dsh_latest {+ Ok(latest) if dsh_files_ok => {+ let record_commit = config::get_dsh_pkg_commit(&app_handle);+ let record_tag = config::get_dsh_pkg_tag(&app_handle);+ let installed_version = config::get_dsh_version(&app_handle);+ // 老记录没有 tag,反查 pkg 仓库 tags 列表确认记录对应的发布版本;+ // 反查失败时由 resolve_update 回退到“以实际文件为准”的保守分支+ let legacy_tags = if record_tag.is_none() {+ download::fetch_dsh_pkg_tags().await.unwrap_or_default()+ } else {+ Vec::new()+ };+ match download::resolve_update(+ record_commit.as_deref(),+ record_tag.as_deref(),+ installed_version.as_deref(),+ latest,+ &legacy_tags,+ ) {+ // 安装文件已是最新 release,只是记录滞后:修正记录后下次+ // 启动直接走 commit 快速比对,不再误判、也绝不整包重下+ download::UpdateCheck::UpToDate+ | download::UpdateCheck::HealUpToDate => {+ if record_commit.as_deref() != Some(latest.commit.as_str()) {+ log::info!(+ "Installed Harness files already at latest release, healing stale record: {} ({})",+ latest.tag,+ latest.commit+ );+ config::set_dsh_pkg_commit(&app_handle, latest.commit.clone());+ config::set_dsh_pkg_tag(&app_handle, latest.tag.clone());+ }+ false+ }+ download::UpdateCheck::UpdateAvailable => {+ // 有新版但 GitHub API 限流拿不到可信源码摘要时,不自动整包重下+ // (无法校验完整性,Windows 上重解压还易损坏 node_modules)。+ // 保持本地安装,更新提示由启动后的 check_dsh_update 给出,稍后可重试。+ if latest.digest.is_none() {+ log::warn!(+ "New dsh release {} found but trusted digest unavailable (API rate-limited), keeping local install",+ latest.tag+ );+ false+ } else {+ true+ }+ }+ }+ }+ // 核心文件缺失(首次安装或目录被清空)→ 需要安装+ Ok(_) => true,+ Err(e) => {+ // 网络不可用或 GitHub API 限流时保留本地安装,不阻塞启动+ log::warn!(+ "Failed to check latest dsh release info, keeping local install: {}",+ e+ );+ !dsh_files_ok+ }+ };++ if node_ok && !dsh_need_install && pnpm_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 {+ setting.installed = true;+ config::set_store_dat_setting(&app_handle, setting);+ }+ sync_cli_link(&app_handle);+ return Ok(false);+ }++ log::info!("Dependencies missing or outdated, starting installation process");+ workflow::status::set_status(workflow::status::Status::Installing);+ workflow::status::emit_status(&app_handle);+ // 返回 dsh 是否真正落盘更新:仅重装 Node/pnpm 或全部任务被跳过(例如+ // 版本相同仅记录滞后)时为 false,前端据此决定是否重启页面/保留更新提示+ let updated = workflow::install(&app_handle, dsh_latest.ok()).await?;+ log::debug!("Installation completed, marked as installed");+ let mut setting = config::get_store_dat_setting(&app_handle);+ setting.installed = true;+ config::set_store_dat_setting(&app_handle, setting);+ sync_cli_link(&app_handle);+ Ok(updated)+}++/// 静默检查是否有新版 Harness 可用(只查不装,供进入页面后后台调用)+///+/// 以“实际安装文件”为准核对,而不是只看本地记录:记录可能因安装时 API+/// 失败或外围途径更新而滞后于文件,此时修正记录并免打扰;同版本热修+/// (版本相同但 commit 不同)仍正常提示。+#[tauri::command]+pub async fn check_dsh_update(+ app_handle: AppHandle,+) -> Result<Option<download::LatestDshPkg>, String> {+ // 本地没有安装时无需提示更新+ let dsh_files_ok = download::Dsh.check_installed(&app_handle);+ if !dsh_files_ok {+ return Ok(None);+ }++ let latest = download::fetch_latest_dsh_pkg_info().await?;+ let record_commit = config::get_dsh_pkg_commit(&app_handle);+ let record_tag = config::get_dsh_pkg_tag(&app_handle);+ let installed_version = config::get_dsh_version(&app_handle);++ // 老记录没有 tag,反查 pkg 仓库 tags 列表确认记录对应的发布版本;+ // 反查失败时由 resolve_update 回退到“以实际文件为准”的保守分支+ let legacy_tags = if record_tag.is_none() {+ download::fetch_dsh_pkg_tags().await.unwrap_or_default()+ } else {+ Vec::new()+ };++ match download::resolve_update(+ record_commit.as_deref(),+ record_tag.as_deref(),+ installed_version.as_deref(),+ &latest,+ &legacy_tags,+ ) {+ download::UpdateCheck::UpToDate => Ok(None),+ download::UpdateCheck::UpdateAvailable => Ok(Some(latest)),+ download::UpdateCheck::HealUpToDate => {+ // 安装文件已是最新 release,只是记录滞后:修正记录后下次启动+ // 直接走 commit 比对快速路径,不再误报+ log::info!(+ "Installed Harness files already at latest release, healing stale record: {} ({})",+ latest.tag,+ latest.commit+ );+ config::set_dsh_pkg_commit(&app_handle, latest.commit.clone());+ config::set_dsh_pkg_tag(&app_handle, latest.tag.clone());+ Ok(None)+ }+ }+}++/// 启动 Harness 服务+#[tauri::command]+pub async fn launch_harness(app_handle: AppHandle) -> Result<(), String> {+ workflow::launch(app_handle).await+}++/// 停止 Harness 服务+#[tauri::command]+pub async fn shutdown_harness(app_handle: AppHandle) -> Result<(), String> {+ workflow::stop(app_handle).await+}++/// 重启 Harness 服务+#[tauri::command]+pub async fn restart_harness(app_handle: AppHandle) -> Result<(), String> {+ workflow::restart(app_handle).await+}++/// 获取当前 Harness 服务状态+#[tauri::command]+pub fn get_dsh_status() -> workflow::status::Status {+ workflow::status::get_status()+}++/// 运行时文件是否已全部在盘(Node / Dsh / pnpm 三件套,纯本地检查、无网络)。+///+/// 判定条件与 `install_dependencies` 的「启动自愈」捷径完全一致:桌面端自更新+/// (MSI 强杀进程)后 store 可能被复位或损坏显示「未安装」,但运行时文件其实+/// 已就绪——此时前端跳过安装/下载界面,交给 install_dependencies 内部自愈+/// 补记 installed 后直接启动,避免自动重开时闪现误导用户的安装界面。+#[tauri::command]+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)+}diff --git a/src-tauri/src/bridge/mod.rs b/src-tauri/src/bridge/mod.rsindex 52958ec9..93bcedd2 100644--- a/src-tauri/src/bridge/mod.rs+++ b/src-tauri/src/bridge/mod.rs@@ -1 +1,21 @@-pub mod cmd;+//! bridge:Tauri 命令的对外出口。+//!+//! 按领域把命令拆成若干子模块(生命周期 / 插件 / 核心 / 档案 / 应用配置 /+//! 系统集成 / 更新),此处统一声明并重导出为「干净 API」,供 `generate_handler!`+//! 以 `crate::bridge::<cmd>` 形式注册。++pub mod app_config;+pub mod core;+pub mod lifecycle;+pub mod plugin;+pub mod profile;+pub mod system_os;+pub mod updater;++pub use app_config::*;+pub use core::*;+pub use lifecycle::*;+pub use plugin::*;+pub use profile::*;+pub use system_os::*;+pub use updater::*;diff --git a/src-tauri/src/bridge/plugin.rs b/src-tauri/src/bridge/plugin.rsnew file mode 100644index 00000000..070e1d05--- /dev/null+++ b/src-tauri/src/bridge/plugin.rs@@ -0,0 +1,109 @@+//! 预装与已安装插件的增删改查、管理。+//!+//! 包括首次启动的预装插件引导(安装/取消/跳过/待办检测/打开仓库)、已安装+//! 插件的列表/升级/卸载,以及运行期异常的记录与「卸除此插件并继续检测」修复。++use crate::config;+use crate::service::plugin;+use tauri::AppHandle;+use tauri::Emitter;+use tauri_plugin_opener::OpenerExt;++/// 获取预装插件列表(含已安装检测结果),首次启动引导界面渲染用+#[tauri::command]+pub async fn get_preinstall_plugins(+ app_handle: AppHandle,+) -> Result<Vec<plugin::PreinstallPlugin>, String> {+ Ok(plugin::list(&app_handle))+}++/// 安装选中的预装插件(`dsh plugin --profile web add <ids...>`),+/// 进程输出实时通过 `preinstall-log` 事件推送;成功后标记引导完成并记录预设指纹。+#[tauri::command]+pub async fn install_preinstall_plugins(+ app_handle: AppHandle,+ ids: Vec<String>,+) -> Result<(), String> {+ plugin::install(&app_handle, &ids).await?;+ let mut setting = config::get_store_dat_setting(&app_handle);+ setting.preinstall_done = true;+ if let Some(hash) = plugin::current_preset_hash(&app_handle) {+ setting.preset_hash = Some(hash);+ }+ config::set_store_dat_setting(&app_handle, setting);+ Ok(())+}++/// 取消正在进行的预装插件安装(网络抖动/限流卡住时用户点“取消”)。+#[tauri::command]+pub async fn cancel_preinstall_plugins(app_handle: AppHandle) {+ plugin::cancel(&app_handle).await;+}++/// 跳过预装插件引导:记录状态与预设指纹,之后不再弹出(除非清单内容变更)+#[tauri::command]+pub async fn skip_preinstall_plugins(app_handle: AppHandle) -> Result<(), String> {+ let mut setting = config::get_store_dat_setting(&app_handle);+ setting.preinstall_done = true;+ if let Some(hash) = plugin::current_preset_hash(&app_handle) {+ setting.preset_hash = Some(hash);+ }+ config::set_store_dat_setting(&app_handle, setting);+ Ok(())+}++/// 是否有新的预装插件需要引导:预设清单内容与上次记录不一致(或老用户无基线)。+/// 资源文件每次安装都被强制覆盖不可比对,只能比对 app-data 里记录的内容指纹。+#[tauri::command]+pub fn get_preinstall_pending(app_handle: AppHandle) -> Result<bool, String> {+ Ok(plugin::preinstall_pending(&app_handle))+}++/// 在系统浏览器中打开预装插件的仓库地址(仅允许预装清单内的 id)+#[tauri::command]+pub async fn open_preinstall_repo(app_handle: AppHandle, id: String) -> Result<(), String> {+ let url = plugin::repo_url_of(&app_handle, &id)+ .ok_or_else(|| format!("PREINSTALL_INVALID_ID: {id}"))?;+ app_handle+ .opener()+ .open_url(url, None::<&str>)+ .map_err(|e| e.to_string())+}++/// 当前 profile 已安装插件列表(含解析后的元信息),`use-dsh-plugins` 首次加载用;+/// 之后 Rust 侧监控插件文件,变化时通过 `dsh-plugins-updated` 事件实时推送。+#[tauri::command]+pub fn get_dsh_plugins(app_handle: AppHandle) -> Vec<plugin::DshPlugin> {+ plugin::watch::list(&app_handle)+}++/// 升级单个已安装插件:`dsh plugin --profile <当前档案> update <id>`,+/// 进程输出通过 `preinstall-log` 事件实时推送。+#[tauri::command]+pub async fn update_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), String> {+ plugin::update(&app_handle, &id).await?;+ plugin::watch::force_emit(&app_handle);+ Ok(())+}++/// 卸载单个已安装插件:`dsh plugin --profile <当前档案> remove <id>`,+/// 进程输出通过 `preinstall-log` 事件实时推送。+#[tauri::command]+pub async fn remove_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), String> {+ plugin::remove(&app_handle, &id).await?;+ plugin::watch::force_emit(&app_handle);+ Ok(())+}++/// 上报插件运行期异常(内嵌页面 / dsh-tauri 桥调用),记录后立即推送新列表。+#[tauri::command]+pub fn report_plugin_error(+ app_handle: AppHandle,+ id: String,+ error: String,+ action: Option<String>,+) -> Result<(), String> {+ plugin::errors::record(&app_handle, &id, action.as_deref().unwrap_or("runtime"), &error)?;+ plugin::watch::force_emit(&app_handle);+ Ok(())+}diff --git a/src-tauri/src/bridge/profile.rs b/src-tauri/src/bridge/profile.rsnew file mode 100644index 00000000..08421de9--- /dev/null+++ b/src-tauri/src/bridge/profile.rs@@ -0,0 +1,34 @@+//! 多 Profile 环境隔离。+//!+//! 管理 `$DSH_HOME/profiles` 下的档案:列表、创建(web 模板)、切换当前使用中的+//! 档案,以及删除(默认档案与使用中的档案不可删除)。++use crate::service::profile;+use tauri::AppHandle;++/// 档案列表($DSH_HOME/profiles 下的目录,含 active/default 标记)+#[tauri::command]+pub fn get_profiles(app_handle: AppHandle) -> Vec<profile::Profile> {+ profile::list(&app_handle)+}++/// 新建档案(初始化 $DSH_HOME/profiles/<id>,web 模板)+#[tauri::command]+pub fn create_profile(app_handle: AppHandle, name: String) -> Result<profile::Profile, String> {+ profile::create(&app_handle, &name)+}++/// 切换当前使用中的档案(持久化;重启服务后生效,由前端触发)+#[tauri::command]+pub fn set_active_profile(+ app_handle: AppHandle,+ id: String,+) -> Result<profile::Profile, String> {+ profile::set_active(&app_handle, &id)+}++/// 删除档案(默认档案与使用中的档案不可删除)+#[tauri::command]+pub fn remove_profile(app_handle: AppHandle, id: String) -> Result<(), String> {+ profile::remove(&app_handle, &id)+}diff --git a/src-tauri/src/bridge/system_os.rs b/src-tauri/src/bridge/system_os.rsnew file mode 100644index 00000000..d26c42ac--- /dev/null+++ b/src-tauri/src/bridge/system_os.rs@@ -0,0 +1,250 @@+//! 浏览器/文件管理器唤起、日志捕获与健康检测。+//!+//! 对外部系统组件的交互:在系统浏览器打开链接、在文件管理器定位/打开目录与+//! 数据目录、复制服务地址到剪贴板;前端与后端日志的透传/读取/清空;以及通过+//! Rust 代理的服务健康检查与运行时环境诊断信息。++use crate::config;+use crate::logger;+use tauri::AppHandle;+use tauri_plugin_clipboard_manager::ClipboardExt;+use tauri_plugin_opener::OpenerExt;++/// 健康检查(通过 Rust 代理,避免 WebView CORS 问题)+#[tauri::command]+pub async fn proxy_health_check(app_handle: AppHandle) -> Result<String, String> {+ let port = config::get_store_dat_setting(&app_handle).port;+ crate::service::workflow::proxy_health_check(port).await+}++/// 运行时/版本/诊断信息(侧边栏展示)+#[tauri::command]+pub async fn get_runtime_info(app_handle: AppHandle) -> Result<config::RuntimeInfo, String> {+ let port = config::get_store_dat_setting(&app_handle).port;+ Ok(config::runtime_info(&app_handle, port))+}++/// 在系统浏览器中打开 Harness 界面+#[tauri::command]+pub async fn open_in_browser(app_handle: AppHandle) -> Result<(), String> {+ let url = config::get_dsh_service_url(config::get_store_dat_setting(&app_handle).port);+ app_handle+ .opener()+ .open_url(url, None::<&str>)+ .map_err(|e| e.to_string())+}++/// 复制 Harness 服务地址到剪贴板+#[tauri::command]+pub async fn copy_service_url(app_handle: AppHandle) -> Result<(), String> {+ let url = config::get_dsh_service_url(config::get_store_dat_setting(&app_handle).port);+ app_handle+ .clipboard()+ .write_text(url)+ .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}"))+}++/// 在系统文件管理器中打开指定目录(核心版本「打开目录」按钮;目录用 open 而非+/// reveal——reveal 是定位父目录,open 是直接打开该目录本身)。+#[tauri::command]+pub fn open_dir(path: String) -> Result<(), String> {+ tauri_plugin_opener::open_path(&path, None::<&str>)+ .map_err(|e| format!("OPEN_DIR_FAILED: {e}"))+}++/// 在系统文件管理器中打开数据目录(官方 $DSH_HOME,即 ~/.dsh)+#[tauri::command]+pub async fn reveal_data_dir(app_handle: AppHandle) -> Result<(), String> {+ let dsh_home = config::get_dsh_data_path(&app_handle);+ // 目录可能尚未创建(全新安装),先建好再打开,避免资源管理器报路径不存在+ std::fs::create_dir_all(&dsh_home).map_err(|e| e.to_string())?;++ if cfg!(windows) {+ std::process::Command::new("explorer")+ .arg(&dsh_home)+ .spawn()+ .map_err(|e| e.to_string())?;+ } else if cfg!(target_os = "macos") {+ std::process::Command::new("open")+ .arg(&dsh_home)+ .spawn()+ .map_err(|e| e.to_string())?;+ } else {+ std::process::Command::new("xdg-open")+ .arg(&dsh_home)+ .spawn()+ .map_err(|e| e.to_string())?;+ }+ Ok(())+}++/// 前端日志透传:前端 `console.*` 劫持经此命令落盘到 `desktop.frontdesk.log`+/// (与持有后端 + `dsh` target 的 `desktop.log` 分离),见 `logger/mod.rs`。+#[tauri::command]+pub fn log_frontend(level: String, target: String, message: String) {+ let lvl = logger::FrontendLevel::from_str(&level);+ logger::log_frontend(lvl, &target, &message);+}++/// 读取 dsh 服务日志+#[tauri::command]+pub async fn read_service_logs(+ app_handle: AppHandle,+ max_bytes: Option<usize>,+) -> Result<String, String> {+ let log_path = config::get_service_log_path(&app_handle);+ if !log_path.exists() {+ return Ok(String::new());+ }++ let content = std::fs::read_to_string(&log_path).map_err(|e| e.to_string())?;+ let max_bytes = max_bytes.unwrap_or(64 * 1024);+ if content.len() <= max_bytes {+ Ok(content)+ } else {+ Ok(content[content.len() - max_bytes..].to_string())+ }+}++/// 清空 dsh 服务日志+#[tauri::command]+pub async fn clear_service_logs(app_handle: AppHandle) -> Result<(), String> {+ let log_path = config::get_service_log_path(&app_handle);+ std::fs::write(&log_path, "").map_err(|e| e.to_string())+}++/// 读取运行日志(DSH 服务日志 + 桌面端 Rust 运行日志),格式化为便于+/// 反馈/报障复制的纯文本块:`### 环境信息`、`### 服务日志`、`### 前台日志`+/// 与 `### 后台日志` 四段。+///+/// 服务日志来自 `logs/dsh-web.log`(debug 构建为 `logs/dsh-web.dev.log`);+/// 运行日志来自 `logs/desktop.log`(桌面端自身 `logger::init` 每次启动落盘,+/// 见 logger/mod.rs)。前端 `console.*` 已在 logger 的文件层按 `target: "frontend"`+/// 跳过、不会写入 `desktop.log`(见 logger/mod.rs),因此「后台日志」取的是纯后端+/// `log::*`;仅对旧版本已落盘、尚未轮转掉的 `frontend:` 行做一次兜底剔除。据此把+/// 「运行日志」拆成:+/// - `### 前台日志`:取自前端独立文件 `logs/desktop.frontdesk.log`+/// (`logger::init` 单独落盘,见 logger/mod.rs),仅含前端 `console.*`;+/// - `### 后台日志`:取自 `logs/desktop.log`,剔除残余 `target: "frontend"` 行,+/// 仅保留后端 `log::*`。+/// 每段取末尾最多 `MAX_LINES` 行(前端日志量大,仅取一半 `FRONTEND_MAX_LINES`),+/// 避免粘贴内容超出 GitHub issue 长度上限。+#[tauri::command]+pub async fn read_run_logs(app_handle: AppHandle) -> Result<String, String> {+ const MAX_LINES: usize = 100;+ // 前端日志量大,复制的行数减半(避免粘贴内容过长);后端仍取满 MAX_LINES+ const FRONTEND_MAX_LINES: usize = MAX_LINES / 2;++ let base = config::get_base_dir(&app_handle);+ let service = config::get_service_log_path(&app_handle);+ let desktop = base.join("logs").join("desktop.log");+ let frontend = base.join("logs").join("desktop.frontdesk.log");++ let read_tail = |path: &std::path::Path, max_lines: usize| -> String {+ if !path.exists() {+ return String::new();+ }+ let content = std::fs::read_to_string(path).unwrap_or_default();+ let lines: Vec<&str> = content.lines().collect();+ let start = lines.len().saturating_sub(max_lines);+ lines[start..].join("\n")+ };++ // 后端尾行:先剔除 `target: "frontend"` 的行,再取末尾,避免前端日志把后端日志挤没+ let read_backend_tail = |path: &std::path::Path, max_lines: usize| -> String {+ if !path.exists() {+ return String::new();+ }+ let content = std::fs::read_to_string(path).unwrap_or_default();+ let lines: Vec<&str> = content+ .lines()+ .filter(|line| !is_frontend_log_line(line))+ .collect();+ let start = lines.len().saturating_sub(max_lines);+ lines[start..].join("\n")+ };++ // 环境信息:桌面端应用版本、dsh 发行版本、Node 版本与系统平台/架构,便于报障时快速定位环境差异+ let dsh_version = config::get_dsh_version(&app_handle)+ .map(|v| format!("dsh: {v}\n"))+ .unwrap_or_default();+ let env_text = format!(+ "app: {}\n{}node: {}\nos: {} ({})",+ app_handle.package_info().version,+ dsh_version,+ config::get_active_node_version(),+ std::env::consts::OS,+ std::env::consts::ARCH,+ );++ let service_text = read_tail(&service, MAX_LINES);+ let frontend_text = read_tail(&frontend, FRONTEND_MAX_LINES);+ let backend_text = read_backend_tail(&desktop, MAX_LINES);++ Ok(format!(+ "### 环境信息\n\n{}\n\n### 服务日志\n\n```\n{}\n```\n\n### 前台日志\n\n```\n{}\n```\n\n### 后台日志\n\n```\n{}\n```",+ env_text,+ service_text.trim_end(),+ frontend_text.trim_end(),+ backend_text.trim_end()+ ))+}++/// 判断某行是否为前端日志(`target: "frontend"`)。+/// 日志行格式见 logger/mod.rs:`[ts] LEVEL target: message`(时间戳可能含空格)。+/// 前端行的 target 恒为 `frontend`,紧跟 LEVEL 之后;用「LEVEL + frontend:」定位,+/// 避免把消息正文里出现的 "frontend" 误判为前端日志。+fn is_frontend_log_line(line: &str) -> bool {+ const LEVELS: [&str; 5] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];+ let trimmed = line.trim_start();+ LEVELS+ .iter()+ .any(|lvl| trimmed.contains(&format!("{lvl} frontend:")))+}++/// 在系统浏览器中打开任意 http(s) 链接(更新说明 / 关于对话框仓库链接等)+#[tauri::command]+pub async fn open_external_url(app_handle: AppHandle, url: String) -> Result<(), String> {+ if !(url.starts_with("https://") || url.starts_with("http://")) {+ return Err(format!("EXTERNAL_URL_INVALID: {url}"));+ }+ app_handle+ .opener()+ .open_url(url, None::<&str>)+ .map_err(|e| e.to_string())+}++#[cfg(test)]+mod tests {+ use super::is_frontend_log_line;++ #[test]+ fn frontend_line_detected() {+ // tracing 文件层(desktop.log)与前端独立文件(desktop.frontdesk.log)两种时间戳格式都应命中+ assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z INFO frontend: [tag] message"));+ assert!(is_frontend_log_line("[2024-06-01 12:00:00.123Z] INFO frontend: message"));+ assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z WARN frontend: something"));+ assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z ERROR frontend: boom"));+ }++ #[test]+ fn backend_line_not_detected() {+ // 后端(dsh 等 target)不应误判为前端;消息正文里出现 "frontend" 也不应命中+ assert!(!is_frontend_log_line("2024-06-01 12:00:00.123Z INFO dsh: starting server"));+ assert!(!is_frontend_log_line("[2024-06-01 12:00:00.123Z] INFO dsh: emit to frontend: 3"));+ assert!(!is_frontend_log_line("2024-06-01 12:00:00.123Z DEBUG reqwest: GET /ping"));+ }++ #[test]+ fn frontend_level_padding_and_extra_spaces() {+ // 级别可能带前导空格(`{:>5}` 或 tracing 层多空格),frontend 目标仍应命中+ assert!(is_frontend_log_line("2024-06-01 12:00:00.123Z INFO frontend: padded"));+ }+}diff --git a/src-tauri/src/bridge/updater.rs b/src-tauri/src/bridge/updater.rsnew file mode 100644index 00000000..36162d38--- /dev/null+++ b/src-tauri/src/bridge/updater.rs@@ -0,0 +1,35 @@+//! 桌面端应用自身的检查与更新。+//!+//! 检查桌面端是否有新版本、下载安装包(含进度事件推送)、打开已下载的安装包,+//! 以及关于对话框信息。++use crate::service::update;+use tauri::AppHandle;++/// 检查桌面端自身是否有新版本(含安装包是否已下载)+#[tauri::command]+pub async fn check_desktop_update(+ app_handle: AppHandle,+) -> Result<Option<update::DesktopUpdateInfo>, String> {+ update::check(&app_handle).await+}++/// 下载桌面端新版本安装包;已下载则直接返回。进度通过 `desktop-update-progress` 事件推送+#[tauri::command]+pub async fn download_desktop_update(+ app_handle: AppHandle,+) -> Result<update::DesktopUpdateInfo, String> {+ update::download(&app_handle).await+}++/// 打开已下载的桌面端安装包(exe/msi/dmg...,交给系统默认处理器)+#[tauri::command]+pub async fn open_desktop_installer(app_handle: AppHandle, path: String) -> Result<(), String> {+ update::open_installer(&app_handle, path).await+}++/// 关于对话框信息(版本 / 发布时间 / 版权 / 仓库)+#[tauri::command]+pub async fn get_desktop_about() -> Result<update::DesktopAboutInfo, String> {+ Ok(update::about().await)+}diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rsdeleted file mode 100644index b5614dd8..00000000--- a/src-tauri/src/core/mod.rs+++ /dev/null@@ -1 +0,0 @@-pub mod utils;diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rsindex f6eff7ff..3bb69f93 100644--- a/src-tauri/src/desktop/builder.rs+++ b/src-tauri/src/desktop/builder.rs@@ -10,7 +10,7 @@ use tauri::{Runtime, WebviewUrl, WebviewWindowBuilder, Wry,};-use crate::core::utils::show_main_window;+use crate::utils::show_main_window;use crate::desktop::window::{on_download, on_new_window};#[cfg(windows)]use crate::desktop::window::on_page_load;@@ -186,55 +186,55 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We// configure invoke handlerpub fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {tauri::generate_handler![- crate::bridge::cmd::install_dependencies,- crate::bridge::cmd::check_dsh_update,- crate::bridge::cmd::launch_harness,- crate::bridge::cmd::shutdown_harness,- crate::bridge::cmd::restart_harness,- crate::bridge::cmd::get_dsh_status,- crate::bridge::cmd::get_preinstall_plugins,- crate::bridge::cmd::get_preinstall_pending,- crate::bridge::cmd::install_preinstall_plugins,- crate::bridge::cmd::cancel_preinstall_plugins,- crate::bridge::cmd::skip_preinstall_plugins,- crate::bridge::cmd::open_preinstall_repo,- crate::bridge::cmd::get_dsh_plugins,- crate::bridge::cmd::update_dsh_plugin,- crate::bridge::cmd::remove_dsh_plugin,- crate::bridge::cmd::report_plugin_error,- crate::bridge::cmd::get_profiles,- crate::bridge::cmd::create_profile,- crate::bridge::cmd::set_active_profile,- crate::bridge::cmd::remove_profile,- crate::bridge::cmd::get_cores,- crate::bridge::cmd::set_active_core,- crate::bridge::cmd::download_core,- crate::bridge::cmd::remove_core,- crate::bridge::cmd::update_local_core,- crate::bridge::cmd::proxy_health_check,- crate::bridge::cmd::get_runtime_info,- crate::bridge::cmd::runtime_ready,- crate::bridge::cmd::get_app_config,- crate::bridge::cmd::update_app_config,- crate::bridge::cmd::get_cli_link_status,- crate::bridge::cmd::open_in_browser,- crate::bridge::cmd::copy_service_url,- crate::bridge::cmd::reveal_data_dir,- crate::bridge::cmd::reveal_in_folder,- crate::bridge::cmd::open_dir,- crate::bridge::cmd::read_service_logs,- crate::bridge::cmd::read_run_logs,- crate::bridge::cmd::clear_service_logs,- crate::bridge::cmd::set_language,- crate::bridge::cmd::toggle_sidebar,- crate::bridge::cmd::get_dsh_theme,- crate::bridge::cmd::check_desktop_update,- crate::bridge::cmd::download_desktop_update,- crate::bridge::cmd::open_desktop_installer,- crate::bridge::cmd::get_desktop_about,- crate::bridge::cmd::open_external_url,+ crate::bridge::install_dependencies,+ crate::bridge::check_dsh_update,+ crate::bridge::launch_harness,+ crate::bridge::shutdown_harness,+ crate::bridge::restart_harness,+ crate::bridge::get_dsh_status,+ crate::bridge::get_preinstall_plugins,+ crate::bridge::get_preinstall_pending,+ crate::bridge::install_preinstall_plugins,+ crate::bridge::cancel_preinstall_plugins,+ crate::bridge::skip_preinstall_plugins,+ crate::bridge::open_preinstall_repo,+ crate::bridge::get_dsh_plugins,+ crate::bridge::update_dsh_plugin,+ crate::bridge::remove_dsh_plugin,+ crate::bridge::report_plugin_error,+ crate::bridge::get_profiles,+ crate::bridge::create_profile,+ crate::bridge::set_active_profile,+ crate::bridge::remove_profile,+ crate::bridge::get_cores,+ crate::bridge::set_active_core,+ crate::bridge::download_core,+ crate::bridge::remove_core,+ crate::bridge::update_local_core,+ crate::bridge::proxy_health_check,+ crate::bridge::get_runtime_info,+ crate::bridge::runtime_ready,+ crate::bridge::get_app_config,+ crate::bridge::update_app_config,+ crate::bridge::get_cli_link_status,+ crate::bridge::open_in_browser,+ crate::bridge::copy_service_url,+ crate::bridge::reveal_data_dir,+ crate::bridge::reveal_in_folder,+ crate::bridge::open_dir,+ crate::bridge::read_service_logs,+ crate::bridge::read_run_logs,+ crate::bridge::clear_service_logs,+ crate::bridge::set_language,+ crate::bridge::toggle_sidebar,+ crate::bridge::get_dsh_theme,+ crate::bridge::check_desktop_update,+ crate::bridge::download_desktop_update,+ crate::bridge::open_desktop_installer,+ crate::bridge::get_desktop_about,+ crate::bridge::open_external_url,crate::desktop::notification::show_native_notification,- crate::bridge::cmd::log_frontend,+ crate::bridge::log_frontend,]}@@ -265,7 +265,7 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {// 因此开发环境跳过该插件。#[cfg(not(debug_assertions))]let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {- crate::core::utils::show_main_window(app);+ crate::utils::show_main_window(app);}));builderdiff --git a/src-tauri/src/desktop/notification.rs b/src-tauri/src/desktop/notification.rsindex 071567e0..1a48ca2d 100644--- a/src-tauri/src/desktop/notification.rs+++ b/src-tauri/src/desktop/notification.rs@@ -1,7 +1,7 @@#[cfg(windows)]use tauri::Manager;-use crate::{core::utils::app_icon_temp_path, desktop::payload::NativeNotificationPayload};+use crate::{utils::app_icon_temp_path, desktop::payload::NativeNotificationPayload};/// 如果 DSH 插件仍有兜底走浏览器 Notification,则保持“已授权”假象,/// 并让每次 `new Notification(...)` 转成发给宿主窗口的 postMessage。diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex ee319873..acbfecf0 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -1,6 +1,6 @@mod bridge;mod config;-mod core;+mod utils;pub mod desktop;mod logger;mod service;@@ -20,7 +20,7 @@ pub fn run() {// RunEvent::Reopen,这里重新显示主窗口,否则窗口会一直隐藏在托盘。#[cfg(target_os = "macos")]tauri::RunEvent::Reopen { .. } => {- crate::core::utils::show_main_window(&app_handle);+ crate::utils::show_main_window(&app_handle);}// 退出时回收 Harness 进程:不回收的话,node 进程会在应用退出后// 残留并把原生模块 DLL(如 sharp 的 libvips-42.dll)锁在内存,diff --git a/src-tauri/src/core/utils/mod.rs b/src-tauri/src/utils/mod.rssimilarity index 99%rename from src-tauri/src/core/utils/mod.rsrename to src-tauri/src/utils/mod.rsindex 9ca48047..99f2e5b6 100644--- a/src-tauri/src/core/utils/mod.rs+++ b/src-tauri/src/utils/mod.rs@@ -24,4 +24,4 @@ pub fn app_icon_temp_path(app: &tauri::AppHandle) -> Option<std::path::PathBuf>let img = image::RgbaImage::from_raw(icon.width(), icon.height(), rgba)?;img.save(&path).ok()?;Some(path)-}\ No newline at end of file+}