The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(Linux): 发行包内置 fcitx5 与输入法插件 #1109
XiaoYouChR4655ce340344
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 9c1e59f6..b573360b 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -657,12 +657,70 @@ jobs:uv python install 3.13uv sync+ - name: Resolve fcitx5-qt plugin cache key+ id: fcitx5_meta+ run: |+ PYSIDE6_VERSION=$(uv run --no-sync python -c "import PySide6; print(PySide6.__version__)")+ FCITX5_QT_TAG=$(uv run --no-sync scripts/build_fcitx5_plugin.py --print-tag)+ echo "pyside6_version=$PYSIDE6_VERSION" >> "$GITHUB_OUTPUT"+ echo "fcitx5_qt_tag=$FCITX5_QT_TAG" >> "$GITHUB_OUTPUT"+ echo "PySide6=$PYSIDE6_VERSION fcitx5-qt=$FCITX5_QT_TAG"++ - name: Cache fcitx5-qt plugin+ id: fcitx5_cache+ uses: actions/cache@v6+ with:+ path: ~/.cache/fcitx5-qt-plugin+ key: fcitx5-qt-plugin-${{ matrix.architecture }}-${{ steps.fcitx5_meta.outputs.pyside6_version }}-${{ steps.fcitx5_meta.outputs.fcitx5_qt_tag }}++ - name: Build fcitx5-qt plugin+ if: ${{ steps.fcitx5_cache.outputs.cache-hit != 'true' }}+ run: |+ sudo apt-get install -y \+ cmake \+ ninja-build \+ pkg-config \+ extra-cmake-modules \+ libxkbcommon-dev \+ libxcb1-dev \+ libx11-dev \+ libwayland-dev \+ libgl-dev \+ patchelf+ uv run --no-sync scripts/build_fcitx5_plugin.py \+ --qt-version "${{ steps.fcitx5_meta.outputs.pyside6_version }}" \+ --arch "${{ matrix.architecture }}" \+ --tag "${{ steps.fcitx5_meta.outputs.fcitx5_qt_tag }}" \+ --output-dir ~/.cache/fcitx5-qt-plugin++ - name: Install fcitx5-qt plugin into PySide6+ run: |+ PLUGIN_DIR=$(uv run --no-sync python -c "import PySide6, pathlib; print(pathlib.Path(PySide6.__file__).parent / 'Qt/plugins/platforminputcontexts')")+ cp ~/.cache/fcitx5-qt-plugin/libfcitx5platforminputcontextplugin.so "$PLUGIN_DIR/"+- name: Build with Nuitkarun: |echo "VERSION=${{ needs.prepare.outputs.version }}" >> "$GITHUB_ENV"uv run scripts/deploy.pychmod +x "dist/Ghost-Downloader-3.dist/Ghost-Downloader-3.bin"+ - name: Verify Linux input method plugins+ run: |+ IM_DIR="dist/Ghost-Downloader-3.dist/PySide6/qt-plugins/platforminputcontexts"+ test -f "$IM_DIR/libfcitx5platforminputcontextplugin.so"+ test -f "$IM_DIR/libibusplatforminputcontextplugin.so"+ test -f "$IM_DIR/libcomposeplatforminputcontextplugin.so"+ test ! -f "$IM_DIR/libqtvirtualkeyboardplugin.so"+ for plugin in "$IM_DIR"/*.so; do+ echo "Checking $plugin"+ LDD_OUT=$(ldd "$plugin")+ echo "$LDD_OUT"+ if grep -q "not found" <<< "$LDD_OUT"; then+ echo "::error::Missing shared library dependency in $plugin"+ exit 1+ fi+ done+- name: Build .deb and .AppImagerun: |DIST_DIR="dist/Ghost-Downloader-3.dist"diff --git a/docs/adr/0034-bundle-fcitx5-qt-plugin-for-linux.md b/docs/adr/0034-bundle-fcitx5-qt-plugin-for-linux.mdnew file mode 100644index 00000000..bf2cee2a--- /dev/null+++ b/docs/adr/0034-bundle-fcitx5-qt-plugin-for-linux.md@@ -0,0 +1,19 @@+# Linux 发行包内置自编译的 fcitx5-qt 输入法插件++Linux 上的 `.AppImage`、`.deb` 与 `.tar.xz` 三种产物共用同一份 Nuitka 打包结果(`dist/Ghost-Downloader-3.dist`),自带 PySide6 捆绑的 Qt6 运行时。此前 `scripts/deploy.py` 只传了 `--include-qt-plugins=platforms`,不仅没有 fcitx5 插件,连 PySide6 自带的 `ibus` 和 `compose` 输入法插件也被漏掉,导致打包版无法在输入框中调起中文输入法(#1109)。++我们改为在打包阶段同时包含 `platforminputcontexts`(排除 `libqtvirtualkeyboardplugin.so` 及其库,避免拖入虚拟键盘与 QML 运行时),并在 Linux CI 构建中用与当前 PySide6 同版本的官方 Qt6 SDK(通过 `aqtinstall` 只拉取 `qtbase`、`qtwayland`、`icu`)以 `-DBUILD_ONLY_PLUGIN=ON` 编译 `fcitx/fcitx5-qt`,将产出的 `libfcitx5platforminputcontextplugin.so` 放入 venv 的 `PySide6/Qt/plugins/platforminputcontexts/`,交由 Nuitka 自动打包并修正 RPATH。++`BUILD_ONLY_PLUGIN=ON` 会把 `Fcitx5Qt6DBusAddons` 编为内部对象文件并静态链入插件,产出的 `.so` 不依赖宿主任何 `libfcitx5*` 动态库,仅依赖 PySide6 自带的 Qt6 库与系统基础库(`libxkbcommon`、`libxcb`),运行时通过 D-Bus 与宿主 fcitx5/fcitx4 通信。默认开启 `WITH_FCITX_PLUGIN_NAME=ON` 使单个插件同时响应 `QT_IM_MODULE=fcitx` 与 `fcitx5`,`ENABLE_QT6_WAYLAND_WORKAROUND=ON` 兼顾 Wayland 下显式设置 `QT_IM_MODULE=fcitx` 的场景。上游 `fcitx5-qt` 不写死版本,构建时动态解析最新稳定 semver tag,并以 `(architecture, pyside6_version, fcitx5_qt_tag)` 作为缓存键缓存 `.so`。++## Considered Options++- **复用宿主系统的 `fcitx5-qt` 插件(或升级 PySide6 对齐发行版 Qt 版本)**:`fcitx5-qt` 链接 `Qt6::GuiPrivate`,依赖 Qt 小版本专属的私有 API 符号(如 `QtPrivate_6_10_3`)。各 Linux 发行版自带的 Qt6 版本跨度极大(Ubuntu 22.04 为 6.2、Debian 12 为 6.4、Debian 13 为 6.8、Arch 滚动更新至 6.12+),靠升级 PySide6 对齐宿主版本无法跨发行版工作。+- **零编译方案(仅打包 PySide6 自带 `ibus` + 运行时改写环境变量走 Wayland 原生协议或 fcitx5 的 IBus Portal)**:改动小且零 CI 编译成本,但需要在应用启动时篡改进程内 `QT_IM_MODULES` / `IBUS_USE_PORTAL`,且依赖宿主 fcitx5 未关闭 `IBus Frontend`,同时不支持 fcitx4。相比之下,自编译插件运行时 0 改动、全环境原生兼容,配合缓存后长期维护成本也很低。+- **拆到独立仓库预编译 `fcitx5-qt`**:纯插件编译很轻,拆仓反而增加了每次升级 PySide6 时的手动联动成本。++## Consequences++- `scripts/deploy.py` 不夹带 fcitx5 特例,开发者在 Linux 本地直接运行 `deploy.py` 时不强制要求先编译 `fcitx5-qt`;发布包的完整性由 `build.yml` 中的插件存在性与 `ldd` 检查兜底。+- 升级 PySide6 后首次 Linux CI 构建会缓存未命中,自动拉取对应版本 Qt6 SDK 并重新编译 `fcitx5-qt` 插件;若上游 `fcitx5-qt` 某版出现编译回归,可通过 `scripts/build_fcitx5_plugin.py --tag` 临时指定版本排查。+- 仅靠 `ldd` 只能验证动态库依赖完整,实际输入体验仍需在 Linux(Wayland 与 X11 下均设置 `QT_IM_MODULE=fcitx`)手动验证。diff --git a/scripts/build_fcitx5_plugin.py b/scripts/build_fcitx5_plugin.pynew file mode 100644index 00000000..04439394--- /dev/null+++ b/scripts/build_fcitx5_plugin.py@@ -0,0 +1,131 @@+from __future__ import annotations++import argparse+import os+import platform+import re+import shutil+import subprocess+import tempfile+from pathlib import Path++FCITX5_QT_REPO = "https://github.com/fcitx/fcitx5-qt.git"+PLUGIN_FILENAME = "libfcitx5platforminputcontextplugin.so"++AQT_TARGETS: dict[str, tuple[str, str]] = {+ "x86_64": ("linux", "linux_gcc_64"),+ "aarch64": ("linux_arm64", "linux_gcc_arm64"),+ "arm64": ("linux_arm64", "linux_gcc_arm64"),+}+++def fetchLatestTag(repoUrl: str = FCITX5_QT_REPO) -> str:+ result = subprocess.run(+ ["git", "ls-remote", "--tags", repoUrl],+ check=True,+ capture_output=True,+ text=True,+ )+ tags = re.findall(r"\trefs/tags/(\d+\.\d+\.\d+)$", result.stdout, re.MULTILINE)+ if not tags:+ raise RuntimeError(f"No stable semver tag found in {repoUrl}")+ return max(tags, key=lambda tag: tuple(int(part) for part in tag.split(".")))+++def compilePlugin(qtVersion: str, arch: str, tag: str, outputFolder: Path) -> Path:+ targetInfo = AQT_TARGETS.get(arch.lower())+ if targetInfo is None:+ raise ValueError(f"Unsupported Linux architecture: {arch}")+ host, target = targetInfo++ with tempfile.TemporaryDirectory(prefix="fcitx5-qt-build-") as tempPath:+ workFolder = Path(tempPath)+ qtFolder = workFolder / "qt"+ sourceFolder = workFolder / "fcitx5-qt"+ buildFolder = workFolder / "build"++ # Qt6 官方 Linux 构建链接自带的 icu,缺它时 qmake/moc 无法启动+ subprocess.run(+ [+ "uvx", "--from", "aqtinstall", "aqt", "install-qt",+ host, "desktop", qtVersion, target,+ "--archives", "qtbase", "qtwayland", "icu",+ "-O", str(qtFolder),+ ],+ check=True,+ )++ versionFolder = qtFolder / qtVersion+ qtPrefix = next(+ (folder for folder in sorted(versionFolder.iterdir()) if (folder / "lib" / "cmake" / "Qt6").is_dir()),+ None,+ )+ if qtPrefix is None:+ raise FileNotFoundError(f"Qt6 CMake config folder not found under: {versionFolder}")++ subprocess.run(+ ["git", "clone", "--depth", "1", "--branch", tag, FCITX5_QT_REPO, str(sourceFolder)],+ check=True,+ )+ subprocess.run(+ [+ "cmake", "-S", str(sourceFolder), "-B", str(buildFolder), "-G", "Ninja",+ "-DCMAKE_BUILD_TYPE=Release",+ f"-DCMAKE_PREFIX_PATH={qtPrefix}",+ "-DBUILD_ONLY_PLUGIN=ON",+ "-DENABLE_QT4=OFF",+ "-DENABLE_QT5=OFF",+ "-DENABLE_QT6=ON",+ "-DENABLE_X11=ON",+ "-DWITH_FCITX_PLUGIN_NAME=ON",+ "-DENABLE_QT6_WAYLAND_WORKAROUND=ON",+ ],+ check=True,+ )+ subprocess.run(+ [+ "cmake", "--build", str(buildFolder),+ "--target", "fcitx5platforminputcontextplugin-qt6",+ f"-j{os.cpu_count() or 2}",+ ],+ check=True,+ )++ builtPlugin = buildFolder / "qt6" / "platforminputcontext" / PLUGIN_FILENAME+ outputFolder.mkdir(parents=True, exist_ok=True)+ targetPlugin = outputFolder / PLUGIN_FILENAME+ shutil.copy2(builtPlugin, targetPlugin)++ # 与 PySide6 自带 platforminputcontexts 插件保持一致,避免 Nuitka 追踪到临时 Qt 目录+ subprocess.run(["patchelf", "--set-rpath", "$ORIGIN/../../lib", str(targetPlugin)], check=True)+ return targetPlugin+++def main() -> int:+ parser = argparse.ArgumentParser(description="Compile fcitx5-qt Qt6 input context plugin matching PySide6.")+ parser.add_argument("--print-tag", action="store_true", help="Print the latest stable fcitx5-qt tag and exit.")+ parser.add_argument("--qt-version", default=None, help="Target Qt6 version (defaults to installed PySide6 version).")+ parser.add_argument("--arch", default=platform.machine(), help="Target Linux architecture (x86_64 or arm64).")+ parser.add_argument("--tag", default=None, help="fcitx5-qt git tag (defaults to latest stable tag).")+ parser.add_argument("--output-dir", type=Path, default=None, help="Folder to write the compiled .so file.")+ args = parser.parse_args()++ if args.print_tag:+ print(fetchLatestTag())+ return 0++ if args.output_dir is None:+ parser.error("--output-dir is required unless --print-tag is specified")++ qtVersion = args.qt_version+ if qtVersion is None:+ import PySide6+ qtVersion = PySide6.__version__++ plugin = compilePlugin(qtVersion, args.arch, args.tag or fetchLatestTag(), args.output_dir)+ print(f"Compiled {plugin}")+ return 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/scripts/deploy.py b/scripts/deploy.pyindex 011741ed..db7069c1 100644--- a/scripts/deploy.py+++ b/scripts/deploy.py@@ -24,11 +24,16 @@ EXTRA_INCLUDE_PACKAGES = []PLATFORM_INCLUDE_PACKAGES = {"win32": ["winrt"],}-# 应用不读 PDF 图像。只排除 PDF 插件时,Nuitka 仍会打包它依赖的 QtPdf,所以两个都排除。+# 应用不读 PDF 图像,也不需要虚拟键盘。只排除插件时 Nuitka 仍可能带入其依赖库,所以成对排除。PLATFORM_EXCLUDED_DLLS = {"win32": ["PySide6/qt-plugins/imageformats/qpdf.dll", "qt6pdf.dll"],"darwin": ["PySide6/qt-plugins/imageformats/libqpdf.dylib", "QtPdf"],- "linux": ["PySide6/qt-plugins/imageformats/libqpdf.so", "libQt6Pdf.so.6"],+ "linux": [+ "PySide6/qt-plugins/imageformats/libqpdf.so",+ "libQt6Pdf.so.6",+ "PySide6/qt-plugins/platforminputcontexts/libqtvirtualkeyboardplugin.so",+ "libQt6VirtualKeyboard.so.6",+ ],}EXTRA_INCLUDE_MODULES = ["app.view.dialogs.edit_task",@@ -186,7 +191,7 @@ def buildArgs() -> list[str]:*includeArgs,*dataArgs,*excludeArgs,- '--include-qt-plugins=platforms',+ '--include-qt-plugins=platforms,platforminputcontexts','--include-module=PySide6.QtDBus','--assume-yes-for-downloads','--linux-icon=app/assets/logo.png',