Skip to content

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

feat(shell): mirror harness-reported styles in the shell chrome

hairyfd421074429ac
diff --git a/src/hooks/use-dsh-style.ts b/src/hooks/use-dsh-style.ts
new file mode 100644
index 00000000..ae4151af
--- /dev/null
+++ b/src/hooks/use-dsh-style.ts
@@ -0,0 +1,9 @@
+import type { CSSProperties } from 'react'
+import { createGlobalState } from '@reause/core'
+
+export const useDshStyle = createGlobalState<{
+ frame?: CSSProperties | null
+ marked?: CSSProperties | null
+ sidebar?: CSSProperties | null
+ colorScheme?: 'dark' | 'light'
+}>({})
diff --git a/src/hooks/use-iframe-message.ts b/src/hooks/use-iframe-message.ts
index ad91ad6b..b0f42f1a 100644
--- a/src/hooks/use-iframe-message.ts
+++ b/src/hooks/use-iframe-message.ts
@@ -25,6 +25,7 @@ export interface IframeMessageContext {
export function useIframeMessage<T>(
iframeRef: RefObject<HTMLIFrameElement | null>,
handler: (message: T, context: IframeMessageContext) => any,
+ types?: string[],
): void {
useEventListener('message', (event: MessageEvent<unknown>) => {
const data = event.data
@@ -37,6 +38,9 @@ export function useIframeMessage<T>(
if (!origin || event.origin !== origin)
return
+ if (types && !types.includes((data as any)?.type as string))
+ return
+
handler(data as T, { origin, event })
})
}
diff --git a/src/layout/components/iframe.tsx b/src/layout/components/iframe.tsx
index 7ff26bf8..1b86a307 100644
--- a/src/layout/components/iframe.tsx
+++ b/src/layout/components/iframe.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react/dom-no-unsafe-iframe-sandbox */
-import type { RefObject } from 'react'
+import type { CSSProperties, RefObject } from 'react'
import { CircleExclamation } from '@gravity-ui/icons'
import { useEventListener } from '@reause/core'
import { invoke } from '@tauri-apps/api/core'
@@ -8,6 +8,7 @@ import { If } from 'react-if-lite'
import { useStore } from 'valtio-define'
import { queryClient } from '@/config/client'
import { queryKeys } from '@/config/query-keys'
+import { useDshStyle } from '@/hooks/use-dsh-style'
import { useIframeMessage } from '@/hooks/use-iframe-message'
import { useIframePost } from '@/hooks/use-iframe-post'
import { useInvokeIframe } from '@/hooks/use-invoke-iframe'
@@ -38,6 +39,10 @@ interface IframeBridgeMessage {
action?: string
/** 插件 boot 桥:失败页文本 */
detail?: string
+
+ sidebar?: CSSProperties
+ marked?: CSSProperties
+ frame?: CSSProperties
}
export interface IframeProps {
@@ -57,6 +62,8 @@ export function Iframe({ iframeRef }: IframeProps) {
const setting = useStore(store.setting)
const post = useIframePost(iframeRef)
+ const [, setDshStyle] = useDshStyle()
+
// 转发 iframe 消息给 Tauri Rust 命令
useInvokeIframe(iframeRef)
@@ -103,10 +110,12 @@ export function Iframe({ iframeRef }: IframeProps) {
void store.harness.handleIframeBootFailure(data.detail)
break
// 缩放快捷键:跨源 iframe 内的 Ctrl/Cmd +/-/0 不会冒泡到壳层,由 dsh-tauri 插件的
- case 'dsh://zoom-shortcut': {
+ case 'dsh://zoom-shortcut':
handleZoomShortcut(data)
break
- }
+ case 'dsh://style':
+ setDshStyle(data)
+ break
}
})
@@ -183,7 +192,7 @@ export function Iframe({ iframeRef }: IframeProps) {
<iframe
key={harness.iframeKey}
ref={iframeRef}
- className="block h-full w-full border-none bg-load-bg"
+ className="h-full w-full"
src={harness.iframeSrc}
allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; clipboard-read; clipboard-write; display-capture; document-domain; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; idle-detection; keyboard-map; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; speaker-selection; usb; web-share; xr-spatial-tracking"
sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-downloads allow-storage-access-by-user-activation"
diff --git a/src/layout/components/loadable.tsx b/src/layout/components/loadable.tsx
index 7cd54d42..76fd669f 100644
--- a/src/layout/components/loadable.tsx
+++ b/src/layout/components/loadable.tsx
@@ -56,8 +56,8 @@ export function Loadable({
const showPanel = hasLogs || percentage != null
return (
- <div className="flex h-full items-center justify-center bg-load-bg -mt-[1px]">
- <div className="flex w-[min(460px,88vw)] flex-col items-center gap-4 text-center">
+ <div className="flex h-full items-center justify-center bg-load-bg">
+ <div className="flex w-[min(460px,88vw)] flex-col items-center gap-4 text-center -mt-[1px]">
{/* 加载态显示 spinner 时隐藏图标(官方 boot 页即无图标),避免与 spinner 重复突兀;仅失败态显示 */}
{/* 加载态显示 spinner 时隐藏图标(官方 boot 页即无图标),避免与 spinner 重复突兀;仅失败态显示 */}
<If cond={error && Icon != null}>
diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsx
index 561e2ff0..9fdb7503 100644
--- a/src/layout/components/navbar.tsx
+++ b/src/layout/components/navbar.tsx
@@ -17,6 +17,7 @@ import { If } from 'react-if-lite'
import { cn } from 'tailwind-variants'
import { useStore } from 'valtio-define'
import { queryKeys } from '@/config/query-keys'
+import { useDshStyle } from '@/hooks/use-dsh-style'
import { useListen } from '@/hooks/use-listen'
import { store } from '@/store'
import { DesktopAboutDialog } from '@/ui/dialog/about'
@@ -151,10 +152,12 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
queryFn: () => invoke<DshPlugin[]>('get_dsh_plugins'),
})
const { updateInfo } = useStore(store.desktopUpdater)
+ const [dshStyle] = useDshStyle()
const openConfigDialog = useOverlay(ConfigDialog)
const openAboutDialog = useOverlay(DesktopAboutDialog)
const openUpdateDialog = useOverlay(DesktopUpdateDialog)
+
// 仅当 dsh-tauri 插件启用(已安装)时显示左侧导航控件
const tauriEnabled = plugins.some(plugin => plugin.id === TAURI_PLUGIN_ID)
function handleWindowAction(action: 'minimize' | 'maximize' | 'background') {
@@ -173,13 +176,13 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
}
}
- function handleDragRegionDoubleClick() {
+ function onDragRegionDoubleClick() {
// macOS 的双击标题栏行为由系统偏好决定,不用网页强制覆盖。
if (!IS_MACOS)
void getCurrentWindow().toggleMaximize()
}
- function handleDragRegionPointerDown(event: React.PointerEvent<HTMLDivElement>) {
+ function onDragRegionPointerDown(event: React.PointerEvent<HTMLDivElement>) {
// data-tauri-drag-region 原生只监听鼠标事件(mousedown/mouseup),
// 触摸屏/笔输入不会触发原生拖拽(见 tauri#13762)。
// 这里对非鼠标输入手动调用 startDragging 进入系统边拖边跟随。
@@ -190,7 +193,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
void getCurrentWindow().startDragging()
}
- function handleHelpAction(key: HelpAction) {
+ function onHelpAction(key: HelpAction) {
if (key === 'check-update')
void handleCheckUpdate()
else if (key === 'about')
@@ -337,6 +340,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
'px-1.5': !IS_MACOS || isFullscreen,
},
)}
+ style={{ background: dshStyle.sidebar?.background }}
>
<If cond={onToggleSidebar != null && tauriEnabled}>
<Button
@@ -438,7 +442,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
className="rounded-md"
id="copy-run-logs"
textValue={t('menu.run_logs')}
- onAction={() => handleHelpAction('copy-run-logs')}
+ onAction={() => onHelpAction('copy-run-logs')}
>
<Label>{t('menu.run_logs')}</Label>
</Dropdown.Item>
@@ -446,7 +450,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
className="rounded-md"
id="check-update"
textValue={t('menu.check_update')}
- onAction={() => handleHelpAction('check-update')}
+ onAction={() => onHelpAction('check-update')}
>
<span className="flex w-full items-center justify-between gap-3">
<Label>{t('menu.check_update')}</Label>
@@ -459,7 +463,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
className="rounded-md"
id="about"
textValue={t('menu.about')}
- onAction={() => handleHelpAction('about')}
+ onAction={() => onHelpAction('about')}
>
<Label>{t('menu.about')}</Label>
</Dropdown.Item>
@@ -467,7 +471,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
className="rounded-md"
id="documentation"
textValue={t('menu.documentation')}
- onAction={() => handleHelpAction('documentation')}
+ onAction={() => onHelpAction('documentation')}
>
<Label>{t('menu.documentation')}</Label>
</Dropdown.Item>
@@ -500,10 +504,12 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
<div
className="min-w-0 flex-1 self-stretch touch-none"
data-tauri-drag-region
- onPointerDown={handleDragRegionPointerDown}
- onDoubleClick={handleDragRegionDoubleClick}
+ onPointerDown={onDragRegionPointerDown}
+ onDoubleClick={onDragRegionDoubleClick}
/>
+ <div className="absolute" style={dshStyle.marked || {}} />
+
<If cond={!IS_MACOS}>
<Button
className="rounded-lg size-7"
diff --git a/src/styles/main.css b/src/styles/main.css
index 63d71fe0..58e157c3 100644
--- a/src/styles/main.css
+++ b/src/styles/main.css
@@ -5,6 +5,16 @@
@import "./components/scrollbar.css";
+@layer base {
+ html,
+ body,
+ #root {
+ min-height: 100%;
+ /* background: #fff; */
+ }
+}
+
+
/* WebView2 123+ 的原生拖拽区域支持触摸屏;Windows runtime 110+ 通过
msWebView2EnableDraggableRegions 参数启用。按钮不在该区域内,故无需 no-drag。 */
[data-tauri-drag-region] {
@@ -121,7 +131,7 @@ html[data-theme="light"] {
}
body {
- @apply overflow-hidden bg-canvas text-ink;
+ @apply overflow-hidden text-ink;
/* 字体栈与官方 web shell(--dsw-font-family)保持一致 */
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;