DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor(ui): extract ProgressPanel from loadable, adjust toast placement and logger setup
hairyf69c55167d307
diff --git a/src/components/loadable.tsx b/src/components/loadable.tsxindex c7c23932..cf4b89f8 100644--- a/src/components/loadable.tsx+++ b/src/components/loadable.tsx@@ -1,12 +1,11 @@import type { ComponentType, ReactNode, SVGProps } from 'react'import { useTranslation } from 'react-i18next'import { button } from './primitives'+import { ProgressPanel } from './progress-panel'/** 图标组件类型(@gravity-ui/icons 均为 SVG 组件) */export type IconComponent = ComponentType<SVGProps<SVGSVGElement>>-const LOG_LIMIT = 5-/*** 通用加载/安装界面。*@@ -86,29 +85,7 @@ export default function Loadable({{showPanel && (<div className="flex w-full flex-col gap-4">- {percentage != null && (- <div className="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>- )}- {hasLogs && (- <div className="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')}>- {(logs!.length ? logs! : [t('ui.waiting_logs')]).slice(-LOG_LIMIT).map((line, index) => (- // 日志行内容可能重复,需以 index 区分 key- // eslint-disable-next-line react/no-array-index-key- <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>- )}+ <ProgressPanel percentage={percentage} logs={hasLogs ? logs! : undefined} /></div>)}diff --git a/src/components/progress-panel.tsx b/src/components/progress-panel.tsxnew file mode 100644index 00000000..20ff1b81--- /dev/null+++ b/src/components/progress-panel.tsx@@ -0,0 +1,54 @@+import { useTranslation } from 'react-i18next'++const LOG_LIMIT = 5++/**+ * 安装/下载进度面板:进度条 + 日志面板。+ *+ * 从 Loadable 中拆出,供首次安装(setup)与核心版本下载对话框共用:+ * 两处都要展示 `install-progress` 事件驱动的百分比与日志流。+ */+export interface ProgressPanelProps {+ /** 进度百分比(0-100);不传则不渲染进度条 */+ percentage?: number+ /** 日志行;不传则不渲染日志面板(空数组渲染"等待日志"占位) */+ logs?: readonly string[]+}++export function ProgressPanel({ percentage, logs }: ProgressPanelProps) {+ const { t } = useTranslation()+ const hasLogs = logs != null+ const showPanel = hasLogs || percentage != null++ if (!showPanel) {+ return null+ }++ return (+ <div className="flex w-full flex-col gap-4">+ {percentage != null && (+ <div className="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>+ )}+ {hasLogs && (+ <div className="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')}>+ {(logs!.length ? logs! : [t('ui.waiting_logs')]).slice(-LOG_LIMIT).map((line, index) => (+ // 日志行内容可能重复,需以 index 区分 key+ // eslint-disable-next-line react/no-array-index-key+ <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>+ )+}diff --git a/src/main.tsx b/src/main.tsxindex 7c290b2f..d71f5ab9 100644--- a/src/main.tsx+++ b/src/main.tsx@@ -1,4 +1,3 @@-import '@/utils/logger'import { OverlaysProvider } from '@overlastic/react'import { QueryClientProvider } from '@tanstack/react-query'import React from 'react'@@ -6,6 +5,7 @@ import ReactDOM from 'react-dom/client'import App from './app'import { ToastProvider } from './components/toast-provider'import { queryClient } from './config/client'+import '@/utils/logger'import './style/main.css'ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(diff --git a/src/utils/logger.ts b/src/utils/logger.tsindex 1a653016..362bcacd 100644--- a/src/utils/logger.ts+++ b/src/utils/logger.ts@@ -10,9 +10,10 @@import { invoke } from '@tauri-apps/api/core'-// 保存原始 console,避免劫持后递归-const _origConsole: Record<string, (...a: unknown[]) => void> | null =- typeof console !== 'undefined'+// 保存原始 console,避免劫持后递归;本模块职责即劫持 console,需要引用原始方法+/* eslint-disable no-console -- 有意引用原始 console 方法 */+const _origConsole: Record<string, (...a: unknown[]) => void> | null+ = typeof console !== 'undefined'? {log: console.log.bind(console),info: console.info.bind(console),@@ -22,6 +23,7 @@ const _origConsole: Record<string, (...a: unknown[]) => void> | null =trace: (console.trace ?? console.log).bind(console),}: null+/* eslint-enable no-console */export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off'@@ -48,7 +50,7 @@ function resolveLevel(): LogLevel {return 'info'}-let currentLevel: LogLevel = resolveLevel()+const currentLevel: LogLevel = resolveLevel()function shouldLog(level: LogLevel): boolean {return LEVEL_ORDER[level] >= LEVEL_ORDER[currentLevel]@@ -114,16 +116,19 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined' && _origConsfor (const m of ['log', 'info', 'debug', 'warn', 'error', 'trace'] as const) {const orig = (_origConsole as Record<string, (...a: unknown[]) => void>)[m] ?? _origConsole.logconst lvl = _consoleLevel[m] ?? 'info'- if ((orig as unknown as { __hijacked?: boolean }).__hijacked) continue+ if ((orig as unknown as { __hijacked?: boolean }).__hijacked)+ continueconst hijacked = (...args: unknown[]) => {- if (!shouldLog(lvl)) return+ if (!shouldLog(lvl))+ returnif (import.meta.env.PROD && LEVEL_ORDER[lvl] < LEVEL_ORDER.warn) {forwardToRust(lvl, 'frontend', args)return}try {orig(...args)- } catch {+ }+ catch {// 忽略控制台异常}forwardToRust(lvl, 'frontend', args)diff --git a/src/utils/toast.ts b/src/utils/toast.tsindex 1d41cab1..d4375674 100644--- a/src/utils/toast.ts+++ b/src/utils/toast.ts@@ -22,7 +22,8 @@ export function toast(message: string,options: HeroUIToastOptions & { placement?: Placement },) {- const { placement = 'top', ...rest } = options+ // 默认右下角;个别调用方需要其他位置时显式传 placement+ const { placement = 'bottom end', ...rest } = optionsconst key = queues[placement].add({ title: message, ...rest })placementsKeys.set(key, placement)return key