Skip to content

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

fix(pet): address CodeRabbit merge-risk notes — live pet label + visible settings errors

hairyf49e50e31e2a6
diff --git a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
index 79a7ef68..7e85e8d1 100644
--- a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
+++ b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
@@ -2,6 +2,7 @@
* components/pet-settings.tsx — 独立「宠物」设置页(注册进 shell.overlay)。
* 类归档页停靠面板:启用/停用开关、选择桌宠、显示/隐藏。走 invoke 桥。
*/
+import type { LocaleKey } from '../types'
import { useEffect, useState, useSyncExternalStore } from 'react'
import { DEFAULT_PETS } from '../constants'
import { text } from '../locales'
@@ -13,6 +14,7 @@ type PetSettingsProps = Record<never, never>
export function PetSettings(_props: PetSettingsProps) {
const { open, status } = useSyncExternalStore(subscribePetUi, getPetUiSnapshot, getPetUiSnapshot)
const [busy, setBusy] = useState(false)
+ const [errorMsg, setErrorMsg] = useState<LocaleKey | null>(null)
const enabled = Boolean(status?.enabled)
useEffect(() => {
@@ -41,11 +43,13 @@ export function PetSettings(_props: PetSettingsProps) {
if (busy)
return
setBusy(true)
+ setErrorMsg(null)
try {
setPetStatus(await setPetEnabled(!enabled))
}
catch (error) {
console.error('[dsh-tauri-pet] setPetEnabled failed:', error)
+ setErrorMsg('setEnabledFailed')
}
finally {
setBusy(false)
@@ -56,11 +60,13 @@ export function PetSettings(_props: PetSettingsProps) {
if (busy || id === status?.active_pet)
return
setBusy(true)
+ setErrorMsg(null)
try {
setPetStatus(await setActivePet(id))
}
catch (error) {
console.error('[dsh-tauri-pet] setActivePet failed:', error)
+ setErrorMsg('setPetFailed')
}
finally {
setBusy(false)
@@ -104,6 +110,9 @@ export function PetSettings(_props: PetSettingsProps) {
<button type="button" className="dshpet-btn" onClick={() => { void hidePet().catch(() => {}) }}>{text('hide')}</button>
</div>
</section>
+ {errorMsg
+ ? <p className="dshpet-error" role="alert">{text(errorMsg)}</p>
+ : null}
</div>
</div>
)
diff --git a/packages/dsh-tauri-pet/src/client/styles/index.ts b/packages/dsh-tauri-pet/src/client/styles/index.ts
index 8c5d19dd..0865becd 100644
--- a/packages/dsh-tauri-pet/src/client/styles/index.ts
+++ b/packages/dsh-tauri-pet/src/client/styles/index.ts
@@ -125,6 +125,12 @@ const style = c([
background: 'transparent',
color: '#e7e9ff',
}, [c('&:hover', { background: 'rgba(80,100,255,0.18)' })]),
+ c('.dshpet-error', {
+ margin: 0,
+ fontSize: '12px',
+ lineHeight: '18px',
+ color: '#ff7a7a',
+ }),
])
export function mountPetStyles(): () => void {
diff --git a/src/pet/pet.tsx b/src/pet/pet.tsx
index baa74247..7a184a9d 100644
--- a/src/pet/pet.tsx
+++ b/src/pet/pet.tsx
@@ -28,21 +28,31 @@ function petDisplayName(id: string | null | undefined): string {
return segment.replace(/\.(zip|png|sprites)$/i, '') || 'dsh'
}
+const PET_STATUS_POLL_MS = 1500
+
export function PetWindow() {
const [activePet, setActivePet] = useState<string>('dsh')
useEffect(() => {
let cancelled = false
- void invoke<PetStatus>('get_pet_status')
- .then((status) => {
+
+ const refresh = async (): Promise<void> => {
+ try {
+ const status = await invoke<PetStatus>('get_pet_status')
if (!cancelled && status.active_pet)
setActivePet(petDisplayName(status.active_pet))
- })
- .catch((error) => {
+ }
+ catch (error) {
console.error('[pet] get_pet_status failed:', error)
- })
+ }
+ }
+
+ void refresh()
+ // 设置页切换宠物时刷新名称标签,避免展示陈旧的 active_pet。
+ const timer = window.setInterval(refresh, PET_STATUS_POLL_MS)
return () => {
cancelled = true
+ window.clearInterval(timer)
}
}, [])