Skip to content

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

fix(wayland): scope EGL software-rendering workaround to AppImage runtime

Lautaro Agustin Diez4f8f75c43aa7
diff --git a/src-tauri/src/bridge/pet.rs b/src-tauri/src/bridge/pet.rs
index 7f27179e..c602ddcf 100644
--- a/src-tauri/src/bridge/pet.rs
+++ b/src-tauri/src/bridge/pet.rs
@@ -188,18 +188,31 @@ pub fn set_pet_enabled(app: AppHandle, enabled: bool) -> Result<PetStatus, Strin
}
/// 选择桌宠模型包并持久化 active_pet。
+///
+/// 空串表示清除选择(存 `None`,与全新安装一致):设置页已选卡片可再次点击取消,
+/// 而不是一旦选中就无法撤销。清空后桌宠窗口无内容可渲染,调用方应同时关闭窗口。
#[tauri::command]
pub fn set_active_pet(app: AppHandle, id: String) -> Result<PetStatus, String> {
- let id = id.trim().to_string();
- validate_active_pet_id(&id)?;
+ let cleared = normalize_set_active_pet_id(&id)?;
let updated = config::update_store_dat_setting(&app, |setting| {
- setting.active_pet = Some(id);
+ setting.active_pet = cleared;
});
let status = status_from_setting(&updated);
emit_pet_status(&app, &status);
Ok(status)
}
+/// 选择 id 归一化:空串(去除首尾空白后)表示清除选择;非空沿用既有合法性校验
+///(预设安全字符集或来源限定 id),非法 id 保持报错而不静默清空。
+fn normalize_set_active_pet_id(id: &str) -> Result<Option<String>, String> {
+ let trimmed = id.trim();
+ if trimmed.is_empty() {
+ return Ok(None);
+ }
+ validate_active_pet_id(trimmed)?;
+ Ok(Some(trimmed.to_string()))
+}
+
/// 设置宠物大小百分比(设置页滑条,50–200),并实时同步窗口尺寸。
#[tauri::command]
pub fn set_pet_size(app: AppHandle, size: f64) -> Result<PetStatus, String> {
@@ -1214,6 +1227,26 @@ mod tests {
}
}
+ #[test]
+ fn set_active_pet_accepts_empty_as_clear() {
+ // 空串/纯空白表示清除选择:存 None(与全新安装一致),而不是非法 id 报错。
+ assert_eq!(normalize_set_active_pet_id(""), Ok(None));
+ assert_eq!(normalize_set_active_pet_id(" "), Ok(None));
+ // 非空保持既有校验:合法 id 原样存(去空白),非法 id 仍然报错。
+ assert_eq!(
+ normalize_set_active_pet_id(" maid-deepseek-whale "),
+ Ok(Some("maid-deepseek-whale".to_string()))
+ );
+ assert_eq!(
+ normalize_set_active_pet_id("chat:custom-pet"),
+ Ok(Some("chat:custom-pet".to_string()))
+ );
+ assert!(
+ normalize_set_active_pet_id("bad id").is_err(),
+ "非法 id 不应被静默当作清除"
+ );
+ }
+
#[test]
fn status_never_reports_visible_when_disabled() {
let setting = config::Setting {
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index f9986b34..b5e52ca2 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -7,12 +7,11 @@ mod task;
mod utils;
pub fn run() {
- // Wayland EGL workaround: AppImage bundles WebKitGTK may fail with
- // "Could not create default EGL display: EGL_BAD_PARAMETER" on Wayland
- // compositors (PikaOS/GNOME Wayland, Ubuntu 22.04+). Host WebKit (deb)
- // works, but AppImage needs compositing disabled. Auto-set when on Wayland
- // if user hasn't already set it — fixes hairyf#??? (PikaOS report).
- if std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland" {
+ // Wayland EGL workaround:仅 AppImage 需要(见 `should_apply_wayland_egl_workaround`)。
+ if should_apply_wayland_egl_workaround(
+ &std::env::var("XDG_SESSION_TYPE").unwrap_or_default(),
+ std::env::var_os("APPIMAGE").is_some(),
+ ) {
// 与 README 文档一致地同时关闭 compositing 与 DMABUF renderer:只关前者在部分
// 发行版/驱动上仍会 SIGSEGV(issue #116 的 WebKitGTK 崩溃)。两个参数互相独立,
// 用户已手动设置其中一个时只补齐另一个。
@@ -66,3 +65,33 @@ pub fn run() {
_ => {}
});
}
+
+/// Wayland EGL workaround 是否生效:仅 AppImage 需要。
+///
+/// AppImage 自带旧 WebKitGTK,打包库与宿主 Wayland 合成器 EGL 不兼容
+/// ("Could not create default EGL display: EGL_BAD_PARAMETER",PikaOS/GNOME
+/// Wayland、Ubuntu 22.04+),必须关闭合成与 DMABUF renderer 才能建窗。
+/// 宿主安装包(deb/rpm/…)用系统 WebKit,可正常创建 EGL 显示;且强制关闭合成
+/// 会破坏透明窗口(桌宠)与视频渲染,因此非 AppImage 运行时不再强制。
+/// AppImage 运行时必带 `APPIMAGE` 环境变量(runtime 规范),以此判定打包形态。
+fn should_apply_wayland_egl_workaround(session_type: &str, appimage_present: bool) -> bool {
+ session_type == "wayland" && appimage_present
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn wayland_workaround_only_inside_appimage() {
+ // AppImage + Wayland:保留旧行为,窗口能建起来。
+ assert!(should_apply_wayland_egl_workaround("wayland", true));
+ // 宿主安装包 + Wayland:系统 WebKit 可建 EGL 显示,不再强制关闭合成
+ //(否则透明桌宠窗口全黑、视频无法渲染)。
+ assert!(!should_apply_wayland_egl_workaround("wayland", false));
+ // 非 Wayland 会话:两种形态都不需要。
+ assert!(!should_apply_wayland_egl_workaround("x11", true));
+ assert!(!should_apply_wayland_egl_workaround("", true));
+ assert!(!should_apply_wayland_egl_workaround("", false));
+ }
+}