diff --git a/.github/scripts/verify-appimage-input-methods.sh b/.github/scripts/verify-appimage-input-methods.sh new file mode 100755 index 0000000000..d520a20f90 --- /dev/null +++ b/.github/scripts/verify-appimage-input-methods.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +set -euo pipefail + +die() { + echo "AppImage input-method verification failed: $*" >&2 + exit 1 +} + +if [[ $# -ne 1 ]]; then + die "usage: $0 " +fi + +input_path=$1 +if [[ -f "$input_path" ]]; then + appimage=$input_path +elif [[ -d "$input_path" ]]; then + appimages=() + while IFS= read -r -d '' candidate; do + appimages+=("$candidate") + done < <(find "$input_path" -maxdepth 1 -type f -name '*.AppImage' -print0) + [[ ${#appimages[@]} -eq 1 ]] \ + || die "expected exactly one AppImage in $input_path, found ${#appimages[@]}" + appimage=${appimages[0]} +else + die "path does not exist: $input_path" +fi +appimage=$(realpath "$appimage") + +work_dir=$(mktemp -d "${TMPDIR:-/tmp}/dbx-appimage-input-methods.XXXXXX") +trap 'rm -rf "$work_dir"' EXIT + +( + cd "$work_dir" + "$appimage" --appimage-extract >/dev/null +) +appdir="$work_dir/squashfs-root" +[[ -d "$appdir" ]] || die "AppImage extraction did not create squashfs-root" +appdir=$(realpath "$appdir") + +require_artifact() { + local basename=$1 + local match + local resolved + match=$(find "$appdir" \( -type f -o -type l \) -name "$basename" -print -quit) + [[ -n "$match" ]] || die "missing bundled artifact: $basename" + [[ -e "$match" ]] || die "bundled artifact is a broken symbolic link: ${match#"$appdir"/}" + resolved=$(realpath "$match") + [[ "$resolved" == "$appdir"/* ]] \ + || die "bundled artifact resolves outside the AppImage: ${match#"$appdir"/}" + echo "Found $basename at ${match#"$appdir"/}" +} + +require_artifact im-fcitx5.so +require_artifact im-ibus.so +require_artifact libFcitx5GClient.so.2 +require_artifact libibus-1.0.so.5 + +cache='' +while IFS= read -r -d '' candidate; do + if grep -Fq 'im-fcitx5.so' "$candidate" && grep -Fq 'im-ibus.so' "$candidate"; then + cache=$candidate + break + fi +done < <(find "$appdir" -type f -path '*/gtk-3.0/*/immodules.cache' -print0) + +[[ -n "$cache" ]] || die "no private GTK 3 immodules.cache registers both Fcitx 5 and IBus" +echo "Verified GTK input-method cache at ${cache#"$appdir"/}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e257bc2b3..2ce58c1a85 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -243,7 +243,9 @@ jobs: if: startsWith(matrix.platform, 'ubuntu') run: | sudo apt-get update - sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev xdg-utils + # Bundle GTK input-method modules from the same Jammy ABI baseline + # instead of loading potentially incompatible modules from the host. + sudo apt-get install -y fcitx5-frontend-gtk3 ibus-gtk3 libwebkit2gtk-4.1-dev libgtk-3-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev xdg-utils - name: Setup Tauri signing key shell: bash @@ -268,6 +270,11 @@ jobs: releaseDraft: true args: --target ${{ matrix.target }} + - name: Verify AppImage input methods + if: startsWith(matrix.platform, 'ubuntu') + shell: bash + run: ./.github/scripts/verify-appimage-input-methods.sh "target/${{ matrix.target }}/release/bundle/appimage" + - name: Show sccache stats if: always() continue-on-error: true diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c6e24a0eed..41ed539d53 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -463,19 +463,6 @@ fn linux_webkit_environment_override<'a>( existing_value.is_none().then_some(workaround_value) } -#[cfg_attr(not(target_os = "linux"), allow(dead_code))] -fn linux_system_gtk3_immodules_cache_path() -> Option<&'static str> { - [ - "/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache", - "/usr/lib/aarch64-linux-gnu/gtk-3.0/3.0.0/immodules.cache", - "/usr/lib64/gtk-3.0/3.0.0/immodules.cache", - "/usr/lib/gtk-3.0/3.0.0/immodules.cache", - ] - .iter() - .copied() - .find(|path| std::path::Path::new(path).is_file()) -} - #[cfg_attr(not(target_os = "linux"), allow(dead_code))] fn linux_appimage_wayland_backend_override( appimage: Option<&std::ffi::OsStr>, @@ -516,31 +503,6 @@ fn linux_uses_native_wayland( }) } -#[cfg_attr(not(target_os = "linux"), allow(dead_code))] -fn linux_appimage_system_gtk_immodules_cache( - appimage: Option<&std::ffi::OsStr>, - appdir: Option<&std::ffi::OsStr>, - gtk_im_module: Option<&std::ffi::OsStr>, - gtk_im_module_file: Option<&std::ffi::OsStr>, - system_cache_path: Option<&'static str>, -) -> Option<&'static str> { - let system_cache_path = system_cache_path?; - if appimage.is_none() || gtk_im_module.is_none() { - return None; - } - - let Some(gtk_im_module_file) = gtk_im_module_file else { - return Some(system_cache_path); - }; - let appdir = appdir?; - - if std::path::Path::new(gtk_im_module_file).starts_with(std::path::Path::new(appdir)) { - Some(system_cache_path) - } else { - None - } -} - #[cfg(target_os = "linux")] fn apply_linux_webkit_rendering_workarounds() { let render_devices = linux_drm_render_devices(); @@ -580,18 +542,6 @@ fn apply_linux_webkit_rendering_workarounds() { ) { std::env::set_var("GDK_BACKEND", gdk_backend); } - if let Some(gtk_im_module_file) = linux_appimage_system_gtk_immodules_cache( - std::env::var_os("APPIMAGE").as_deref(), - std::env::var_os("APPDIR").as_deref(), - std::env::var_os("GTK_IM_MODULE").as_deref(), - std::env::var_os("GTK_IM_MODULE_FILE").as_deref(), - linux_system_gtk3_immodules_cache_path(), - ) { - // linuxdeploy-plugin-gtk points GTK_IM_MODULE_FILE at the bundled - // cache. That hides host IM modules such as fcitx5/ibus, so prefer the - // host GTK cache when the user has configured a GTK input method. - std::env::set_var("GTK_IM_MODULE_FILE", gtk_im_module_file); - } } /// Brings the main window to the foreground, reporting whether it ended up visible. @@ -1003,22 +953,19 @@ pub(crate) fn apply_desktop_settings(app: &tauri::AppHandle, desktop_settings: & #[allow(clippy::items_after_test_module)] mod tests { use super::{ - app_menu_copy_support_info_label, app_menu_quit_label, linux_appimage_system_gtk_immodules_cache, - linux_appimage_wayland_backend_override, linux_drm_driver_is_software_only, - linux_drm_render_devices_from_paths, linux_nvidia_driver_from_state, linux_pci_id_from_sysfs_value, - linux_selected_drm_render_device, linux_uses_native_wayland, linux_webkit_environment_override, - linux_webkit_rendering_workarounds, native_window_decorations_override, should_confirm_app_exit_request, - should_enable_single_instance, should_fallback_to_native_quit, should_hide_window_on_close, - should_setup_desktop_tray, should_show_main_window_after_setup, should_show_main_window_before_setup_tasks, - startup_data_dir_mode, tray_menu_labels_for_locale, uses_application_level_icon, LinuxDrmRenderDevice, - LinuxNvidiaDriver, + app_menu_copy_support_info_label, app_menu_quit_label, linux_appimage_wayland_backend_override, + linux_drm_driver_is_software_only, linux_drm_render_devices_from_paths, linux_nvidia_driver_from_state, + linux_pci_id_from_sysfs_value, linux_selected_drm_render_device, linux_uses_native_wayland, + linux_webkit_environment_override, linux_webkit_rendering_workarounds, native_window_decorations_override, + should_confirm_app_exit_request, should_enable_single_instance, should_fallback_to_native_quit, + should_hide_window_on_close, should_setup_desktop_tray, should_show_main_window_after_setup, + should_show_main_window_before_setup_tasks, startup_data_dir_mode, tray_menu_labels_for_locale, + uses_application_level_icon, LinuxDrmRenderDevice, LinuxNvidiaDriver, }; use crate::data_dir::DataDirMode; use std::ffi::OsStr; use std::path::{Path, PathBuf}; - const TEST_GTK3_IMMODULES_CACHE: &str = "/usr/lib/test/gtk-3.0/3.0.0/immodules.cache"; - #[test] fn tray_menu_labels_follow_locale() { assert_eq!(tray_menu_labels_for_locale("zh-CN"), ("显示 DBX", "退出 DBX")); @@ -1437,78 +1384,6 @@ mod tests { assert_eq!(linux_appimage_wayland_backend_override(Some(OsStr::new("/tmp/DBX.AppImage")), None, None), None); assert_eq!(linux_appimage_wayland_backend_override(None, Some(OsStr::new("wayland-0")), None), None); } - - #[test] - fn prefers_system_gtk_immodules_cache_for_appimage_input_methods() { - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - Some(OsStr::new("/tmp/DBX.AppImage")), - Some(OsStr::new("/tmp/.mount_DBX123")), - Some(OsStr::new("fcitx5")), - Some(OsStr::new("/tmp/.mount_DBX123/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache")), - Some(TEST_GTK3_IMMODULES_CACHE), - ), - Some(TEST_GTK3_IMMODULES_CACHE) - ); - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - Some(OsStr::new("/tmp/DBX.AppImage")), - Some(OsStr::new("/tmp/.mount_DBX123")), - Some(OsStr::new("ibus")), - None, - Some(TEST_GTK3_IMMODULES_CACHE), - ), - Some(TEST_GTK3_IMMODULES_CACHE) - ); - } - - #[test] - fn preserves_external_gtk_immodules_cache_overrides() { - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - Some(OsStr::new("/tmp/DBX.AppImage")), - Some(OsStr::new("/tmp/.mount_DBX123")), - Some(OsStr::new("fcitx5")), - Some(OsStr::new("/opt/custom/immodules.cache")), - Some(TEST_GTK3_IMMODULES_CACHE), - ), - None - ); - } - - #[test] - fn skips_system_gtk_immodules_cache_without_required_context() { - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - None, - Some(OsStr::new("/tmp/.mount_DBX123")), - Some(OsStr::new("fcitx5")), - Some(OsStr::new("/tmp/.mount_DBX123/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache")), - Some(TEST_GTK3_IMMODULES_CACHE), - ), - None - ); - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - Some(OsStr::new("/tmp/DBX.AppImage")), - Some(OsStr::new("/tmp/.mount_DBX123")), - None, - Some(OsStr::new("/tmp/.mount_DBX123/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache")), - Some(TEST_GTK3_IMMODULES_CACHE), - ), - None - ); - assert_eq!( - linux_appimage_system_gtk_immodules_cache( - Some(OsStr::new("/tmp/DBX.AppImage")), - Some(OsStr::new("/tmp/.mount_DBX123")), - Some(OsStr::new("fcitx5")), - Some(OsStr::new("/tmp/.mount_DBX123/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache")), - None, - ), - None - ); - } } #[cfg_attr(mobile, tauri::mobile_entry_point)]