DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(pet): 设置页提供 XWayland 开关
fainabib2a13811eaa2
diff --git a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsxindex 9b5c0002..48725d67 100644--- a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx+++ b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx@@ -10,9 +10,11 @@ import {clearPetSelection,enablePet,importPetArchive,+ loadForceXwayland,loadPetCatalog,loadPetOverlaySupported,resizePet,+ toggleForceXwayland,togglePet,} from '../service/pet'import { store } from '../store'@@ -40,11 +42,13 @@ function readAsBase64(file: File): Promise<string> {/** 桌宠设置页:预设 / Chat / Codex 三类宠物卡片(选择、启用、取消选择)、开关、大小滑条与导入。 */export function PetSettings(props: PetSettingsProps): ReactElement {locale.useLocale()- const { status, presetPets, chatPets, codexPets, catalogLoaded, overlaySupported } = useStore(store.pet)+ const { status, presetPets, chatPets, codexPets, catalogLoaded, overlaySupported, forceXwayland } = useStore(store.pet)const [tab, setTab] = useState<'pets' | 'codex'>('pets')const [busy, setBusy] = useState(() => !catalogLoaded)const [error, setError] = useState<string | null>(null)const [size, setSize] = useState(status?.pet_size ?? PET_DEFAULT_SIZE)+ // 切换只落盘,本次进程不会有任何变化,提示重启是用户唯一能看到的反馈。+ const [xwaylandRestart, setXwaylandRestart] = useState(false)const tabsId = useId()const fileRef = useRef<HTMLInputElement>(null)const committedSizeRef = useRef<number | null>(null)@@ -64,6 +68,12 @@ export function PetSettings(props: PetSettingsProps): ReactElement {void loadPetOverlaySupported()}, [overlaySupported])+ // 同上的重试语义:读不到只让开关不出现。+ useEffect(() => {+ if (forceXwayland === null)+ void loadForceXwayland()+ }, [forceXwayland])+useEffect(() => {let cancelled = falsevoid loadPetCatalog().then((result) => {@@ -122,6 +132,20 @@ export function PetSettings(props: PetSettingsProps): ReactElement {setBusy(false)}+ /** 切换「强制 XWayland」:应用全局设置,下次启动生效。 */+ async function toggleXwayland(): Promise<void> {+ if (busy)+ return+ setBusy(true)+ setError(null)+ const result = await toggleForceXwayland({ enabled: !forceXwayland })+ if (result.ok)+ setXwaylandRestart(true)+ else+ setError(locale.text('xwaylandFailed'))+ setBusy(false)+ }+async function commitSize(value: number): Promise<void> {setError(null)const result = await resizePet({ size: value })@@ -222,8 +246,31 @@ export function PetSettings(props: PetSettingsProps): ReactElement {return (<div className="dshp-pet__page">- {overlaySupported === false- ? <div className="dshp-pet__notice" role="status">{locale.text('waylandNotice')}</div>+ {/* 开启并重启后 overlaySupported 变回 true、提示消失,没有 forceXwayland 这一支就再也关不掉。+ xwaylandRestart 一支覆盖在 XWayland 下关闭开关的情形:前两个条件同时落空,+ 整块会连同刚点过的按钮一起卸载,重启提示无从显示。+ macOS / Windows 上三个条件都不成立,整块不渲染。 */}+ {overlaySupported === false || forceXwayland || xwaylandRestart+ ? (+ <div className="dshp-pet__notice" role="status">+ {overlaySupported === false ? <p>{locale.text('waylandNotice')}</p> : null}+ <div className="dshp-pet__notice-actions">+ <Button+ type="button"+ variant="outline"+ size="sm"+ disabled={busy}+ onClick={() => { void toggleXwayland() }}+ >+ {forceXwayland ? locale.text('xwaylandDisable') : locale.text('xwaylandEnable')}+ </Button>+ </div>+ {xwaylandRestart+ ? <p className="dshp-pet__notice-banner">{locale.text('xwaylandRestart')}</p>+ : null}+ <p className="dshp-pet__notice-hint">{locale.text('xwaylandDesc')}</p>+ </div>+ ): null}<div className="dshp-pet__tabs"><SegmentedControldiff --git a/packages/dsh-tauri-pet/src/client/constants/index.ts b/packages/dsh-tauri-pet/src/client/constants/index.tsindex c85f696c..493794c0 100644--- a/packages/dsh-tauri-pet/src/client/constants/index.ts+++ b/packages/dsh-tauri-pet/src/client/constants/index.ts@@ -22,6 +22,8 @@ export const PET_HATCH_PROMPT = '/hatch-dsh-pet 根据你对我的了解,养/** 桌面端 Tauri 命令 id(与 src-tauri 的 command 名逐字一致)。 */export const CMD_GET_PET_STATUS = 'get_pet_status'export const CMD_GET_PET_OVERLAY_SUPPORTED = 'get_pet_overlay_supported'+export const CMD_GET_FORCE_XWAYLAND = 'get_force_xwayland'+export const CMD_SET_FORCE_XWAYLAND = 'set_force_xwayland'export const CMD_SET_PET_ENABLED = 'set_pet_enabled'export const CMD_SET_ACTIVE_PET = 'set_active_pet'export const CMD_SET_PET_SIZE = 'set_pet_size'diff --git a/packages/dsh-tauri-pet/src/client/locales/index.ts b/packages/dsh-tauri-pet/src/client/locales/index.tsindex f34f7e1b..36cf4b65 100644--- a/packages/dsh-tauri-pet/src/client/locales/index.ts+++ b/packages/dsh-tauri-pet/src/client/locales/index.ts@@ -24,7 +24,12 @@ const zh = {tabCodexDesc: '从 Codex 或压缩包中导入 Codex 宠物(支持 .zip 文件)',tabInstalledDesc: '宠物会管理对话串,并突出显示需要关注的事项',toggleFailed: '切换桌宠开关失败',- waylandNotice: '当前为 Wayland 会话,桌宠窗口无法置顶,会被其他窗口遮挡,也不会停在设定的位置。以 GDK_BACKEND=x11 启动可恢复正常显示。',+ waylandNotice: '当前为 Wayland 会话,桌宠窗口无法置顶,会被其他窗口遮挡,也不会停在设定的位置。开启 XWayland 可恢复这两项能力。',+ xwaylandDesc: '开启后整个应用经 XWayland 渲染,分数缩放下界面变模糊,输入法走 XIM 路径。系统未运行 XWayland 时该选项不生效。',+ xwaylandDisable: '关闭 XWayland',+ xwaylandEnable: '开启 XWayland',+ xwaylandFailed: '切换 XWayland 开关失败',+ xwaylandRestart: '设置已保存,重启应用后生效。',}const en: Record<keyof typeof zh, string> = {@@ -49,7 +54,12 @@ const en: Record<keyof typeof zh, string> = {tabCodexDesc: 'Import Codex pets from Codex or archives (.zip files supported)',tabInstalledDesc: 'Pets manage your conversation threads and highlight items that need attention',toggleFailed: 'Failed to toggle the pet',- waylandNotice: 'This is a Wayland session. The pet window cannot stay on top, so it is covered by other windows and does not stay where it was placed. Launch with GDK_BACKEND=x11 to restore normal display.',+ waylandNotice: 'This is a Wayland session. The pet window cannot stay on top, so it is covered by other windows and does not stay where it was placed. Enable XWayland to restore both behaviors.',+ xwaylandDesc: 'When enabled, the whole app renders through XWayland. The interface blurs under fractional scaling and input methods go through XIM. The option has no effect when XWayland is not running.',+ xwaylandDisable: 'Disable XWayland',+ xwaylandEnable: 'Enable XWayland',+ xwaylandFailed: 'Failed to toggle XWayland',+ xwaylandRestart: 'Saved. Takes effect after the app restarts.',}export const locale = defineLocale(PLUGIN_ID, { zh, en })diff --git a/packages/dsh-tauri-pet/src/client/service/pet.invoke.ts b/packages/dsh-tauri-pet/src/client/service/pet.invoke.tsindex 290c84aa..0cf0d38a 100644--- a/packages/dsh-tauri-pet/src/client/service/pet.invoke.ts+++ b/packages/dsh-tauri-pet/src/client/service/pet.invoke.ts@@ -2,12 +2,14 @@import type { PetListItem, PetSource, PetStatus, PresetPetItem } from './pet.types'import { invoke } from 'dsh-tauri/client'import {+ CMD_GET_FORCE_XWAYLAND,CMD_GET_PET_OVERLAY_SUPPORTED,CMD_GET_PET_STATUS,CMD_IMPORT_PET,CMD_LIST_PETS,CMD_LIST_PRESET_PETS,CMD_SET_ACTIVE_PET,+ CMD_SET_FORCE_XWAYLAND,CMD_SET_PET_ENABLED,CMD_SET_PET_SIZE,} from '../constants'@@ -21,6 +23,15 @@ export function getPetOverlaySupported(): Promise<boolean> {return invoke<boolean>(CMD_GET_PET_OVERLAY_SUPPORTED)}+/** 「强制 XWayland」开关的当前值(应用全局设置,下次启动生效)。 */+export function getForceXwayland(): Promise<boolean> {+ return invoke<boolean>(CMD_GET_FORCE_XWAYLAND)+}++export function postForceXwayland(enabled: boolean): Promise<boolean> {+ return invoke<boolean>(CMD_SET_FORCE_XWAYLAND, { enabled })+}+export function postPetEnabled(enabled: boolean): Promise<PetStatus> {return invoke<PetStatus>(CMD_SET_PET_ENABLED, { enabled })}diff --git a/packages/dsh-tauri-pet/src/client/service/pet.ts b/packages/dsh-tauri-pet/src/client/service/pet.tsindex 3cda4f5c..946243a7 100644--- a/packages/dsh-tauri-pet/src/client/service/pet.ts+++ b/packages/dsh-tauri-pet/src/client/service/pet.ts@@ -3,11 +3,13 @@ import type { PetActionResult, PetStatus } from './pet.types'import { PET_HATCH_PROMPT } from '../constants'import { store } from '../store'import {+ getForceXwayland,getPetList,getPetOverlaySupported,getPetStatus,getPresetPets,postActivePet,+ postForceXwayland,postPetEnabled,postPetImport,postPetSize,@@ -53,6 +55,24 @@ export async function loadPetOverlaySupported(): Promise<boolean | null> {}}+/**+ * Query:读取「强制 XWayland」开关的持久值(issue #649)。+ *+ * 与 `loadPetOverlaySupported` 同样的失败语义:返回 `null` 并保留 store 中的旧值,+ * 读不到只让开关不出现,不把设置页整体打成错误态。+ */+export async function loadForceXwayland(): Promise<boolean | null> {+ try {+ const enabled = await getForceXwayland()+ store.pet.setForceXwayland(enabled)+ return enabled+ }+ catch (error) {+ console.error('[dsh-tauri-pet] load force xwayland failed:', error)+ return null+ }+}+/** Query:装载预设 / Chat / Codex 三份清单,并顺带刷新共享状态快照。 */export async function loadPetCatalog(): Promise<PetActionResult> {const revision = store.pet.beginFetch()@@ -133,6 +153,23 @@ export async function togglePet(input: { enabled: boolean }): Promise<PetActionR}}+/**+ * Action:切换「强制 XWayland」开关。+ *+ * 只落盘,不改变本次进程的任何行为:`GDK_BACKEND` 在 GTK 初始化时已被读走,+ * 生效要等下次启动,调用方据此提示用户重启。+ */+export async function toggleForceXwayland(input: { enabled: boolean }): Promise<PetActionResult> {+ try {+ store.pet.setForceXwayland(await postForceXwayland(input.enabled))+ return { ok: true }+ }+ catch (error) {+ console.error('[dsh-tauri-pet] toggle force xwayland failed:', error)+ return { ok: false, error: messageOf(error) }+ }+}+/** Action:调整桌宠窗口大小。 */export async function resizePet(input: { size: number }): Promise<PetActionResult> {try {diff --git a/packages/dsh-tauri-pet/src/client/store/modules/pet.ts b/packages/dsh-tauri-pet/src/client/store/modules/pet.tsindex 22ccf3c5..06e65a02 100644--- a/packages/dsh-tauri-pet/src/client/store/modules/pet.ts+++ b/packages/dsh-tauri-pet/src/client/store/modules/pet.ts@@ -23,6 +23,8 @@ export const pet = defineStore({prefills: {} as Record<string, string>,/** 当前环境能否让桌宠窗口置顶并定位;`null` 为尚未读取(issue #649)。 */overlaySupported: null as boolean | null,+ /** 「强制 XWayland」开关的持久值;`null` 为尚未读取(issue #649)。 */+ forceXwayland: null as boolean | null,}),actions: {/** 开始一次状态拉取,返回其轮次。 */@@ -51,6 +53,9 @@ export const pet = defineStore({setOverlaySupported(supported: boolean): void {this.overlaySupported = supported},+ setForceXwayland(enabled: boolean): void {+ this.forceXwayland = enabled+ },setCodexPets(list: PetListItem[]): void {this.codexPets = list},diff --git a/packages/dsh-tauri-pet/src/client/styles/index.cssr.ts b/packages/dsh-tauri-pet/src/client/styles/index.cssr.tsindex dbe83ad5..57603d83 100644--- a/packages/dsh-tauri-pet/src/client/styles/index.cssr.ts+++ b/packages/dsh-tauri-pet/src/client/styles/index.cssr.ts@@ -61,12 +61,40 @@ export default c([}),// 环境能力提示(原生 Wayland 下桌宠无法置顶):常驻而非一次性报错,用弱化配色。c('.dshp-pet__notice', {+ display: 'flex',+ flexDirection: 'column',+ gap: '8px',padding: '10px 12px',fontSize: '12px',lineHeight: '18px',borderRadius: '10px',border: '1px solid var(--dsw-alias-border-weak)',color: 'var(--dsw-alias-label-secondary)',+ }, [+ c('p', { margin: '0' }),+ ]),+ c('.dshp-pet__notice-actions', {+ display: 'flex',+ alignItems: 'center',+ flexWrap: 'wrap',+ gap: '8px',+ }),+ // 「重启后生效」与紧随其后的说明文字同处一个灰底提示块内,仅靠字号区分会被读者略过,+ // 故沿用 dshp-extension__banner[data-kind=info] 的描边加浅底做法。+ c('.dshp-pet__notice-banner', {+ margin: '0',+ padding: '8px 10px',+ fontSize: '13px',+ lineHeight: '20px',+ borderRadius: '8px',+ border: '1px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 35%, transparent)',+ background: 'color-mix(in srgb, var(--dsw-alias-state-business-primary) 8%, transparent)',+ color: 'var(--dsw-alias-label-primary)',+ }),+ c('.dshp-pet__notice-hint', {+ fontSize: '12px',+ lineHeight: '18px',+ color: 'var(--dsw-alias-label-tertiary)',}),c('.dshp-pet__cards', { display: 'flex', flexDirection: 'column', gap: '12px' }),