Skip to content

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

fix(desktop): 修复 Linux 语音输入不可用(权限、GStreamer 与录音编码) (#1171)

davidxy123eef482cc5f0b
diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml
index ecdbf935..597f19b1 100644
--- a/.github/workflows/build-linux.yml
+++ b/.github/workflows/build-linux.yml
@@ -100,6 +100,20 @@ jobs:
bash scripts/fix-appimage-host-libs.sh --require-removal "$appimage"
done
+ # linuxdeploy 的 gstreamer 插件按 Debian 布局写扫描器路径,而产物把
+ # gst-plugin-scanner 放在 usr/lib/gstreamer-1.0/;路径不存在时 WebKit 枚举不到
+ # 音频源,getUserMedia 直接 NotAllowedError(桌面端麦克风没有权限弹窗、录音永远为空)。
+ # 同时剔除 libgstpython:它会为 gst-plugin-scanner 初始化 CPython,宿主 python 缺
+ # gi 时每次采集都打印 pygobject CRITICAL。本步同样重写 AppImage 字节,必须在签名前。
+ - name: Fix GStreamer scanner paths and drop the Python plugin from the AppImage
+ 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-gstreamer.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/packages/dsh-tauri/src/host/apply.test.ts b/packages/dsh-tauri/src/host/apply.test.ts
index 15a5513b..1ca0fbb9 100644
--- a/packages/dsh-tauri/src/host/apply.test.ts
+++ b/packages/dsh-tauri/src/host/apply.test.ts
@@ -2,18 +2,22 @@ import type { HostContext, IndexInjectRow } from './types'
import { createContext, runInContext } from 'node:vm'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { apply } from './apply'
+import { MEDIA_RECORDER_SHIM_SCRIPT } from './media-recorder-shim'
afterEach(() => {
vi.unstubAllEnvs()
})
function activate() {
- let inject: ((table: IndexInjectRow[]) => void) | undefined
+ const listeners: ((table: IndexInjectRow[]) => void)[] = []
const on = vi.fn((event: string, listener: (table: IndexInjectRow[]) => void) => {
expect(event).toBe('webserver/index-inject')
- inject = listener
+ listeners.push(listener)
return () => {
- inject = undefined
+ const index = listeners.indexOf(listener)
+ if (index >= 0) {
+ listeners.splice(index, 1)
+ }
}
})
const ctx = {
@@ -25,7 +29,7 @@ function activate() {
apply(ctx)
return { on, collect: (): IndexInjectRow[] => {
const table: IndexInjectRow[] = []
- inject?.(table)
+ for (const listener of listeners) listener(table)
return table
} }
}
@@ -50,10 +54,9 @@ describe('desktop account marker', () => {
vi.stubEnv('DSH_TAURI_EMBEDDED', '1')
const { collect, on } = activate()
- expect(on).toHaveBeenCalledOnce()
+ expect(on).toHaveBeenCalled()
const rows = collect()
- expect(rows).toHaveLength(1)
- const row = rows[0]
+ const row = rows.find(item => item.kind === 'script' && item.text.includes('protocolVersion'))
expect(row?.kind).toBe('script')
expect(row?.kind === 'script' ? row.placement : undefined).toBe('head')
@@ -68,6 +71,14 @@ describe('desktop account marker', () => {
expect(runMarker(script, '?t=1')).toBeUndefined()
})
+ it('injects the media recorder shim into the head', () => {
+ vi.stubEnv('DSH_TAURI_EMBEDDED', '1')
+ const rows = activate().collect()
+
+ const shim = rows.find(item => item.kind === 'script' && item.text === MEDIA_RECORDER_SHIM_SCRIPT)
+ expect(shim?.kind === 'script' ? shim.placement : undefined).toBe('head')
+ })
+
it('does not advertise a desktop carrier to standalone web', () => {
vi.stubEnv('DSH_TAURI_EMBEDDED', '0')
const { collect, on } = activate()
@@ -76,3 +87,108 @@ describe('desktop account marker', () => {
expect(collect()).toEqual([])
})
})
+
+const WEBKITGTK_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15'
+const CHROME_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36'
+
+interface RecorderCall {
+ stream: unknown
+ options?: Record<string, unknown>
+}
+
+function installRecorder(userAgent: string) {
+ const calls: RecorderCall[] = []
+ class FakeMediaRecorder {
+ static isTypeSupported(type: string): boolean {
+ return type === 'audio/webm;codecs=opus' || type === 'audio/ogg;codecs=opus'
+ }
+
+ constructor(stream: unknown, options?: Record<string, unknown>) {
+ calls.push({ stream, options })
+ }
+ }
+ const sandbox: Record<string, unknown> = { navigator: { userAgent }, MediaRecorder: FakeMediaRecorder }
+ runInContext(MEDIA_RECORDER_SHIM_SCRIPT, createContext(sandbox))
+ return { sandbox, calls, original: FakeMediaRecorder }
+}
+
+interface RecorderInstance {
+ stream: unknown
+ options?: Record<string, unknown>
+}
+
+function recorderOf(sandbox: Record<string, unknown>) {
+ return sandbox.MediaRecorder as unknown as new (stream: unknown, options?: Record<string, unknown>) => RecorderInstance
+}
+
+describe('media recorder mime default', () => {
+ /** WebKitGTK 不指定 mimeType 时录不到数据;补默认类型是该脚本唯一目的。 */
+ it('fills a supported mimeType for default calls in WebKitGTK', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+
+ Reflect.construct(recorderOf(sandbox), ['stream'])
+
+ expect(calls).toHaveLength(1)
+ expect(calls[0]?.options).toEqual({ mimeType: 'audio/webm;codecs=opus' })
+ })
+
+ it('keeps explicit options untouched', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+
+ Reflect.construct(recorderOf(sandbox), ['stream', { mimeType: 'audio/ogg;codecs=opus', audioBitsPerSecond: 128000 }])
+
+ expect(calls[0]?.options).toEqual({ mimeType: 'audio/ogg;codecs=opus', audioBitsPerSecond: 128000 })
+ })
+
+ it('preserves other options when adding the mimeType', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+
+ Reflect.construct(recorderOf(sandbox), ['stream', { audioBitsPerSecond: 128000 }])
+
+ expect(calls[0]?.options).toEqual({ audioBitsPerSecond: 128000, mimeType: 'audio/webm;codecs=opus' })
+ })
+
+ it('leaves recorders without isTypeSupported untouched', () => {
+ class BareRecorder {}
+ const sandbox: Record<string, unknown> = { navigator: { userAgent: WEBKITGTK_UA }, MediaRecorder: BareRecorder }
+ runInContext(MEDIA_RECORDER_SHIM_SCRIPT, createContext(sandbox))
+
+ expect(sandbox.MediaRecorder).toBe(BareRecorder)
+ })
+
+ it('treats an empty mimeType as omitted', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+
+ Reflect.construct(recorderOf(sandbox), ['stream', { mimeType: '' }])
+
+ expect(calls[0]?.options).toEqual({ mimeType: 'audio/webm;codecs=opus' })
+ })
+
+ it('keeps native constructor semantics', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+ const Recorder = recorderOf(sandbox)
+ class SubRecorder extends Recorder {}
+ const sub = new SubRecorder('stream')
+
+ expect(sub).toBeInstanceOf(SubRecorder)
+ expect((sandbox.MediaRecorder as unknown as { name: string }).name).toBe('FakeMediaRecorder')
+ expect(() => (Recorder as unknown as (stream: unknown) => unknown)('stream')).toThrow(TypeError)
+ expect(calls).toHaveLength(1)
+ })
+
+ it('does not touch non-WebKitGTK pages', () => {
+ const { sandbox, original } = installRecorder(CHROME_UA)
+
+ expect(recorderOf(sandbox)).toBe(original)
+ })
+
+ it('wraps only once', () => {
+ const { sandbox, calls } = installRecorder(WEBKITGTK_UA)
+ runInContext(MEDIA_RECORDER_SHIM_SCRIPT, createContext(sandbox))
+
+ Reflect.construct(recorderOf(sandbox), ['stream'])
+
+ expect(calls).toHaveLength(1)
+ expect(calls[0]?.options).toEqual({ mimeType: 'audio/webm;codecs=opus' })
+ })
+})
diff --git a/packages/dsh-tauri/src/host/apply.ts b/packages/dsh-tauri/src/host/apply.ts
index 73201252..bd44d4f2 100644
--- a/packages/dsh-tauri/src/host/apply.ts
+++ b/packages/dsh-tauri/src/host/apply.ts
@@ -1,11 +1,13 @@
import type { ConnectionHost, HostContext } from './types'
import process from 'node:process'
import { PLUGIN_ID } from '../shared/constants'
+import { MEDIA_RECORDER_SHIM_SCRIPT } from './media-recorder-shim'
import { server } from './server'
import { gate } from './service/gate'
const GATE_EFFECT = `${PLUGIN_ID}: gate`
const ACCOUNT_EFFECT = `${PLUGIN_ID}: account desktop marker`
+const MEDIA_RECORDER_EFFECT = `${PLUGIN_ID}: media recorder mime default`
const ROUTES_EFFECT = `${PLUGIN_ID}: routes`
/**
@@ -33,5 +35,8 @@ export function apply(ctx: HostContext): void {
ctx.effect(() => ctx.on('webserver/index-inject', (table) => {
table.push({ kind: 'script', placement: 'head', text: ACCOUNT_MARKER_SCRIPT })
}), ACCOUNT_EFFECT)
+ ctx.effect(() => ctx.on('webserver/index-inject', (table) => {
+ table.push({ kind: 'script', placement: 'head', text: MEDIA_RECORDER_SHIM_SCRIPT })
+ }), MEDIA_RECORDER_EFFECT)
}
}
diff --git a/packages/dsh-tauri/src/host/media-recorder-shim.ts b/packages/dsh-tauri/src/host/media-recorder-shim.ts
new file mode 100644
index 00000000..608d32f6
--- /dev/null
+++ b/packages/dsh-tauri/src/host/media-recorder-shim.ts
@@ -0,0 +1,31 @@
+/**
+ * WebKitGTK 在不指定 `mimeType` 时构造 `MediaRecorder` 会启动但产不出任何 chunk,
+ * 上游语音插件因此把整段录音判为空(桌面端表现为「未识别到语音」)。本脚本在解析期
+ * 包装构造器:只在 Linux WebKitGTK 页面里,为缺省 `mimeType` 的调用补一个引擎支持的
+ * 编码类型;显式传参与其他录音选项保持原样,非 WebKitGTK 页面完全不介入。
+ *
+ * 走 `webserver/index-inject` 的 head 经典脚本通道,先于任何客户端模块执行,因此不依赖
+ * 上游包路径、文件内容或加载顺序。
+ */
+export const MEDIA_RECORDER_SHIM_SCRIPT = `(() => {
+ const Native = globalThis.MediaRecorder;
+ if (typeof Native !== "function" || Native.__dshDesktopMimeDefault) return;
+ if (typeof Native.isTypeSupported !== "function") return;
+ const ua = navigator.userAgent || "";
+ if (ua.indexOf("Linux") < 0 || ua.indexOf("AppleWebKit") < 0 || /Chrome|Chromium/.test(ua)) return;
+ const candidates = ["audio/webm;codecs=opus", "audio/ogg;codecs=opus", "audio/webm", "audio/ogg", "audio/mp4"];
+ const pick = () => candidates.find((type) => Native.isTypeSupported(type));
+ const WrappedMediaRecorder = new Proxy(Native, {
+ construct(target, args, newTarget) {
+ const options = args[1];
+ const explicit = options !== undefined && options !== null && typeof options.mimeType === "string" && options.mimeType !== "";
+ const mimeType = explicit ? undefined : pick();
+ if (mimeType === undefined) return Reflect.construct(target, args, newTarget);
+ const next = args.slice();
+ next[1] = Object.assign({}, options, { mimeType });
+ return Reflect.construct(target, next, newTarget);
+ }
+ });
+ Object.defineProperty(WrappedMediaRecorder, "__dshDesktopMimeDefault", { value: true });
+ globalThis.MediaRecorder = WrappedMediaRecorder;
+})();`
diff --git a/scripts/fix-appimage-gstreamer.sh b/scripts/fix-appimage-gstreamer.sh
new file mode 100755
index 00000000..87e36ed7
--- /dev/null
+++ b/scripts/fix-appimage-gstreamer.sh
@@ -0,0 +1,253 @@
+#!/usr/bin/env bash
+#
+# 修正 AppImage 内 GStreamer 的两处打包缺陷(桌面端麦克风/语音输入的根因)。
+#
+# 1) 删除 usr/lib/gstreamer-1.0/libgstpython*.so:GStreamer 做插件扫描时会为该插件
+# 初始化 CPython,而宿主 python3 没有 gi 时每次采集都打印
+# "pygobject initialization failed" 的 CRITICAL(WebKit 不用 Python 实现的元素)。
+# 在自带 python 的环境里更糟:init 直接致命退出,可能连带拖死插件扫描。
+# 2) 修正 apprun-hooks/linuxdeploy-plugin-gstreamer.sh 的辅助程序路径:linuxdeploy 的
+# gstreamer 插件按 Debian 布局写 usr/lib/gstreamer1.0/gstreamer-1.0/,而产物把
+# gst-plugin-scanner 放在 usr/lib/gstreamer-1.0/。路径不存在时 GStreamer 无法启动
+# 外部扫描器(日志为成片的 "External plugin loader failed"),WebKit 枚举不到任何
+# 音频源,getUserMedia 直接以 NotAllowedError 失败——桌面端因此既没有权限弹窗,
+# 也永远拿不到录音。
+#
+# 重打包复用原 AppImage 自带 runtime 前缀(head -c <offset>),与
+# fix-appimage-host-libs.sh 使用同一组 squashfs 参数,不依赖 appimagetool。
+set -euo pipefail
+
+readonly GST_DIR=usr/lib/gstreamer-1.0
+readonly GST_HOOK=apprun-hooks/linuxdeploy-plugin-gstreamer.sh
+readonly WRONG_PREFIX='usr/lib/gstreamer1.0/gstreamer-1.0/'
+readonly WRONG_PREFIX_SED='usr/lib/gstreamer1\.0/gstreamer-1\.0/'
+readonly RIGHT_PREFIX='usr/lib/gstreamer-1.0/'
+readonly SCANNER_NAME=gst-plugin-scanner
+readonly PTP_HELPER_NAME=gst-ptp-helper
+
+# 与 linuxdeploy 产出的 squashfs 对齐(实测 zstd / 128K block / 单一 root id)。
+readonly SQUASHFS_COMPRESSION=zstd
+readonly SQUASHFS_BLOCK_SIZE=131072
+
+# 在镜像中扫描 squashfs 4.0 superblock:magic "hsqs",版本字段 s_major/s_minor == 4/0,
+# block_size 为 2 的幂且在 [4096, 1048576],compression 在 1..6,block_log 与 block_size 自洽。
+# Type-2 AppImage 的尾部是 ELF runtime,正文里还可能出现字面量 "hsqs",因此必须逐个按
+# superblock 字段校验,而不是命中第一个 magic 就返回。
+detect_squashfs_offset() {
+ local file="$1"
+ python3 - "$file" <<'PY'
+import struct
+import sys
+
+path = sys.argv[1]
+with open(path, 'rb') as handle:
+ data = handle.read()
+
+start = 0
+while True:
+ index = data.find(b'hsqs', start)
+ if index < 0:
+ break
+ start = index + 1
+ if index + 32 > len(data):
+ continue
+ (magic, _inodes, _mtime, block_size, _fragments, compression, block_log,
+ _flags, _no_ids, s_major, s_minor) = struct.unpack_from('<IIIIIHHHHHH', data, index)
+ if magic != 0x73717368:
+ continue
+ if s_major != 4 or s_minor != 0:
+ continue
+ if block_size < 4096 or block_size > 1048576 or block_size & (block_size - 1):
+ continue
+ if compression < 1 or compression > 6:
+ continue
+ if (1 << block_log) != block_size:
+ continue
+ print(index)
+ sys.exit(0)
+sys.exit(1)
+PY
+}
+
+usage() {
+ echo "usage: $(basename "$0") [--require-removal] <path-to.AppImage>" >&2
+}
+
+# CI 用 --require-removal:linuxdeploy 若不再打包 libgstpython,剔除会静默变成 no-op。
+# 要求「至少删掉一个」把这种退化变成构建失败,提示重新核对(与 host-libs 脚本一致)。
+require_removal=0
+if [ "${1:-}" = "--require-removal" ]; then
+ require_removal=1
+ shift
+fi
+
+appimage="${1:-}"
+if [ -z "$appimage" ]; then
+ usage
+ exit 2
+fi
+if [ ! -f "$appimage" ]; then
+ echo "fix-appimage-gstreamer: no such file: $appimage" >&2
+ exit 1
+fi
+
+appimage="$(cd "$(dirname "$appimage")" && pwd)/$(basename "$appimage")"
+
+for tool in mksquashfs unsquashfs python3; do
+ if ! command -v "$tool" >/dev/null 2>&1; then
+ echo "fix-appimage-gstreamer: required tool not found: $tool" >&2
+ exit 1
+ fi
+done
+
+work="$(mktemp -d)"
+trap 'rm -rf "$work"' EXIT
+
+cp "$appimage" "$work/in.AppImage"
+chmod +x "$work/in.AppImage"
+
+# 先让 AppImage 自带 runtime 报出 squashfs 偏移并解包(不挂载 FUSE,容器里可直接跑)。
+# runtime 不可执行时(noexec 挂载等)退回扫描 superblock + unsquashfs -o。
+offset=""
+if offset="$("$work/in.AppImage" --appimage-offset 2>/dev/null)" && [ -n "$offset" ]; then
+ case "$offset" in
+ *[!0-9]*)
+ echo "fix-appimage-gstreamer: unexpected AppImage offset: $offset" >&2
+ exit 1
+ ;;
+ esac
+else
+ # 注意 set -e:赋值里的命令替换失败会直接终止脚本,因此必须用 `|| true` 兜住。
+ offset="$(detect_squashfs_offset "$work/in.AppImage" || true)"
+ if [ -z "$offset" ]; then
+ echo "fix-appimage-gstreamer: runtime unusable and no squashfs superblock found in $appimage" >&2
+ exit 1
+ fi
+ echo "fix-appimage-gstreamer: runtime unusable, scanned squashfs offset $offset"
+fi
+
+tree="$work/squashfs-root"
+if ! (
+ cd "$work"
+ ./in.AppImage --appimage-extract >/dev/null 2>&1
+) || [ ! -d "$tree" ]; then
+ rm -rf "$tree"
+ if ! unsquashfs -o "$offset" -d "$tree" "$work/in.AppImage" >/dev/null; then
+ echo "fix-appimage-gstreamer: extraction failed (runtime and unsquashfs)" >&2
+ exit 1
+ fi
+fi
+if [ ! -d "$tree" ]; then
+ echo "fix-appimage-gstreamer: extraction produced no root directory" >&2
+ exit 1
+fi
+
+if [ ! -d "$tree/$GST_DIR" ]; then
+ echo "fix-appimage-gstreamer: $GST_DIR is missing from the AppDir" >&2
+ exit 1
+fi
+
+removed=()
+while IFS= read -r found; do
+ rm -f "$found"
+ removed+=("${found#"$tree"/}")
+done < <(find "$tree/$GST_DIR" -maxdepth 1 -name 'libgstpython*.so' -print)
+
+hook_changed=0
+hook="$tree/$GST_HOOK"
+if [ -f "$hook" ] && grep -qF "$WRONG_PREFIX" "$hook"; then
+ sed -i "s|$WRONG_PREFIX_SED|$RIGHT_PREFIX|g" "$hook"
+ hook_changed=1
+fi
+if [ -f "$hook" ] && ! grep -q '^export GST_PLUGIN_SCANNER=' "$hook"; then
+ printf 'export GST_PLUGIN_SCANNER="${APPDIR}/%s%s"\n' "$RIGHT_PREFIX" "$SCANNER_NAME" >> "$hook"
+ hook_changed=1
+fi
+
+if [ "${#removed[@]}" -eq 0 ]; then
+ if [ "$require_removal" -eq 1 ]; then
+ echo "fix-appimage-gstreamer: no libgstpython plugin was bundled, but --require-removal" >&2
+ echo " was requested: the packaging changed. Re-verify before dropping the fix." >&2
+ exit 1
+ fi
+ if [ "$hook_changed" -eq 0 ]; then
+ echo "fix-appimage-gstreamer: no Python plugin and no wrong scanner path, nothing to do"
+ exit 0
+ fi
+fi
+
+if [ "${#removed[@]}" -gt 0 ]; then
+ echo "fix-appimage-gstreamer: removed from AppDir:"
+ printf ' %s\n' "${removed[@]}"
+fi
+if [ "$hook_changed" -eq 1 ]; then
+ echo "fix-appimage-gstreamer: corrected GStreamer helper paths in $GST_HOOK"
+fi
+
+head -c "$offset" "$work/in.AppImage" > "$work/out.AppImage"
+mksquashfs "$tree" "$work/fs.squashfs" \
+ -comp "$SQUASHFS_COMPRESSION" \
+ -b "$SQUASHFS_BLOCK_SIZE" \
+ -all-root -mkfs-time 0 -no-xattrs -noappend -no-progress -quiet
+cat "$work/fs.squashfs" >> "$work/out.AppImage"
+chmod +x "$work/out.AppImage"
+
+# 交付前自检:新镜像仍可解包、Python 插件确实消失、钩子不再引用不存在的目录、
+# 钩子指向的辅助程序真实存在、AppRun 与主程序仍在。
+verify="$work/verify"
+mkdir -p "$verify"
+verdict=0
+if (
+ cd "$verify"
+ ../out.AppImage --appimage-extract >/dev/null 2>&1
+) && [ -d "$verify/squashfs-root" ]; then
+ verified="$verify/squashfs-root"
+else
+ rm -rf "$verify/squashfs-root"
+ if unsquashfs -o "$offset" -d "$verify/squashfs-root" "$work/out.AppImage" >/dev/null 2>&1; then
+ verified="$verify/squashfs-root"
+ else
+ echo "fix-appimage-gstreamer: verification failed, repacked image cannot be extracted" >&2
+ exit 1
+ fi
+fi
+
+if find "$verified/$GST_DIR" -maxdepth 1 -name 'libgstpython*.so' -print -quit | grep -q .; then
+ echo "fix-appimage-gstreamer: verification failed, libgstpython is still bundled" >&2
+ verdict=1
+fi
+if [ -f "$verified/$GST_HOOK" ]; then
+ if grep -qF "$WRONG_PREFIX" "$verified/$GST_HOOK"; then
+ echo "fix-appimage-gstreamer: verification failed, hook still references $WRONG_PREFIX" >&2
+ verdict=1
+ fi
+ if ! grep -q '^export GST_PLUGIN_SCANNER=' "$verified/$GST_HOOK"; then
+ echo "fix-appimage-gstreamer: verification failed, hook lacks GST_PLUGIN_SCANNER" >&2
+ verdict=1
+ fi
+fi
+for helper in "$SCANNER_NAME" "$PTP_HELPER_NAME"; do
+ if [ -n "$(find "$verified/$GST_DIR" -maxdepth 1 -name "$helper" -print -quit)" ]; then
+ :
+ elif grep -qF "$helper" "$verified/$GST_HOOK" 2>/dev/null; then
+ echo "fix-appimage-gstreamer: verification failed, $helper is referenced but missing" >&2
+ verdict=1
+ fi
+done
+for required in AppRun AppRun.wrapped usr/bin/deepseek-harness-desktop; do
+ if [ ! -e "$verified/$required" ]; then
+ echo "fix-appimage-gstreamer: verification failed, $required is missing" >&2
+ verdict=1
+ fi
+done
+if [ "$verdict" -ne 0 ]; then
+ exit 1
+fi
+
+# 原子替换:先写同目录临时文件再 rename,避免中断留下半截 AppImage。
+tmp="$(mktemp "$(dirname "$appimage")/.$(basename "$appimage").XXXXXX")"
+cat "$work/out.AppImage" > "$tmp"
+chmod +x "$tmp"
+mv -f "$tmp" "$appimage"
+
+echo "fix-appimage-gstreamer: repacked $appimage"
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 4fadb827..2035bf93 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -1092,6 +1092,10 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We
// “源码”按钮在桌面端因此无法跳转(浏览器里正常)。
// 这里把 http(s) 链接交给系统浏览器打开,其余协议一律拒绝。
.on_new_window(move |url, features| on_new_window(app_handle.clone(), url, features))
+ .on_permission_request(|_, kind| match kind {
+ tauri::webview::PermissionKind::Microphone => tauri::webview::PermissionResponse::Allow,
+ _ => tauri::webview::PermissionResponse::Default,
+ })
.on_download(on_download);
#[cfg(windows)]
@@ -1211,6 +1215,10 @@ pub fn build_shell_window(
let webview_builder = webview_builder
.disable_drag_drop_handler()
.on_new_window(move |url, features| on_new_window(app_handle.clone(), url, features))
+ .on_permission_request(|_, kind| match kind {
+ tauri::webview::PermissionKind::Microphone => tauri::webview::PermissionResponse::Allow,
+ _ => tauri::webview::PermissionResponse::Default,
+ })
.on_download(on_download);
#[cfg(windows)]
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index dd28a819..e62439be 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -2,6 +2,22 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
+ // AppImage 的 AppRun 把 GST 扫描器指到不存在的目录、并把 PYTHONHOME 泄漏给所有子进程,
+ // 前者让 WebKitGTK 枚举不到任何音频源(getUserMedia 直接 NotAllowedError),后者让
+ // gst-plugin-scanner 内嵌的 Python 插件初始化失败、并污染 bash 工具里的 python3。
+ if let Ok(appdir) = std::env::var("APPDIR") {
+ let scanner = format!("{appdir}/usr/lib/gstreamer-1.0/gst-plugin-scanner");
+ if std::path::Path::new(&scanner).exists() {
+ std::env::set_var("GST_PLUGIN_SCANNER", &scanner);
+ std::env::set_var("GST_PLUGIN_SCANNER_1_0", &scanner);
+ }
+ for name in ["PYTHONHOME", "PYTHONPATH"] {
+ if std::env::var_os(name).is_some_and(|value| value.to_string_lossy().contains(&appdir)) {
+ std::env::remove_var(name);
+ }
+ }
+ }
+
// 无 GUI 的补丁入口:E2E 的插件 L2 直接起 `dsh web`,需要把 npm 装来的核心
// 打成与桌面端装配核心同样的形态。复用 lib 里的补丁集,而不是另抄一份实现。
let args: Vec<String> = std::env::args().collect();