Skip to content

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

fix(linux): use host GStreamer for AppImage media (#1220)

Hairy6de27dadeaa3
diff --git a/scripts/fix-appimage-host-libs.sh b/scripts/fix-appimage-host-libs.sh
index 0aabb462..bcd33000 100755
--- a/scripts/fix-appimage-host-libs.sh
+++ b/scripts/fix-appimage-host-libs.sh
@@ -36,6 +36,16 @@ 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:]]*$'
+readonly GSTREAMER_SOURCE_PATTERN='^[[:space:]]*source[[:space:]].*apprun-hooks/linuxdeploy-plugin-gstreamer[.]sh[[:space:]]*$'
+readonly GSTREAMER_NATIVE_PATTERN='GST_PLUGIN_SYSTEM_PATH(_1_0)?='
+readonly EXCLUDED_MEDIA=(
+ 'libgst*.so*'
+ gstreamer-1.0
+ gstreamer1.0
+ gst-plugin-scanner
+ gst-ptp-helper
+ linuxdeploy-plugin-gstreamer.sh
+)
# 在镜像中扫描 squashfs 4.0 superblock:magic "hsqs",版本字段 s_major/s_minor == 4/0,
# block_size 为 2 的幂且在 [4096, 1048576],compression 在 1..6,block_log 与 block_size 自洽。
@@ -152,13 +162,27 @@ if [ ! -d "$tree" ]; then
fi
removed=()
-for lib in "${EXCLUDED_LIBS[@]}"; do
- while IFS= read -r found; do
- rm -f "$found"
+# #1209:整套媒体栈交给宿主,避免版本混用。
+for lib in "${EXCLUDED_LIBS[@]}" "${EXCLUDED_MEDIA[@]}"; do
+ while IFS= read -r -d '' found; do
+ rm -rf "$found"
removed+=("${found#"$tree"/}")
- done < <(find "$tree" -name "$lib" -print)
+ done < <(find "$tree" -name "$lib" -prune -print0)
done
+launcher_changed=0
+if grep -Eq "$GSTREAMER_SOURCE_PATTERN" "$tree/AppRun"; then
+ sed -Ei "\|$GSTREAMER_SOURCE_PATTERN|d" "$tree/AppRun"
+ launcher_changed=1
+fi
+
+native_changed=0
+# #1209:apprun-old 用 Qt 路径覆盖 GST;等长改名保留宿主默认值及用户配置。
+if [ -f "$tree/AppRun.wrapped" ] && grep -aEq "$GSTREAMER_NATIVE_PATTERN" "$tree/AppRun.wrapped"; then
+ sed -Ei 's/GST_PLUGIN_SYSTEM_PATH(_1_0)?=/DSH_PLUGIN_SYSTEM_PATH\1=/g' "$tree/AppRun.wrapped"
+ native_changed=1
+fi
+
hook_changed=0
# #789:在启动钩子处删除上游强制值,保留用户的 GDK_BACKEND 与其余 GTK 环境。
if [ -f "$tree/$GTK_HOOK" ] && grep -Eq "$GDK_OVERRIDE_PATTERN" "$tree/$GTK_HOOK"; then
@@ -168,13 +192,13 @@ 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
- echo " --require-removal was requested: the over-bundling this guards against (#620)" >&2
+ echo "fix-appimage-host-libs: none of the host-interface libraries or media stack were bundled, but" >&2
+ echo " --require-removal was requested: the over-bundling this guards against (#620, #1209)" >&2
echo " is no longer happening, or the bundler changed. Re-verify before dropping the fix." >&2
exit 1
fi
- if [ "$hook_changed" -eq 0 ]; then
- echo "fix-appimage-host-libs: no host-interface libs or forced GTK backend, nothing to do"
+ if [ "$hook_changed" -eq 0 ] && [ "$launcher_changed" -eq 0 ] && [ "$native_changed" -eq 0 ]; then
+ echo "fix-appimage-host-libs: no bundled host/media stack or forced GTK backend, nothing to do"
exit 0
fi
fi
@@ -215,12 +239,20 @@ else
fi
fi
-for lib in "${EXCLUDED_LIBS[@]}"; do
+for lib in "${EXCLUDED_LIBS[@]}" "${EXCLUDED_MEDIA[@]}"; do
if find "$verified" -name "$lib" -print -quit | grep -q .; then
echo "fix-appimage-host-libs: verification failed, $lib is still bundled" >&2
verdict=1
fi
done
+if [ -f "$verified/AppRun.wrapped" ] && grep -aEq "$GSTREAMER_NATIVE_PATTERN" "$verified/AppRun.wrapped"; then
+ echo "fix-appimage-host-libs: verification failed, native AppRun still overrides the host GStreamer path" >&2
+ verdict=1
+fi
+if grep -Eq "$GSTREAMER_SOURCE_PATTERN" "$verified/AppRun"; then
+ echo "fix-appimage-host-libs: verification failed, AppRun still sources the removed GStreamer hook" >&2
+ verdict=1
+fi
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
@@ -246,4 +278,4 @@ fi
[ "$verdict" -eq 0 ] || exit 1
mv "$work/out.AppImage" "$appimage"
-echo "fix-appimage-host-libs: repacked $(basename "$appimage") (${#removed[@]} host-interface libs dropped)"
+echo "fix-appimage-host-libs: repacked $(basename "$appimage") (${#removed[@]} bundled host/media entries dropped)"
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 18936947..64852f50 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -53,7 +53,7 @@
},
"linux": {
"appimage": {
- "bundleMediaFramework": true
+ "bundleMediaFramework": false
},
"deb": {
"depends": ["gstreamer1.0-plugins-good", "gstreamer1.0-plugins-bad"],
diff --git a/test/appimage-host-libs.test.ts b/test/appimage-host-libs.test.ts
index 4a83b5cd..99b2f45a 100644
--- a/test/appimage-host-libs.test.ts
+++ b/test/appimage-host-libs.test.ts
@@ -1,6 +1,6 @@
// @vitest-environment node
import { execFileSync } from 'node:child_process'
-import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { chmodSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
@@ -142,28 +142,70 @@ describe('appimage host-interface library exclusion (#620)', () => {
})
})
-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) => {
+describe('appimage host stack selection (#789, #1209)', () => {
+ it('uses the host GStreamer instead of additionally bundling the build-system media framework', () => {
+ const config = JSON.parse(readFileSync(fileURLToPath(new URL('../src-tauri/tauri.conf.json', import.meta.url)), 'utf8'))
+ expect(config.bundle.linux.appimage.bundleMediaFramework).toBe(false)
+ expect(config.bundle.linux.deb.depends).toEqual(expect.arrayContaining(['gstreamer1.0-plugins-good', 'gstreamer1.0-plugins-bad']))
+ })
+
+ it.skipIf(process.platform !== 'linux').each([
+ [false, false],
+ [false, true],
+ [true, false],
+ [true, true],
+ ])('repacks host libraries: %s, media stack: %s, and is idempotent', (bundledHostLibrary, bundledMedia) => {
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, 'AppRun'), `#!/usr/bin/env bash\nset -e\nthis_dir="$(readlink -f "$(dirname "$0")")"\n${bundledMedia ? 'source "$this_dir"/apprun-hooks/linuxdeploy-plugin-gstreamer.sh\n' : ''}source "$this_dir"/apprun-hooks/linuxdeploy-plugin-gtk.sh\nexec "$this_dir"/AppRun.wrapped "$@"\n`)
+ writeFileSync(join(tree, 'AppRun.wrapped'), `#!/bin/sh\nset -e\nexport GST_PLUGIN_SYSTEM_PATH="$APPDIR/usr/lib/gstreamer:$QT_PLUGIN_PATH"\nexport GST_PLUGIN_SYSTEM_PATH_1_0="$APPDIR/usr/lib/gstreamer-1.0:$QT_PLUGIN_PATH"\ntest "\${GST_PLUGIN_SYSTEM_PATH_1_0+x}" = "$1"\ntest "\${GST_PLUGIN_SYSTEM_PATH_1_0-}" = "$2"\n`)
+ chmodSync(join(tree, 'AppRun.wrapped'), 0o755)
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')
+ writeFileSync(join(tree, 'usr/lib/libgssapi_krb5.so.2'), 'keep unrelated library')
+ const mediaPaths = [
+ 'usr/lib/libgstreamer-1.0.so.0',
+ 'usr/lib/libgstreamer-1.0.so.0.2003.0',
+ 'usr/lib/libgstbase-1.0.so.0',
+ 'usr/lib/libgstapp-1.0.so.0',
+ 'usr/lib/gstreamer-1.0/libgstautodetect.so',
+ 'usr/lib/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner',
+ 'usr/libexec/gstreamer-1.0/gst-ptp-helper',
+ 'apprun-hooks/linuxdeploy-plugin-gstreamer.sh',
+ ]
+ if (bundledMedia) {
+ for (const path of mediaPaths) {
+ const target = join(tree, path)
+ mkdirSync(join(target, '..'), { recursive: true })
+ if (path === 'usr/lib/libgstreamer-1.0.so.0')
+ symlinkSync('libgstreamer-1.0.so.0.2003.0', target)
+ else
+ writeFileSync(target, path.endsWith('.sh') ? 'export GST_PLUGIN_SYSTEM_PATH_1_0="$APPDIR/usr/lib/gstreamer-1.0"\nexport GST_PLUGIN_SCANNER_1_0="$APPDIR/usr/lib/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner"\n' : 'drop bundled media')
+ }
+ }
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' })
+ execFileSync('bash', [fixScriptPath, ...(bundledHostLibrary || bundledMedia ? ['--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')
+ for (const path of mediaPaths)
+ expect(lstatSync(join(output, path), { throwIfNoEntry: false }), `${path} must come from the host`).toBeUndefined()
+ expect(readFileSync(join(output, 'usr/lib/libgssapi_krb5.so.2'), 'utf8')).toBe('keep unrelated library')
+ expect(readFileSync(join(output, 'AppRun'), 'utf8')).not.toContain('linuxdeploy-plugin-gstreamer.sh')
+ expect(readFileSync(join(output, 'AppRun.wrapped'), 'utf8')).not.toMatch(/GST_PLUGIN_SYSTEM_PATH(?:_1_0)?=/)
+ for (const mediaPath of [undefined, '', '/custom/media']) {
+ const env = { ...process.env, QT_PLUGIN_PATH: '/custom/qt', GST_PLUGIN_SYSTEM_PATH_1_0: mediaPath }
+ execFileSync('bash', [join(output, 'AppRun'), mediaPath === undefined ? '' : 'x', mediaPath ?? ''], { env, stdio: 'inherit' })
+ }
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], {