Skip to content

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

fix(linux): strip forced GTK backend from AppImage hook (#1050)

Mao Mr8445cfc580c5
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index 25f37ca5..b22c58e6 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -112,7 +112,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
- sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf gstreamer1.0-plugins-good gstreamer1.0-plugins-bad
+ sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf squashfs-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad
- name: Install frontend dependencies
run: pnpm install --frozen-lockfile
@@ -125,6 +125,15 @@ jobs:
- name: Build packages
run: pnpm tauri build --bundles appimage,deb ${{ inputs.nightly && '--config src-tauri/tauri.nightly.conf.json' || '' }}
+ - name: Fix AppImage host libraries and GTK backend
+ shell: bash
+ run: |
+ mapfile -d '' appimages < <(find src-tauri/target/release/bundle/appimage -name '*.AppImage' -print0)
+ [ "${#appimages[@]}" -gt 0 ] || { echo '::error::no AppImage was produced'; exit 1; }
+ for appimage in "${appimages[@]}"; do
+ bash scripts/fix-appimage-host-libs.sh --require-removal "$appimage"
+ done
+
- name: Normalize release asset names
run: node scripts/rename-release-assets.mjs src-tauri/target/release/bundle/appimage src-tauri/target/release/bundle/deb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 01de1531..21dd7471 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -56,6 +56,15 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
+ - name: Install AppImage regression tools
+ run: sudo apt-get update && sudo apt-get install -y squashfs-tools
+
+ - name: Test AppImage repacking
+ run: |
+ for seed in 1 2 3 4 5; do
+ node node_modules/vitest/vitest.mjs run --project unit test/appimage-host-libs.test.ts --sequence.shuffle --sequence.seed="$seed"
+ done
+
- name: Test iOS signing guards without credentials
run: python3 -m unittest discover -s .github/scripts -p 'test_ios_testflight.py' -v
diff --git a/scripts/fix-appimage-host-libs.sh b/scripts/fix-appimage-host-libs.sh
index 08910992..0aabb462 100755
--- a/scripts/fix-appimage-host-libs.sh
+++ b/scripts/fix-appimage-host-libs.sh
@@ -34,6 +34,8 @@ readonly EXCLUDED_LIBS=(
# 与 linuxdeploy 产出的 squashfs 对齐(实测 zstd / 128K block / 单一 root id)。
readonly SQUASHFS_COMPRESSION=zstd
readonly SQUASHFS_BLOCK_SIZE=131072
+readonly GTK_HOOK=apprun-hooks/linuxdeploy-plugin-gtk.sh
+readonly GDK_OVERRIDE_PATTERN='^[[:space:]]*export[[:space:]]+GDK_BACKEND=x11([[:space:]]+#.*)?[[:space:]]*$'
# 在镜像中扫描 squashfs 4.0 superblock:magic "hsqs",版本字段 s_major/s_minor == 4/0,
# block_size 为 2 的幂且在 [4096, 1048576],compression 在 1..6,block_log 与 block_size 自洽。
@@ -157,6 +159,13 @@ for lib in "${EXCLUDED_LIBS[@]}"; do
done < <(find "$tree" -name "$lib" -print)
done
+hook_changed=0
+# #789:在启动钩子处删除上游强制值,保留用户的 GDK_BACKEND 与其余 GTK 环境。
+if [ -f "$tree/$GTK_HOOK" ] && grep -Eq "$GDK_OVERRIDE_PATTERN" "$tree/$GTK_HOOK"; then
+ sed -Ei "/$GDK_OVERRIDE_PATTERN/d" "$tree/$GTK_HOOK"
+ hook_changed=1
+fi
+
if [ "${#removed[@]}" -eq 0 ]; then
if [ "$require_removal" -eq 1 ]; then
echo "fix-appimage-host-libs: none of the host-interface libs were bundled, but" >&2
@@ -164,12 +173,19 @@ if [ "${#removed[@]}" -eq 0 ]; then
echo " is no longer happening, or the bundler changed. Re-verify before dropping the fix." >&2
exit 1
fi
- echo "fix-appimage-host-libs: none of the host-interface libs were bundled, nothing to do"
- exit 0
+ if [ "$hook_changed" -eq 0 ]; then
+ echo "fix-appimage-host-libs: no host-interface libs or forced GTK backend, nothing to do"
+ exit 0
+ fi
fi
-echo "fix-appimage-host-libs: removed from AppDir:"
-printf ' %s\n' "${removed[@]}"
+if [ "${#removed[@]}" -gt 0 ]; then
+ echo "fix-appimage-host-libs: removed from AppDir:"
+ printf ' %s\n' "${removed[@]}"
+fi
+if [ "$hook_changed" -eq 1 ]; then
+ echo "fix-appimage-host-libs: removed GTK hook's forced GDK_BACKEND=x11"
+fi
head -c "$offset" "$work/in.AppImage" > "$work/out.AppImage"
mksquashfs "$tree" "$work/fs.squashfs" \
@@ -205,6 +221,14 @@ for lib in "${EXCLUDED_LIBS[@]}"; do
verdict=1
fi
done
+if [ -f "$verified/$GTK_HOOK" ] && grep -Eq "$GDK_OVERRIDE_PATTERN" "$verified/$GTK_HOOK"; then
+ echo "fix-appimage-host-libs: verification failed, GTK hook still forces GDK_BACKEND=x11" >&2
+ verdict=1
+fi
+if [ "$hook_changed" -eq 1 ] && [ ! -f "$verified/$GTK_HOOK" ]; then
+ echo "fix-appimage-host-libs: verification failed, GTK hook is missing" >&2
+ verdict=1
+fi
for required in AppRun AppRun.wrapped; do
if [ ! -e "$verified/$required" ]; then
echo "fix-appimage-host-libs: verification failed, $required is missing" >&2
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 03be7b2e..1aaf5d5a 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -17,8 +17,7 @@ pub fn patch_core_dir(core_dir: &std::path::Path) -> Result<(), String> {
service::patch::apply_all_at(core_dir)
}
-/// 应用入口:先做 Wayland 环境兼容(见 `should_apply_wayland_egl_workaround` 与
-/// `should_restore_wayland_backend`),再初始化日志、装配桌面端并进入事件循环。
+/// 应用入口:先做 Wayland 环境兼容,再初始化日志、装配桌面端并进入事件循环。
pub fn run() -> Result<(), String> {
desktop::startup::verify()?;
// Wayland EGL workaround:仅 AppImage 需要(见 `should_apply_wayland_egl_workaround`)。
@@ -47,22 +46,6 @@ pub fn run() -> Result<(), String> {
// GDK 只在初始化时读一次 GDK_BACKEND,建窗之后再改无效。
let force_xwayland =
config::force_xwayland_setting() || std::env::var_os("DSH_FORCE_XWAYLAND").is_some();
- // AppImage 的 GTK 钩子把 GDK_BACKEND 强制成 x11(见 `should_restore_wayland_backend`):
- // 默认丢掉,让 GTK 与 WebKit 一起走原生 Wayland;用户显式要 XWayland 时不动它。
- if should_restore_wayland_backend(
- std::env::var_os("APPIMAGE").is_some(),
- &std::env::var("WAYLAND_DISPLAY").unwrap_or_default(),
- &std::env::var("GDK_BACKEND").unwrap_or_default(),
- ) && !force_xwayland
- {
- std::env::remove_var("GDK_BACKEND");
- // 同上,logger::init() 尚未执行,只能用 eprintln。这里是「原生 Wayland 反而起不来」
- // 时唯一的提示位:那种情况下窗口不会出现,用户在应用内看不到任何日志或设置项。
- eprintln!(
- "[wayland] dropped the AppImage hook's GDK_BACKEND=x11 to use native Wayland (issue #789)"
- );
- eprintln!("[wayland] set DSH_FORCE_XWAYLAND=1 to keep XWayland instead");
- }
if should_force_xwayland(
force_xwayland,
&std::env::var("WAYLAND_DISPLAY").unwrap_or_default(),
@@ -142,35 +125,6 @@ fn should_apply_wayland_egl_workaround(session_type: &str, appimage_present: boo
session_type == "wayland" && appimage_present
}
-/// AppImage 的 GTK 启动钩子强制出来的 XWayland 后端是否应被丢弃。
-///
-/// linuxdeploy-plugin-gtk 为绕开 tauri#8541(Ubuntu 20.04 构建的 AppImage 在 Fedora 39
-/// 上以 `GLib-GIO-ERROR … xsettings` 退出)无条件 `export GDK_BACKEND=x11`,于是 Wayland
-/// 会话下的 AppImage 永远以 XWayland 客户身份运行 GTK3,并按 AppImage 自带的 immodules
-/// 缓存选中 XIM 输入法模块。上游已认定这是缺陷:tauri#15781「钩子覆盖用户显式设置的
-/// GDK_BACKEND,静默降级到 XWayland 且不报错」,#11790 记下的结论是「hardcoded,需要时
-/// 从 Rust 侧覆盖」,PR #16062 已在 dev 分支删掉该行但尚未发布,linuxdeploy-plugin-gtk
-/// 的 master 也仍在使用它(`@tauri-apps/cli` 2.11.4 在 tools 目录缺失时直接下载 master)。
-///
-/// issue #789 的现场与该降级吻合:Wayland + AppImage 下点击内嵌 iframe 后整个 WebView
-/// 不再出帧(顶层 navbar 照常可点,拖窗口边框才刷出几帧,剪贴板为空)。丢掉强制值后
-/// GTK 与 WebKit 同样工作在 Wayland 上,不再出现 X11 窗口配 Wayland 加速面的错配。
-/// 判定用 `WAYLAND_DISPLAY` 而非 `XDG_SESSION_TYPE`:后者由 pam_systemd 设置,从 TTY
-/// 直接起的合成器下为空,而 GDK 照样连上 Wayland(与 [`pet_overlay_supported`] 同一理由)。
-///
-/// 只认裸 `x11`:`wayland` / `x11,wayland` 这类优先级列表只可能来自用户或启动脚本,不覆盖。
-///
-/// `force_xwayland` 2026-09-23 才引入(38d7f01b),晚于标识符改短(67f058c9,
-/// 2026-09-21):可能含该键的 store 只存在于当前标识符目录下,读取不会漏掉
-/// 任何已持久化的用户意图。
-fn should_restore_wayland_backend(
- appimage_present: bool,
- wayland_display: &str,
- gdk_backend: &str,
-) -> bool {
- appimage_present && !wayland_display.is_empty() && gdk_backend == "x11"
-}
-
/// 桌宠窗口的置顶与绝对定位能力是否可用。
///
/// xdg-shell 不提供这两项能力。tao 的 Linux 后端基于 GTK3,`always_on_top` 与
@@ -244,28 +198,6 @@ mod tests {
assert!(!should_apply_wayland_egl_workaround("", false));
}
- #[test]
- fn appimage_hook_forced_x11_backend_is_dropped_on_wayland() {
- // AppImage 自带钩子的强制值 + Wayland 套接字可用:丢弃,改走原生 Wayland。
- assert!(should_restore_wayland_backend(true, "wayland-0", "x11"));
- // 用户或启动脚本显式给的优先级列表不是钩子的裸 x11,保持权威。
- assert!(!should_restore_wayland_backend(
- true,
- "wayland-0",
- "wayland"
- ));
- assert!(!should_restore_wayland_backend(
- true,
- "wayland-0",
- "x11,wayland"
- ));
- // 没有 Wayland 套接字(纯 X11 会话 / macOS / Windows):GDK 自己挑后端。
- assert!(!should_restore_wayland_backend(true, "", "x11"));
- // 宿主安装包没有该钩子,变量来自用户,不动。
- assert!(!should_restore_wayland_backend(false, "wayland-0", "x11"));
- assert!(!should_restore_wayland_backend(false, "wayland-0", ""));
- }
-
#[test]
fn pet_overlay_unsupported_only_on_native_wayland() {
// 原生 Wayland:GTK 的置顶与定位调用是 no-op,桌宠被主窗口遮挡。
diff --git a/test/appimage-host-libs.test.ts b/test/appimage-host-libs.test.ts
index b47a78a6..4a83b5cd 100644
--- a/test/appimage-host-libs.test.ts
+++ b/test/appimage-host-libs.test.ts
@@ -1,6 +1,8 @@
// @vitest-environment node
import { execFileSync } from 'node:child_process'
-import { readFileSync } from 'node:fs'
+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
@@ -140,20 +142,68 @@ describe('appimage host-interface library exclusion (#620)', () => {
})
})
-describe('linux release workflow wires the appimage fix', () => {
+describe('appimage GTK backend selection (#789)', () => {
+ it.skipIf(process.platform !== 'linux').each([false, true])('repacks GTK hook (bundled host library: %s), preserves backends, and is idempotent', (bundledHostLibrary) => {
+ const work = mkdtempSync(join(tmpdir(), 'dsh-appimage-'))
+ try {
+ const tree = join(work, 'AppDir')
+ mkdirSync(join(tree, 'apprun-hooks'), { recursive: true })
+ mkdirSync(join(tree, 'usr/lib'), { recursive: true })
+ mkdirSync(join(tree, 'usr/bin'), { recursive: true })
+ writeFileSync(join(tree, 'AppRun'), '#!/bin/sh\nexit 0\n')
+ writeFileSync(join(tree, 'AppRun.wrapped'), '#!/bin/sh\nexit 0\n')
+ writeFileSync(join(tree, 'usr/bin/app'), '#!/bin/sh\nexit 0\n')
+ chmodSync(join(tree, 'usr/bin/app'), 0o755)
+ writeFileSync(join(tree, 'usr/lib/libwebkit2gtk-4.1.so.0'), 'keep WebKit')
+ if (bundledHostLibrary)
+ writeFileSync(join(tree, 'usr/lib/libwayland-client.so.0'), 'drop host library')
+ writeFileSync(join(tree, 'apprun-hooks/linuxdeploy-plugin-gtk.sh'), 'export GTK_THEME=Adwaita\nexport GDK_BACKEND=x11 # upstream override\nexport GTK_DATA_PREFIX="$APPDIR"\n')
+ const image = join(work, 'test.AppImage')
+ execFileSync('mksquashfs', [tree, image, '-noappend', '-quiet', '-no-progress'], { stdio: 'inherit' })
+ execFileSync('bash', [fixScriptPath, ...(bundledHostLibrary ? ['--require-removal'] : []), image], { stdio: 'inherit' })
+ const output = join(work, 'unpacked')
+ execFileSync('unsquashfs', ['-d', output, image], { stdio: 'ignore' })
+ const hook = join(output, 'apprun-hooks/linuxdeploy-plugin-gtk.sh')
+ expect(readFileSync(hook, 'utf8')).toBe('export GTK_THEME=Adwaita\nexport GTK_DATA_PREFIX="$APPDIR"\n')
+ for (const backend of ['', 'wayland', 'x11', 'x11,wayland']) {
+ execFileSync('bash', ['-c', 'source "$1"; test "$GDK_BACKEND" = "$2" && test "$GTK_THEME" = Adwaita', '_', hook, backend], {
+ env: { ...process.env, GDK_BACKEND: backend },
+ stdio: 'inherit',
+ })
+ }
+ const fixed = readFileSync(image)
+ execFileSync('bash', [fixScriptPath, image], { stdio: 'inherit' })
+ expect(readFileSync(image)).toEqual(fixed)
+ expect(bashExitCode([fixScriptPath, '--require-removal', image])).toBe(1)
+ }
+ finally {
+ rmSync(work, { recursive: true, force: true })
+ }
+ })
+
+ it('does not discard explicit GDK_BACKEND values at runtime', () => {
+ const startup = readFileSync(fileURLToPath(new URL('../src-tauri/src/lib.rs', import.meta.url)), 'utf8')
+ expect(startup).not.toContain('std::env::remove_var("GDK_BACKEND")')
+ })
+})
+
+describe.each([
+ ['release', linuxWorkflow],
+ ['unsigned', readFileSync(fileURLToPath(new URL('../.github/workflows/build-test.yml', import.meta.url)), 'utf8').split(' linux:')[1].split(' windows:')[0]],
+])('linux %s workflow wires the appimage fix', (_name, workflow) => {
it('installs squashfs-tools for mksquashfs', () => {
- expect(linuxWorkflow).toContain('squashfs-tools')
+ expect(workflow).toContain('squashfs-tools')
})
it('runs the fix with --require-removal for every built AppImage', () => {
- expect(linuxWorkflow).toContain('scripts/fix-appimage-host-libs.sh --require-removal')
- expect(linuxWorkflow).toContain('find src-tauri/target/release/bundle/appimage -name \'*.AppImage\'')
+ expect(workflow).toContain('scripts/fix-appimage-host-libs.sh --require-removal')
+ expect(workflow).toContain('find src-tauri/target/release/bundle/appimage -name \'*.AppImage\'')
})
it('runs the fix after the bundle and before uploading artifacts', () => {
- const bundleIndex = linuxWorkflow.indexOf('pnpm tauri build --bundles appimage,deb')
- const fixIndex = linuxWorkflow.indexOf('scripts/fix-appimage-host-libs.sh --require-removal')
- const uploadIndex = linuxWorkflow.indexOf('actions/upload-artifact')
+ const bundleIndex = workflow.indexOf('pnpm tauri build --bundles appimage,deb')
+ const fixIndex = workflow.indexOf('scripts/fix-appimage-host-libs.sh --require-removal')
+ const uploadIndex = workflow.indexOf('actions/upload-artifact')
expect(bundleIndex).toBeGreaterThan(-1)
expect(fixIndex).toBeGreaterThan(-1)