Skip to content

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

feat(pet): 原生 Wayland 下提示桌宠无法置顶

fainabi1dd7e3e7d6d1
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 f8489a2e..9b5c0002 100644
--- a/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
+++ b/packages/dsh-tauri-pet/src/client/components/pet-settings.tsx
@@ -11,6 +11,7 @@ import {
enablePet,
importPetArchive,
loadPetCatalog,
+ loadPetOverlaySupported,
resizePet,
togglePet,
} from '../service/pet'
@@ -39,7 +40,7 @@ function readAsBase64(file: File): Promise<string> {
/** 桌宠设置页:预设 / Chat / Codex 三类宠物卡片(选择、启用、取消选择)、开关、大小滑条与导入。 */
export function PetSettings(props: PetSettingsProps): ReactElement {
locale.useLocale()
- const { status, presetPets, chatPets, codexPets, catalogLoaded } = useStore(store.pet)
+ const { status, presetPets, chatPets, codexPets, catalogLoaded, overlaySupported } = useStore(store.pet)
const [tab, setTab] = useState<'pets' | 'codex'>('pets')
const [busy, setBusy] = useState(() => !catalogLoaded)
const [error, setError] = useState<string | null>(null)
@@ -57,6 +58,12 @@ export function PetSettings(props: PetSettingsProps): ReactElement {
setSize(statusSize)
})
+ // 判定在进程生命周期内不变,读到过就不再重复发起;上次失败(仍为 null)时重试。
+ useEffect(() => {
+ if (overlaySupported === null)
+ void loadPetOverlaySupported()
+ }, [overlaySupported])
+
useEffect(() => {
let cancelled = false
void loadPetCatalog().then((result) => {
@@ -215,6 +222,9 @@ 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>
+ : null}
<div className="dshp-pet__tabs">
<SegmentedControl
id={tabsId}
diff --git a/packages/dsh-tauri-pet/src/client/constants/index.ts b/packages/dsh-tauri-pet/src/client/constants/index.ts
index be8981cd..c85f696c 100644
--- a/packages/dsh-tauri-pet/src/client/constants/index.ts
+++ b/packages/dsh-tauri-pet/src/client/constants/index.ts
@@ -21,6 +21,7 @@ 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_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.ts
index f18131bb..f34f7e1b 100644
--- a/packages/dsh-tauri-pet/src/client/locales/index.ts
+++ b/packages/dsh-tauri-pet/src/client/locales/index.ts
@@ -24,6 +24,7 @@ const zh = {
tabCodexDesc: '从 Codex 或压缩包中导入 Codex 宠物(支持 .zip 文件)',
tabInstalledDesc: '宠物会管理对话串,并突出显示需要关注的事项',
toggleFailed: '切换桌宠开关失败',
+ waylandNotice: '当前为 Wayland 会话,桌宠窗口无法置顶,会被其他窗口遮挡,也不会停在设定的位置。以 GDK_BACKEND=x11 启动可恢复正常显示。',
}
const en: Record<keyof typeof zh, string> = {
@@ -48,6 +49,7 @@ 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.',
}
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.ts
index ff41ea9a..290c84aa 100644
--- a/packages/dsh-tauri-pet/src/client/service/pet.invoke.ts
+++ b/packages/dsh-tauri-pet/src/client/service/pet.invoke.ts
@@ -2,6 +2,7 @@
import type { PetListItem, PetSource, PetStatus, PresetPetItem } from './pet.types'
import { invoke } from 'dsh-tauri/client'
import {
+ CMD_GET_PET_OVERLAY_SUPPORTED,
CMD_GET_PET_STATUS,
CMD_IMPORT_PET,
CMD_LIST_PETS,
@@ -15,6 +16,11 @@ export function getPetStatus(): Promise<PetStatus> {
return invoke<PetStatus>(CMD_GET_PET_STATUS)
}
+/** 当前环境能否让桌宠窗口置顶并定位(原生 Wayland 下不能,issue #649)。 */
+export function getPetOverlaySupported(): Promise<boolean> {
+ return invoke<boolean>(CMD_GET_PET_OVERLAY_SUPPORTED)
+}
+
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.ts
index d322155c..3cda4f5c 100644
--- a/packages/dsh-tauri-pet/src/client/service/pet.ts
+++ b/packages/dsh-tauri-pet/src/client/service/pet.ts
@@ -4,6 +4,7 @@ import { PET_HATCH_PROMPT } from '../constants'
import { store } from '../store'
import {
getPetList,
+ getPetOverlaySupported,
getPetStatus,
getPresetPets,
postActivePet,
@@ -34,6 +35,24 @@ export async function loadPetStatus(): Promise<PetStatus | null> {
}
}
+/**
+ * Query:读取当前环境能否让桌宠窗口置顶并定位(issue #649)。
+ *
+ * 与清单装载分开发起:判定失败只应让提示不出现,不该把设置页整体打成错误态。
+ * 失败返回 `null` 并保留 store 中的旧值,重试交给下一次进入设置页。
+ */
+export async function loadPetOverlaySupported(): Promise<boolean | null> {
+ try {
+ const supported = await getPetOverlaySupported()
+ store.pet.setOverlaySupported(supported)
+ return supported
+ }
+ catch (error) {
+ console.error('[dsh-tauri-pet] load pet overlay support failed:', error)
+ return null
+ }
+}
+
/** Query:装载预设 / Chat / Codex 三份清单,并顺带刷新共享状态快照。 */
export async function loadPetCatalog(): Promise<PetActionResult> {
const revision = store.pet.beginFetch()
diff --git a/packages/dsh-tauri-pet/src/client/store/modules/pet.ts b/packages/dsh-tauri-pet/src/client/store/modules/pet.ts
index 9e574556..22ccf3c5 100644
--- a/packages/dsh-tauri-pet/src/client/store/modules/pet.ts
+++ b/packages/dsh-tauri-pet/src/client/store/modules/pet.ts
@@ -21,6 +21,8 @@ export const pet = defineStore({
codexPets: [] as PetListItem[],
/** 待注入的新会话草稿(sessionId → 文本)。 */
prefills: {} as Record<string, string>,
+ /** 当前环境能否让桌宠窗口置顶并定位;`null` 为尚未读取(issue #649)。 */
+ overlaySupported: null as boolean | null,
}),
actions: {
/** 开始一次状态拉取,返回其轮次。 */
@@ -46,6 +48,9 @@ export const pet = defineStore({
this.codexPets = input.codex
this.catalogLoaded = true
},
+ setOverlaySupported(supported: boolean): void {
+ this.overlaySupported = supported
+ },
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.ts
index 972b34ab..dbe83ad5 100644
--- a/packages/dsh-tauri-pet/src/client/styles/index.cssr.ts
+++ b/packages/dsh-tauri-pet/src/client/styles/index.cssr.ts
@@ -59,6 +59,15 @@ export default c([
lineHeight: '18px',
color: 'var(--dsw-alias-state-error-primary)',
}),
+ // 环境能力提示(原生 Wayland 下桌宠无法置顶):常驻而非一次性报错,用弱化配色。
+ c('.dshp-pet__notice', {
+ padding: '10px 12px',
+ fontSize: '12px',
+ lineHeight: '18px',
+ borderRadius: '10px',
+ border: '1px solid var(--dsw-alias-border-weak)',
+ color: 'var(--dsw-alias-label-secondary)',
+ }),
c('.dshp-pet__cards', { display: 'flex', flexDirection: 'column', gap: '12px' }),
c('.dshp-pet__card-item', {
diff --git a/src-tauri/src/bridge/pet.rs b/src-tauri/src/bridge/pet.rs
index b41b59df..97bf8bd2 100644
--- a/src-tauri/src/bridge/pet.rs
+++ b/src-tauri/src/bridge/pet.rs
@@ -165,6 +165,15 @@ pub fn get_pet_status(app: AppHandle) -> PetStatus {
status_from_setting(&config::get_store_dat_setting(&app))
}
+/// 查询当前运行环境能否让桌宠窗口置顶并定位(issue #649)。
+///
+/// 结果由运行环境推导,与持久设置无关,因此不并入 [`PetStatus`]:
+/// [`status_from_setting`] 是 [`config::Setting`] 的纯函数,掺入环境变量会破坏这一点。
+#[tauri::command]
+pub fn get_pet_overlay_supported() -> bool {
+ crate::pet_overlay_supported_env()
+}
+
/// 启用/关闭桌宠(持久化)。侧栏入口、设置页与桌宠窗口自身的关闭请求都走这里。
///
/// 关闭即销毁窗口实例(不是 hide,见 `desktop::pet::set_pet_window_visible`:隐藏窗口里
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 03b9dc0f..5f7e6547 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -984,6 +984,7 @@ pub fn handler() -> impl Fn(Invoke<Wry>) -> bool + Send + Sync + 'static {
crate::desktop::window::quit_app,
crate::bridge::log_frontend,
crate::bridge::get_pet_status,
+ crate::bridge::get_pet_overlay_supported,
crate::bridge::set_pet_enabled,
crate::bridge::set_active_pet,
crate::bridge::set_pet_size,
diff --git a/src-tauri/src/desktop/pet.rs b/src-tauri/src/desktop/pet.rs
index 5db5f5fe..1b321f44 100644
--- a/src-tauri/src/desktop/pet.rs
+++ b/src-tauri/src/desktop/pet.rs
@@ -17,6 +17,8 @@
//! 时回退为非透明窗口继续工作。
//! - `always_on_top` 在 Windows 上 Tauri 原生 API 即可保持置顶(BongoCat 为
//! 额外稳定性用 SetWindowPos 循环轮询,本项目暂不做该平台特定加固)。
+//! - 原生 Wayland 会话下 `always_on_top` 与 `set_position` 都不生效,桌宠被主窗口
+//! 遮挡(issue #649)。判定见 `crate::pet_overlay_supported`,前端据此提示用户。
use crate::config::{store_dat_file_name, STORE_PET_WINDOW_STATE_KEY};
use serde::{Deserialize, Serialize};
@@ -286,6 +288,13 @@ pub fn ensure_pet_window<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Webvie
if let Some(window) = app.get_webview_window(PET_WINDOW_LABEL) {
return Ok(window);
}
+ if !crate::pet_overlay_supported_env() {
+ log::warn!(
+ "PET_OVERLAY_UNSUPPORTED: always-on-top and absolute positioning are unavailable on \
+ a native Wayland session; the pet window is covered by other windows and does not \
+ stay where it was placed. Launch with GDK_BACKEND=x11 to restore them."
+ );
+ }
let app_handle = app.clone();
let (width, height) =
pet_window_logical_size(get_pet_size_percent(app), pet_window_aspect(app));
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index d446ce6c..fdd9f9ef 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -95,6 +95,34 @@ fn should_apply_wayland_egl_workaround(session_type: &str, appimage_present: boo
session_type == "wayland" && appimage_present
}
+/// 桌宠窗口的置顶与绝对定位能力是否可用。
+///
+/// xdg-shell 不提供这两项能力。tao 的 Linux 后端基于 GTK3,`always_on_top` 与
+/// `set_position` 最终落到 `gtk_window_set_keep_above` 与 `gtk_window_move`,
+/// 二者在 GDK 的 Wayland 后端上是 no-op:不生效,也不返回错误。桌宠因此成为
+/// 层级由合成器决定的普通 toplevel,被主窗口覆盖。X11 / XWayland 下窗口管理器
+/// 识别 `_NET_WM_STATE_ABOVE` 并接受绝对放置,两项能力都可用。
+///
+/// 判定读 `WAYLAND_DISPLAY` 而非 `XDG_SESSION_TYPE`:后者由 pam_systemd 设置,
+/// 从 TTY 直接起的合成器(sway / weston / cage)下为空,而 GDK 照样连上 Wayland,
+/// 正是本提示要覆盖的场景。`WAYLAND_DISPLAY` 缺席时 `wl_display_connect` 失败,
+/// GDK 不会选中 Wayland 后端。macOS / Windows 上该变量为空,判定为可用。
+///
+/// `GDK_BACKEND` 是逗号分隔的优先级列表,首项为 `x11` 即强制走 XWayland。GDK 在
+/// 首项打开失败时会顺延到后续项,因此 `x11,wayland` 在没有 XWayland 的环境下会被
+/// 判为可用而实际不可用;该写法需显式配置,这里不为它牺牲判定的简单性。
+pub(crate) fn pet_overlay_supported(wayland_display: &str, gdk_backend: &str) -> bool {
+ wayland_display.is_empty() || gdk_backend.split(',').next() == Some("x11")
+}
+
+/// [`pet_overlay_supported`] 的环境变量读取版本,供查询命令与建窗路径共用。
+pub(crate) fn pet_overlay_supported_env() -> bool {
+ pet_overlay_supported(
+ &std::env::var("WAYLAND_DISPLAY").unwrap_or_default(),
+ &std::env::var("GDK_BACKEND").unwrap_or_default(),
+ )
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -111,4 +139,21 @@ mod tests {
assert!(!should_apply_wayland_egl_workaround("", true));
assert!(!should_apply_wayland_egl_workaround("", false));
}
+
+ #[test]
+ fn pet_overlay_unsupported_only_on_native_wayland() {
+ // 原生 Wayland:GTK 的置顶与定位调用是 no-op,桌宠被主窗口遮挡。
+ assert!(!pet_overlay_supported("wayland-0", ""));
+ assert!(!pet_overlay_supported("wayland-0", "wayland"));
+ // 首项决定 GDK 实际后端;wayland 排在前面时仍走 Wayland。
+ assert!(!pet_overlay_supported("wayland-0", "wayland,x11"));
+ // 强制 XWayland:窗口管理器接受 _NET_WM_STATE_ABOVE 与绝对放置。
+ assert!(pet_overlay_supported("wayland-0", "x11"));
+ assert!(pet_overlay_supported("wayland-0", "x11,wayland"));
+ // 冒号不是 GDK 的分隔符,整串匹配不上 `x11`,仍判为 Wayland。
+ assert!(!pet_overlay_supported("wayland-0", "x11:wayland"));
+ // X11 会话与 macOS / Windows:没有 Wayland 套接字。
+ assert!(pet_overlay_supported("", ""));
+ assert!(pet_overlay_supported("", "wayland"));
+ }
}
diff --git a/src/hooks/use-invoke-iframe.ts b/src/hooks/use-invoke-iframe.ts
index aa602e32..861c3a4c 100644
--- a/src/hooks/use-invoke-iframe.ts
+++ b/src/hooks/use-invoke-iframe.ts
@@ -29,7 +29,7 @@ interface InvokeBridgeRequest {
/**
* 允许 iframe 桥调用的 Tauri command 白名单(与 dsh-tauri-pet 的
- * client/apis/index.ts 一一对应)。凡新增可经桥调用的 command 必须在此登记,
+ * client/constants/index.ts 中 `CMD_*` 一一对应)。凡新增可经桥调用的 command 必须在此登记,
* 防止 iframe 内其他插件借道桥执行任意 Tauri command(越权)。
*/
const ALLOWED_INVOKE_CMDS = new Set([
@@ -39,6 +39,7 @@ const ALLOWED_INVOKE_CMDS = new Set([
// (命令自身只放行 http(s),见 bridge/system_os.rs)。
'open_external_url',
'get_pet_status',
+ 'get_pet_overlay_supported',
'set_pet_enabled',
'set_active_pet',
'set_pet_size',