Skip to content

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

Merge remote-tracking branch 'origin/main' into feat/pet-reapply

hairyf72f34ee74db2
diff --cc src/components/toast-provider.tsx
index 4fef4e15,453d8c55..d8a3f8c5
--- a/src/components/toast-provider.tsx
+++ b/src/components/toast-provider.tsx
@@@ -1,61 -1,18 +1,61 @@@
import type { ReactNode } from 'react'
+import type { ToastUpdateEvent } from '@/utils/toast'
+import { useEventBus } from '@hairy/react-lib'
import { Toast } from '@heroui/react'
+import { useState } from 'react'
+import { If } from 'react-if-lite'
- import { placements, activeQueues } from '@/utils/toast'
+ import { activeQueues, placements } from '@/utils/toast'
-export function ToastProvider({ children }: { children?: ReactNode }) {
+interface ToastProviderProps {
+ children?: ReactNode
+ hideCloseButton?: boolean
+}
+
+/**
+ * 应用共用的 HeroUI queue/provider。桌宠窗口仅通过 hideCloseButton 使用
+ * 自定义渲染分支,仍复用这里的 queues 与 src/utils/toast.ts API。
+ */
+export function ToastProvider(props: ToastProviderProps) {
+ const [updates, setUpdates] = useState(() => new Map<string, ToastUpdateEvent['options']>())
+
+ useEventBus<ToastUpdateEvent>('toast.update').on((event) => {
+ if (event === undefined || typeof event.key !== 'string')
+ return
+ setUpdates((current) => {
+ const next = new Map(current)
+ next.set(event.key, { ...(current.get(event.key) ?? {}), ...event.options })
+ return next
+ })
+ })
+
return (
<>
- {placements.map(p => (
+ {placements.map(placement => (
<Toast.Provider
- key={p}
- placement={p}
- queue={activeQueues[p]}
- />
+ key={placement}
+ placement={placement}
+ queue={activeQueues[placement]}
+ >
+ {props.hideCloseButton
+ ? ({ toast: item }) => {
+ const content = { ...item.content, ...updates.get(item.key) }
+ return (
+ <Toast toast={item} variant={content?.variant}>
+ <Toast.Content>
+ <If cond={content?.title !== undefined}>
+ <Toast.Title>{content?.title}</Toast.Title>
+ </If>
+ <If cond={content?.description !== undefined}>
+ <Toast.Description>{content?.description}</Toast.Description>
+ </If>
+ </Toast.Content>
+ </Toast>
+ )
+ }
+ : undefined}
+ </Toast.Provider>
))}
- {children}
+ {props.children}
</>
)
}
diff --cc src/utils/toast.ts
index 670fb1a0,31171197..21cbbf2b
--- a/src/utils/toast.ts
+++ b/src/utils/toast.ts
@@@ -32,55 -24,33 +32,55 @@@ const linuxQueues = Object.fromEntries
) as Record<Placement, ToastQueue>
export const activeQueues = navigator.platform.toLowerCase().includes('linux')
- ? linuxQueues
- : queues
+ ? linuxQueues
+ : queues
+const toastContents = new Map<string, ToastContentValue>()
const placementsKeys = new Map<string, Placement>()
-export function toast(
- message: string,
- options?: ToastOptions,
-) {
- // 默认右下角;个别调用方需要其他位置时显式传 placement
- const { placement = 'bottom end', ...rest } = options || {}
- const key = activeQueues[placement].add({ title: message, ...rest })
- placementsKeys.set(key, placement)
- return key
-}
-
-function close(key: string) {
- const placement = placementsKeys.get(key)
- placementsKeys.delete(key)
- if (placement)
- activeQueues[placement].close(key)
-}
+/**
+ * 统一 toast API:直接调用创建,toast.update/close/clear 通过 key 管理。
+ * update 触发 emitter 'toast.update',由 ToastProvider 经 useEventBus 消费后
+ * 原地更新对应 queue 的 content(HeroUI ToastQueue 没有 update 方法)。
+ */
+export const toast = Object.assign(
+ (message: string | ReactNode, options?: ToastOptions) => {
+ // 默认右下角;个别调用方需要其他位置时显式传 placement
+ const { placement = 'bottom end', timeout, onClose, ...rest } = options || {}
+ let key = ''
+ const content = { title: message, ...rest }
+ key = activeQueues[placement].add(content, {
+ timeout,
+ onClose: () => {
+ toastContents.delete(key)
+ placementsKeys.delete(key)
+ onClose?.()
+ },
+ })
+ toastContents.set(key, content)
+ placementsKeys.set(key, placement)
+ return key
+ },
+ {
+ update(key: string, options: ToastUpdateOptions): void {
+ if (!placementsKeys.has(key))
+ return
+ toastContents.set(key, { ...(toastContents.get(key) ?? {}), ...options })
+ emitter.emit('toast.update', { key, options })
+ },
-function clear() {
- placementsKeys.clear()
- placements.forEach(p => activeQueues[p].clear())
-}
+ close(key: string): void {
+ const placement = placementsKeys.get(key)
+ if (placement)
+ activeQueues[placement].close(key)
+ else
+ toastContents.delete(key)
+ },
-toast.close = close
-toast.clear = clear
+ clear(): void {
+ toastContents.clear()
+ placementsKeys.clear()
+ placements.forEach(p => activeQueues[p].clear())
+ },
+ },
+)