Skip to content

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

fix(pet): 不再默认选中内置鲸鱼宠物,全新安装无默认选择

hairyf142e2a4b6dee
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 dc534342..f06da74e 100644
--- a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
+++ b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
@@ -2,7 +2,7 @@ import type { ChangeEvent, ReactElement } from 'react'
import type { PetListItem, PetSettingsProps, PresetDownloadProgress, PresetPetItem } from '../types'
import { ArrowDownToLine, Icon, Plus, useMountStyle } from 'dsh-tauri-ui/client'
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react'
-import { BUILTIN_PET_ID, PET_DEFAULT_SIZE, PET_SIZE_MAX, PET_SIZE_MIN, PET_SIZE_STEP } from '../constants'
+import { PET_DEFAULT_SIZE, PET_SIZE_MAX, PET_SIZE_MIN, PET_SIZE_STEP } from '../constants'
import { text, usePetLocale } from '../locales'
import {
downloadPresetPet,
@@ -140,7 +140,7 @@ export function PetSettings(props: PetSettingsProps): ReactElement {
const committedSizeRef = useRef<number | null>(null)
const enabled = Boolean(status?.enabled)
const visible = Boolean(status?.visible)
- const active = status?.active_pet ?? BUILTIN_PET_ID
+ const active = status?.active_pet ?? ''
const statusSize = status?.pet_size ?? PET_DEFAULT_SIZE
useEffect(() => {
diff --git a/packages/dsh-tauri-pet/src/client/constants/index.ts b/packages/dsh-tauri-pet/src/client/constants/index.ts
index fdf9b769..b3d68f6f 100644
--- a/packages/dsh-tauri-pet/src/client/constants/index.ts
+++ b/packages/dsh-tauri-pet/src/client/constants/index.ts
@@ -29,7 +29,6 @@ export const BUILTIN_PET_ID = 'maid-deepseek-whale'
export const BUILTIN_PET_NAME = 'Maid DeepSeek Whale'
export const BUILTIN_PET_DESC_ZH = '一只小小的七比蓝头发的鲸鱼女仆Codex宠物,穿着海军蓝裙子,白色褶边,蓝眼睛,侧鳍和鲸鱼尾巴。'
export const BUILTIN_PET_DESC_EN = 'A tiny blue-haired whale maid Codex pet in a navy dress with white ruffles, blue eyes, side fins, and a whale tail.'
-export const DEFAULT_PETS = [{ id: BUILTIN_PET_ID, label: BUILTIN_PET_NAME }] as const
export const SIDEBAR_SELECTOR = '[data-slot="sidebar"]'
export const SETTINGS_TRIGGER_SELECTOR = '.dshp-settings-trigger'
export const PET_ICON_ATTRIBUTE = 'data-dsh-tauri-pet-icon'
diff --git a/packages/dsh-tauri-pet/src/client/utils/preset-card.test.ts b/packages/dsh-tauri-pet/src/client/utils/preset-card.test.ts
index 19d88e9e..1ba9f008 100644
--- a/packages/dsh-tauri-pet/src/client/utils/preset-card.test.ts
+++ b/packages/dsh-tauri-pet/src/client/utils/preset-card.test.ts
@@ -18,6 +18,12 @@ describe('resolvePresetCardAction', () => {
expect(resolvePresetCardAction({ ...maid, installed: true }, 'maid-deepseek-whale', progress('downloading'))).toBe('selected')
})
+ it('激活 id 为空串(全新安装无默认选择):未安装给出下载、已安装给出启用', () => {
+ // 不再默认选中内置宠物;active_pet 为空 → 任何预设卡都不显示「已选」。
+ expect(resolvePresetCardAction(maid, '', null)).toBe('download')
+ expect(resolvePresetCardAction({ ...maid, installed: true }, '', null)).toBe('enable')
+ })
+
it('下载/解压中显示 downloading,不因已安装而跳到 enable', () => {
expect(resolvePresetCardAction(maid, 'other', progress('downloading'))).toBe('downloading')
expect(resolvePresetCardAction(maid, 'other', progress('extracting'))).toBe('downloading')
diff --git a/packages/dsh-tauri-pet/src/client/utils/preset-card.ts b/packages/dsh-tauri-pet/src/client/utils/preset-card.ts
index 4b68e626..f78676d0 100644
--- a/packages/dsh-tauri-pet/src/client/utils/preset-card.ts
+++ b/packages/dsh-tauri-pet/src/client/utils/preset-card.ts
@@ -6,9 +6,9 @@ import type { PresetDownloadProgress, PresetPetItem } from '../types'
* 优先级:已选(selected)> 下载/解压中(downloading)> 已安装(enable)>
* 未安装(download)。与设置页 `presetCardAction` 一一对应。
*
- * 已选必须同时满足「已安装且为当前激活宠物」:内置归一 id(maid-deepseek-whale)
- * 与预设卡 id 相同,新装环境 active_pet 归一为内置 id 但产物尚未下载,此时卡片
- * 必须给出下载入口,而不是显示已选禁用(issue #401)。
+ * 已选必须同时满足「已安装且为当前激活宠物」:预设卡 id(maid-deepseek-whale)与
+ * 激活 id 相同但产物尚未下载,或全新安装 active_pet 为空串(未选择任何宠物)时,
+ * 卡片必须给出下载入口,而不是显示已选禁用(issue #401)。
*
* 下载中状态有两个来源:`progress.phase`(进行中的轮询快照)与 `item.phase`
* (`list_preset_pets` 返回的进程内注册表阶段,跨挂载恢复下载中视图用——组件
diff --git a/src-tauri/src/bridge/pet.rs b/src-tauri/src/bridge/pet.rs
index f0c68073..a4e22b93 100644
--- a/src-tauri/src/bridge/pet.rs
+++ b/src-tauri/src/bridge/pet.rs
@@ -28,8 +28,6 @@ use zip::ZipArchive;
pub const PET_SIZE_MIN: f64 = pet_window::PET_SIZE_MIN_PERCENT;
pub const PET_SIZE_MAX: f64 = pet_window::PET_SIZE_MAX_PERCENT;
-/// 缺省选择对外统一呈现的精确内置宠物 id。
-pub const DEFAULT_ACTIVE_PET_ID: &str = "maid-deepseek-whale";
/// 导入桌宠资源包的压缩大小上限(32 MiB)。
const PET_PACKAGE_MAX_BYTES: usize = 32 * 1024 * 1024;
/// 防止 zip 炸弹的条目数与解压后总大小上限。
@@ -71,7 +69,7 @@ pub struct PetStatus {
pub enabled: bool,
/// 桌宠窗口当前是否应显示。
pub visible: bool,
- /// 当前桌宠 id;持久值缺省或空白时始终返回内置默认 id。
+ /// 当前桌宠 id;持久值缺省或空白时返回空串(未选择任何宠物)。
pub active_pet: String,
/// 宠物大小百分比(50–200,100 = 精灵图原始尺寸);None = 未设置(默认 100)。
pub pet_size: Option<f64>,
@@ -140,19 +138,17 @@ pub struct PetAsset {
pub rows: u8,
}
-/// 将缺省、旧版未限定 id 或非法选择归一化为内置默认宠物的精确 id。
-/// 合法值:默认宠物 id、预设宠物 id(~/.dsh/pets 目录,安全字符集)或来源限定 id。
+/// 将缺省、旧版未限定 id 或非法选择归一化为空字符串(未选择任何宠物)。
+/// 合法值:预设宠物 id(~/.dsh/pets 目录,安全字符集)或来源限定 id。
+/// 注意:不再默认给内置宠物 —— 全新安装下 active_pet 为空,需用户先下载再启用。
fn normalize_active_pet(active_pet: Option<&str>) -> String {
let Some(id) = active_pet.map(str::trim).filter(|id| !id.is_empty()) else {
- return DEFAULT_ACTIVE_PET_ID.to_string();
+ return String::new();
};
- if id == DEFAULT_ACTIVE_PET_ID
- || crate::bridge::preset_pet::safe_preset_id(id)
- || parse_qualified_id(id).is_ok()
- {
+ if crate::bridge::preset_pet::safe_preset_id(id) || parse_qualified_id(id).is_ok() {
id.to_string()
} else {
- DEFAULT_ACTIVE_PET_ID.to_string()
+ String::new()
}
}
@@ -347,9 +343,9 @@ fn parse_qualified_id(id: &str) -> Result<(PetSource, &str), String> {
Ok((source, manifest_id))
}
-/// 校验激活宠物 id:默认宠物、预设宠物(安全字符集)或来源限定 id。
+/// 校验激活宠物 id:预设宠物(安全字符集)或来源限定 id。
fn validate_active_pet_id(id: &str) -> Result<(), String> {
- if id == DEFAULT_ACTIVE_PET_ID || crate::bridge::preset_pet::safe_preset_id(id) {
+ if crate::bridge::preset_pet::safe_preset_id(id) {
return Ok(());
}
parse_qualified_id(id).map(|_| ())
@@ -936,9 +932,10 @@ mod tests {
}
#[test]
- fn active_pet_defaults_to_exact_builtin_id() {
- assert_eq!(normalize_active_pet(None), DEFAULT_ACTIVE_PET_ID);
- assert_eq!(normalize_active_pet(Some(" ")), DEFAULT_ACTIVE_PET_ID);
+ fn active_pet_defaults_to_empty_when_unset_or_invalid() {
+ // 全新安装不再默认选中内置宠物:缺省/空白/非法 id 一律归一为空串(未选择)。
+ assert_eq!(normalize_active_pet(None), "");
+ assert_eq!(normalize_active_pet(Some(" ")), "");
assert_eq!(
normalize_active_pet(Some(" chat:custom-pet ")),
"chat:custom-pet",
@@ -949,14 +946,14 @@ mod tests {
"codex:custom_pet"
);
// 未限定 id(预设宠物,安全字符集)与来源限定 id 都是合法激活选择;
- // 只有非法字符集 / 未知来源限定才回落内置宠物。
+ // 只有非法字符集 / 未知来源限定才归一为空串(未选择任何宠物)。
assert_eq!(normalize_active_pet(Some("cat")), "cat");
assert_eq!(normalize_active_pet(Some("shiba")), "shiba");
for legacy_or_invalid in ["other:pet", "chat:../pet", "bad id", "x/y"] {
assert_eq!(
normalize_active_pet(Some(legacy_or_invalid)),
- DEFAULT_ACTIVE_PET_ID,
- "旧版或非法 id {legacy_or_invalid} 应回落内置宠物"
+ "",
+ "旧版或非法 id {legacy_or_invalid} 应归一为空串(未选择宠物)"
);
}
}
@@ -970,7 +967,7 @@ mod tests {
let status = status_from_setting(&setting);
assert!(!status.enabled);
assert!(!status.visible);
- assert_eq!(status.active_pet, DEFAULT_ACTIVE_PET_ID);
+ assert_eq!(status.active_pet, "");
}
#[test]
diff --git a/src/pet/components/pet.tsx b/src/pet/components/pet.tsx
index f4bb31da..0e1dc756 100644
--- a/src/pet/components/pet.tsx
+++ b/src/pet/components/pet.tsx
@@ -15,12 +15,11 @@ import {
rollKind,
} from '../pet-config'
-const BUILT_IN_PET_ID = 'maid-deepseek-whale'
-/** 默认预设宠物未安装时的提示文案:桌宠窗口无 i18n 基础设施(气泡文案同样硬编码),按窗口语言就近显示。 */
+const PET_BASE_WIDTH = 220
+/** 已安装预设被清理/未安装时的提示文案:桌宠窗口无 i18n 基础设施(气泡文案同样硬编码),按窗口语言就近显示。 */
const PRESET_MISSING_HINT = (document.documentElement.lang || navigator.language || 'zh-CN').toLowerCase().startsWith('zh')
? '预设宠物未安装,请在设置中下载'
: 'Preset pet not installed. Download it in Settings.'
-const PET_BASE_WIDTH = 220
const PET_DEFAULT_SIZE_PERCENT = 100
const PET_SIZE_MIN_PERCENT = 50
const PET_SIZE_MAX_PERCENT = 200
@@ -141,8 +140,9 @@ export function Pet(props: PetProps) {
error: preset?.error ?? null,
}
}, [activePet, petResources])
- // 默认预设宠物未安装(新装环境 active_pet 归一为内置 id,但产物需手动下载):
- // 资源拉取失败时视频层静默空白,这里给出可见提示引导去设置页下载(issue #401)。
+ // 已选预设宠物未安装(如资源被外部清理):资源拉取失败时视频层静默空白,
+ // 这里给出可见提示引导去设置页下载(issue #401)。全新安装 active_pet 为空串
+ // (无默认选择),不会走此分支。
const presetMissing = isPreset && error?.includes('PET_PRESET_NOT_INSTALLED') === true
// 预设宠物配置驱动动画池:池条目是动画名(webm 文件名主名,如 待机呼吸休闲),
// 点击/拖拽/待机链按名字从 assets map 取 URL。配置缺失或命令失败时回落与旧
@@ -211,7 +211,9 @@ export function Pet(props: PetProps) {
// 已安装预设的 config.jsonc 池条目(待机呼吸休闲 等)即 webm 文件名主名,
// assets map 的 key 与池条目一一对应,动画链/点击/拖拽直接按名字取 URL。
useEffect(() => {
- if (isPreset === false)
+ // 无激活宠物(active_pet 为空串,全新安装未选择)时不拉取任何资源,避免
+ // 对空 id 发无意义请求或误显示「预设未安装」提示;窗口在未启用时本就不展示。
+ if (isPreset === false || activePet === '')
return undefined
let disposed = false
let loadError: string | null = null
@@ -600,8 +602,9 @@ function toAdHocStatus(entry: string | undefined): string | null {
}
function normalizeActivePet(value: string | null | undefined): string {
- const normalized = value?.trim()
- return normalized || BUILT_IN_PET_ID
+ // 全新安装 active_pet 为空串(未选择任何宠物),不再回落内置宠物;窗口据此
+ // 感知「无宠物」态,避免误渲染一个未安装的默认预设。
+ return value?.trim() || ''
}
function normalizePetSize(value: number | null | undefined): number {