DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(boot): skip setup screens when installed, add silent update prompt
hairyfa4e48fec7b08
diff --git a/src-tauri/src/bridge/cmd.rs b/src-tauri/src/bridge/cmd.rsindex 38b2fdbb..2fa8d813 100644--- a/src-tauri/src/bridge/cmd.rs+++ b/src-tauri/src/bridge/cmd.rs@@ -57,6 +57,26 @@ pub async fn install_dependencies(app_handle: AppHandle) -> Result<(), String> {Ok(())}+/// 静默检查是否有新版 Harness 可用(只查不装,供进入页面后后台调用)+#[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 current = config::get_dsh_pkg_commit(&app_handle);+ if current.as_deref() == Some(latest.commit.as_str()) {+ Ok(None)+ } else {+ Ok(Some(latest))+ }+}+/// 启动 Harness 服务#[tauri::command]pub async fn launch_harness(app_handle: AppHandle) -> Result<(), String> {diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 10696801..8a3a7bde 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -91,6 +91,7 @@ fn tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {tauri::generate_handler![bridge::cmd::install_dependencies,+ bridge::cmd::check_dsh_update,bridge::cmd::launch_harness,bridge::cmd::shutdown_harness,bridge::cmd::restart_harness,diff --git a/src-tauri/src/service/download/core.rs b/src-tauri/src/service/download/core.rsindex c85d2b79..3888723f 100644--- a/src-tauri/src/service/download/core.rs+++ b/src-tauri/src/service/download/core.rs@@ -214,11 +214,18 @@ pub fn ensure_extract<'a, R: Runtime>(/// GitHub API 地址(未认证限流 60 次/小时/IP,仅供每次启动检查一次)const DSH_PKG_GITHUB_API: &str = "https://api.github.com/repos/hairyf/deepseek-harness-pkg";-/// 查询 GitHub 上最新 Harness 发行版对应的 commit hash+/// 最新 Harness 发行版信息(版本 tag + 对应 commit hash)+#[derive(Debug, Clone, serde::Serialize)]+pub struct LatestDshPkg {+ pub tag: String,+ pub commit: String,+}++/// 查询 GitHub 上最新 Harness 发行版信息////// 先取最新 release 的 tag_name,再通过 commits 端点把 tag 解析为 commit。/// 网络不可用或 API 限流时返回 Err,由调用方决定是否保留本地安装。-pub async fn fetch_latest_dsh_pkg_commit() -> Result<String, String> {+pub async fn fetch_latest_dsh_pkg_info() -> Result<LatestDshPkg, String> {let client = reqwest::Client::builder().user_agent("deepseek-harness-desktop").timeout(std::time::Duration::from_secs(5))@@ -252,9 +259,18 @@ pub async fn fetch_latest_dsh_pkg_commit() -> Result<String, String> {.json().await.map_err(|e| format!("Failed to parse release commit response: {}", e))?;- commit+ let sha = commit.get("sha").and_then(|v| v.as_str())- .map(|s| s.to_string())- .ok_or_else(|| "Missing sha in release commit response".to_string())+ .ok_or_else(|| "Missing sha in release commit response".to_string())?;++ Ok(LatestDshPkg {+ tag: tag_name.to_string(),+ commit: sha.to_string(),+ })+}++/// 查询 GitHub 上最新 Harness 发行版对应的 commit hash+pub async fn fetch_latest_dsh_pkg_commit() -> Result<String, String> {+ fetch_latest_dsh_pkg_info().await.map(|info| info.commit)}diff --git a/src-tauri/src/service/download/mod.rs b/src-tauri/src/service/download/mod.rsindex c46e4e8b..325fd4a8 100644--- a/src-tauri/src/service/download/mod.rs+++ b/src-tauri/src/service/download/mod.rs@@ -5,6 +5,9 @@ mod progress;mod utils;// 导出公共接口-pub use core::{download_file, ensure_extract, fetch_latest_dsh_pkg_commit};+pub use core::{+ download_file, ensure_extract, fetch_latest_dsh_pkg_commit, fetch_latest_dsh_pkg_info,+ LatestDshPkg,+};pub use installable::{Dsh, Installable, Nodejs};pub use progress::ProgressTracker;diff --git a/src/App.tsx b/src/App.tsxindex 24242d95..fe21123f 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -17,6 +17,11 @@ interface InstallerState {logs: string[];}+interface DshUpdateInfo {+ tag: string;+ commit: string;+}+const initialInstaller: InstallerState = {title: "",detail: "",@@ -30,13 +35,16 @@ const btnPrimary =export default function App() {const { t } = useI18n();useDshTheme();- const [status, setStatus] = useState<SetupStatus>("checking");+ const [status, setStatus] = useState<SetupStatus>("ready");const [installer, setInstaller] = useState<InstallerState>(initialInstaller);const [errorMsg, setErrorMsg] = useState("");const [serviceUrl, setServiceUrl] = useState("http://127.0.0.1:3080");const [iframeLoaded, setIframeLoaded] = useState(false);const [iframeError, setIframeError] = useState(false);const [iframeKey, setIframeKey] = useState(0);+ const [serviceHealthy, setServiceHealthy] = useState(false);+ const [updateInfo, setUpdateInfo] = useState<DshUpdateInfo | null>(null);+ const [updating, setUpdating] = useState(false);const [sidebarOpen, setSidebarOpen] = useState(() => {const saved = localStorage.getItem("sidebarOpen");return saved === null ? false : saved === "true";@@ -93,30 +101,74 @@ export default function App() {}};+ // 安装进度流:只前进不后退,供首次安装/手动更新共用+ const listenInstallProgress = useCallback(async (): Promise<UnlistenFn> => {+ return listen<InstallProgress>("install-progress", (e) => {+ const payload = e.payload;+ setInstaller((prev) => {+ if (payload.percentage < prev.percentage) {+ return prev;+ }+ const logs = payload.log+ ? [...prev.logs, payload.log].slice(-5)+ : prev.logs;+ return {+ title: payload.title || prev.title,+ detail: payload.detail || prev.detail,+ percentage: payload.percentage,+ logs,+ };+ });+ });+ }, []);++ // 后台静默检查是否有新版 Harness(网络失败/API 限流时静默跳过)+ const checkForUpdate = useCallback(async () => {+ try {+ const info = await invoke<DshUpdateInfo | null>("check_dsh_update");+ if (info) {+ setUpdateInfo(info);+ }+ } catch (err) {+ console.log("[App] update check skipped:", err);+ }+ }, []);++ // 拉起服务并等待健康检查通过,通过后才挂载 iframe+ const launchAndWait = useCallback(async () => {+ setStatus("ready");+ setInstaller(initialInstaller);+ setServiceHealthy(false);+ setIframeLoaded(false);+ setIframeError(false);+ await invoke("launch_harness");+ setServiceRunning(true);++ let healthy = false;+ for (let attempt = 0; attempt < MAX_RETRIES && !healthy; attempt++) {+ healthy = await checkHealthViaProxy();+ if (!healthy) {+ await new Promise((resolve) => setTimeout(resolve, 2000));+ }+ }+ if (!healthy) {+ throw new Error(+ t("errors.service_start_timeout", { port: new URL(serviceUrl).port || "3080" }),+ );+ }+ setServiceHealthy(true);+ }, [serviceUrl, t]);+const boot = useCallback(async () => {const token = ++bootToken.current;+ // 回到加载态:已安装时不再显示检测/启动界面,直接进入页面加载状态+ setServiceHealthy(false);+ setIframeLoaded(false);+ setIframeError(false);let unlistenInstall: UnlistenFn | null = null;try {- // Install-progress stream: only ever move the percentage forward, like- // the reference installer store.- unlistenInstall = await listen<InstallProgress>("install-progress", (e) => {- const payload = e.payload;- setInstaller((prev) => {- if (payload.percentage < prev.percentage) {- return prev;- }- const logs = payload.log- ? [...prev.logs, payload.log].slice(-5)- : prev.logs;- return {- title: payload.title || prev.title,- detail: payload.detail || prev.detail,- percentage: payload.percentage,- logs,- };- });- });+ unlistenInstall = await listenInstallProgress();const runtimeInfo = await invoke<{ service_url: string }>("get_runtime_info");setServiceUrl(runtimeInfo.service_url);@@ -124,35 +176,20 @@ export default function App() {// 已安装过则跳过安装界面,避免每次启动都闪现“正在安装依赖...”const config = await invoke<{ installed: boolean }>("get_app_config");- // 1. Install dependencies (Node runtime + harness package).+ // 仅首次使用需要检测环境/安装依赖;之后直接进入页面if (!config.installed) {setStatus("installing");setInstaller({ ...initialInstaller, title: t("status.installing") });+ await invoke("install_dependencies");}- await invoke("install_dependencies");- // 2. Launch + health check.- setStatus("starting");- setInstaller((prev) => ({ ...prev, title: t("status.starting") }));- await invoke("launch_harness");- setServiceRunning(true);-- let healthy = false;- for (let attempt = 0; attempt < MAX_RETRIES && !healthy; attempt++) {- healthy = await checkHealthViaProxy();- if (!healthy) {- await new Promise((resolve) => setTimeout(resolve, 2000));- }- }- if (!healthy) {- throw new Error(- t("errors.service_start_timeout", { port: new URL(serviceUrl).port || "3080" }),- );- }+ await launchAndWait();if (token !== bootToken.current) return;- setStatus("ready");- refreshIframe();+ // 已安装时后台静默检查新版,发现后提示用户+ if (config.installed) {+ void checkForUpdate();+ }} catch (err) {if (token !== bootToken.current) return;console.error("[App] startup failed:", err);@@ -162,7 +199,31 @@ export default function App() {} finally {unlistenInstall?.();}- }, [refreshIframe, serviceUrl, t]);+ }, [listenInstallProgress, launchAndWait, checkForUpdate, t]);++ // 手动更新:重新下载安装新版并重启服务+ const handleUpdate = async () => {+ if (updating) return;+ setUpdating(true);+ setUpdateInfo(null);+ let unlistenInstall: UnlistenFn | null = null;+ try {+ unlistenInstall = await listenInstallProgress();+ setStatus("installing");+ setInstaller({ ...initialInstaller, title: t("status.updating") });+ await invoke("install_dependencies");+ await launchAndWait();+ setUpdateInfo(null);+ } catch (err) {+ console.error("[App] update failed:", err);+ setErrorMsg(String(err));+ setStatus("error");+ setServiceRunning(false);+ } finally {+ unlistenInstall?.();+ setUpdating(false);+ }+ };// React StrictMode 在 dev 下会执行两次 effect,这里确保 boot 只挂载一次useEffect(() => {@@ -174,13 +235,13 @@ export default function App() {// 进入 ready 后如果 iframe 长时间未加载(dsh 未就绪/挂起),// 转为错误界面,避免一直停在黑色加载遮罩useEffect(() => {- if (status !== "ready" || iframeLoaded) return;+ if (status !== "ready" || !serviceHealthy || iframeLoaded) return;const timer = setTimeout(() => {setIframeLoaded(false);setIframeError(true);}, 20000);return () => clearTimeout(timer);- }, [status, iframeLoaded, iframeKey]);+ }, [status, serviceHealthy, iframeLoaded, iframeKey]);const restart = async () => {try {@@ -274,7 +335,7 @@ export default function App() {<p>{t("status.loading")}</p></div>)}- {iframeError && (+ {serviceHealthy && iframeError && (<div className="absolute inset-0 z-[1] flex flex-col items-center justify-center gap-3 bg-canvas text-ink"><p>{t("ui.iframe_error")}</p><p className="text-muted">{t("ui.ensure_running", { url: serviceUrl })}</p>@@ -283,21 +344,40 @@ export default function App() {</button></div>)}- <iframe- key={iframeKey}- className="block h-full w-full border-none bg-white"- src={iframeSrc}- onLoad={() => {- setIframeLoaded(true);- setIframeError(false);- }}- onError={() => {- setIframeError(true);- setIframeLoaded(false);- }}- title={t("app.open_editor")}- />+ {serviceHealthy && (+ <iframe+ key={iframeKey}+ className="block h-full w-full border-none bg-white"+ src={iframeSrc}+ onLoad={() => {+ setIframeLoaded(true);+ setIframeError(false);+ }}+ onError={() => {+ setIframeError(true);+ setIframeLoaded(false);+ }}+ title={t("app.open_editor")}+ />+ )}</main>+ {updateInfo && !updating && (+ <div className="fixed bottom-4 right-4 z-50 flex max-w-[420px] items-center gap-3 rounded-lg border border-accent/40 bg-panel px-4 py-3 shadow-lg">+ <div className="min-w-0 flex-1">+ <p className="text-[13px] font-semibold text-ink">{t("update.available", { tag: updateInfo.tag })}</p>+ <p className="mt-0.5 text-xs text-muted">{updateInfo.commit.slice(0, 7)}</p>+ </div>+ <button className={btnPrimary} onClick={handleUpdate}>+ {t("update.now")}+ </button>+ <button+ className="inline-flex cursor-pointer items-center justify-center rounded-md border border-line bg-panel2 px-3 py-1.5 text-[13px] text-ink transition-colors hover:bg-panel-hover"+ onClick={() => setUpdateInfo(null)}+ >+ {t("update.later")}+ </button>+ </div>+ )}<buttononClick={handleToggleSidebar}title={t("ui.settings")}diff --git a/src/components/SetupScreen.tsx b/src/components/SetupScreen.tsxindex 266160ab..884f6403 100644--- a/src/components/SetupScreen.tsx+++ b/src/components/SetupScreen.tsx@@ -39,16 +39,10 @@ export default function SetupScreen({onRetry,}: SetupScreenProps) {const { t } = useI18n();- const loading = status === "checking" || status === "starting";const error = status === "error";- const defaultText =- status === "checking"- ? t("status.checking")- : status === "starting"- ? t("status.starting")- : t("status.installing");- const heading = error ? t("status.error") : title || defaultText;- const description = error ? "" : detail || defaultText;+ const installing = status === "installing";+ const heading = error ? t("status.error") : title || t("status.installing");+ const description = error ? "" : detail || t("status.installing");const visibleLogs = logs.length ? logs : [t("ui.waiting_logs")];return (@@ -67,23 +61,27 @@ export default function SetupScreen({<h2 className="mt-[18px] mb-1.5 text-xl font-semibold text-ink truncate">{heading}</h2><p className="mb-6 min-h-[18px] text-[13px] break-all text-muted">{errorMsg || description}</p>- <div className="mb-5 flex items-center gap-3">- <div className="h-2 flex-1 overflow-hidden rounded-full bg-panel2" role="progressbar" aria-valuenow={Math.round(percentage)}>- <div className="h-full bg-gradient-to-r from-accent to-accent2 transition-[width] duration-150" style={{ width: `${Math.min(percentage, 100)}%` }} />- </div>- <span className="min-w-[44px] text-right text-[13px] font-semibold tabular-nums text-accent2">{Math.round(percentage)}%</span>- </div>+ {installing && (+ <>+ <div className="mb-5 flex items-center gap-3">+ <div className="h-2 flex-1 overflow-hidden rounded-full bg-panel2" role="progressbar" aria-valuenow={Math.round(percentage)}>+ <div className="h-full bg-gradient-to-r from-accent to-accent2 transition-[width] duration-150" style={{ width: `${Math.min(percentage, 100)}%` }} />+ </div>+ <span className="min-w-[44px] text-right text-[13px] font-semibold tabular-nums text-accent2">{Math.round(percentage)}%</span>+ </div>- <div className="mb-5 min-h-[112px] max-h-[184px] overflow-y-auto rounded-lg border border-line bg-log-bg px-3.5 py-2.5 text-left font-mono text-xs leading-[1.7]" aria-label={t("ui.install_log")}>- {visibleLogs.slice(-LOG_LIMIT).map((line, index) => (- <p key={`${line}-${index}`} className="m-0 flex gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-log-ink">- <span className="shrink-0 text-accent select-none">›</span>- <span className="min-w-0 overflow-hidden text-ellipsis">{line}</span>- </p>- ))}- </div>+ <div className="mb-5 min-h-[112px] max-h-[184px] overflow-y-auto rounded-lg border border-line bg-log-bg px-3.5 py-2.5 text-left font-mono text-xs leading-[1.7]" aria-label={t("ui.install_log")}>+ {visibleLogs.slice(-LOG_LIMIT).map((line, index) => (+ <p key={`${line}-${index}`} className="m-0 flex gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-log-ink">+ <span className="shrink-0 text-accent select-none">›</span>+ <span className="min-w-0 overflow-hidden text-ellipsis">{line}</span>+ </p>+ ))}+ </div>+ </>+ )}- {loading && (+ {!error && (<div className="inline-flex items-center gap-2.5"><span className="h-3.5 w-3.5 animate-spin rounded-full border-2 border-line border-t-accent" /><span className="text-[11px] font-semibold tracking-[0.18em] text-muted">PROCESSING...</span>diff --git a/src/i18n/en.ts b/src/i18n/en.tsindex 0b38f061..a3578045 100644--- a/src/i18n/en.ts+++ b/src/i18n/en.ts@@ -18,6 +18,7 @@ export const en: Translations = {status: {checking: "Checking system environment...",installing: "Installing dependencies...",+ updating: "Updating DeepSeek Harness...",preparing_engine: "Preparing Node.js runtime... {{progress}}%",downloading_harness: "Downloading DeepSeek Harness... {{progress}}%",extracting: "Extracting resource package...",@@ -26,6 +27,11 @@ export const en: Translations = {error: "Startup failed",loading: "Loading interface...",},+ update: {+ available: "A new version {{tag}} is available. Update now?",+ now: "Update Now",+ later: "Later",+ },errors: {service_start_timeout: "DeepSeek Harness startup timeout. Please check whether port {{port}} is occupied or the startup is too slow.",install_verify_failed: "Package downloaded but installation verification failed.",diff --git a/src/i18n/types.ts b/src/i18n/types.tsindex 314f0e8c..c7c84889 100644--- a/src/i18n/types.ts+++ b/src/i18n/types.ts@@ -18,6 +18,7 @@ export interface Translations {status: {checking: string;installing: string;+ updating: string;preparing_engine: string;downloading_harness: string;extracting: string;@@ -26,6 +27,11 @@ export interface Translations {error: string;loading: string;};+ update: {+ available: string;+ now: string;+ later: string;+ };errors: {service_start_timeout: string;install_verify_failed: string;diff --git a/src/i18n/zh.ts b/src/i18n/zh.tsindex 032ffaa9..777fb70a 100644--- a/src/i18n/zh.ts+++ b/src/i18n/zh.ts@@ -18,6 +18,7 @@ export const zh: Translations = {status: {checking: "正在检查系统环境...",installing: "正在安装依赖...",+ updating: "正在更新 DeepSeek Harness...",preparing_engine: "正在准备 Node.js 运行时... {{progress}}%",downloading_harness: "正在下载 DeepSeek Harness... {{progress}}%",extracting: "正在解压资源包...",@@ -26,6 +27,11 @@ export const zh: Translations = {error: "启动失败",loading: "正在加载界面...",},+ update: {+ available: "发现新版本 {{tag}},是否立即更新?",+ now: "立即更新",+ later: "稍后",+ },errors: {service_start_timeout: "DeepSeek Harness 启动超时,请检查端口 {{port}} 是否被占用或启动过慢。",install_verify_failed: "资源包已下载,但安装校验失败。",