From 423ab95c2b4b4d7551d35eb80a54c12ebcb1abc8 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Sun, 24 Nov 2024 18:36:07 +0100 Subject: [PATCH] remove env vars --- .../linux/{appimage/mod.rs => appimage.rs} | 33 ++++--- .../src/bundle/linux/appimage/appimage | 86 ------------------- crates/tauri-bundler/src/bundle/settings.rs | 2 + crates/tauri-cli/src/bundle.rs | 18 ---- crates/tauri-cli/src/interface/rust.rs | 13 ++- 5 files changed, 29 insertions(+), 123 deletions(-) rename crates/tauri-bundler/src/bundle/linux/{appimage/mod.rs => appimage.rs} (93%) delete mode 100644 crates/tauri-bundler/src/bundle/linux/appimage/appimage diff --git a/crates/tauri-bundler/src/bundle/linux/appimage/mod.rs b/crates/tauri-bundler/src/bundle/linux/appimage.rs similarity index 93% rename from crates/tauri-bundler/src/bundle/linux/appimage/mod.rs rename to crates/tauri-bundler/src/bundle/linux/appimage.rs index 263b80d322ed..d4aae7c0f67b 100644 --- a/crates/tauri-bundler/src/bundle/linux/appimage/mod.rs +++ b/crates/tauri-bundler/src/bundle/linux/appimage.rs @@ -114,22 +114,9 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { fs::copy("/usr/bin/xdg-mime", app_dir_usr_bin.join("xdg-mime"))?; } - // TODO: don't rely on env vars - let gstreamer = std::env::var("APPIMAGE_BUNDLE_GSTREAMER") - .map(|x| x == "1") - .unwrap_or(false); - - if let Ok(path) = std::env::var("TAURI_TRAY_LIBRARY_PATH") { - let path = PathBuf::from(path); - if let Some(file_name) = path.file_name() { - fs::copy(&path, app_dir_usr_lib.join(file_name))?; - } - } - - if std::env::var("APPIMAGE_BUNDLE_XDG_OPEN") - .map(|x| x == "1") - .unwrap_or(false) - { + // xdg-open is only 50kb (in a 80mb+ appimage) and quite commonly used so we just always add it + // we do however check if the user may have provided their own copy already + if !app_dir_usr_bin.join("xdg-open").exists() { fs::copy("/usr/bin/xdg-open", app_dir_usr_bin.join("xdg-open"))?; } @@ -188,6 +175,18 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { _ => "0", }; + // This should prevent linuxdeploy to be detected by appimage integration tools + let _ = Command::new("dd") + .args([ + "if=/dev/zero", + "bs=1", + "count=3", + "seek=8", + "conf=notrunc", + &format!("of={}", linuxdeploy_path.display()), + ]) + .piped(); + let mut cmd = Command::new(linuxdeploy_path); cmd.env("OUTPUT", &appimage_path); cmd.args([ @@ -199,7 +198,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { "--plugin", "gtk", ]); - if gstreamer { + if settings.appimage().bundle_media_framework { cmd.args(["--plugin", "gstreamer"]); } cmd.args(["--output", "appimage"]); diff --git a/crates/tauri-bundler/src/bundle/linux/appimage/appimage b/crates/tauri-bundler/src/bundle/linux/appimage/appimage deleted file mode 100644 index 8e447a0048b3..000000000000 --- a/crates/tauri-bundler/src/bundle/linux/appimage/appimage +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019-2024 Tauri Programme within The Commons Conservancy -# SPDX-License-Identifier: Apache-2.0 -# SPDX-License-Identifier: MIT - -set -euxo pipefail - -export ARCH={{arch}} -APPIMAGE_BUNDLE_XDG_OPEN=${APPIMAGE_BUNDLE_XDG_OPEN-0} -APPIMAGE_BUNDLE_XDG_MIME=${APPIMAGE_BUNDLE_XDG_MIME-0} -APPIMAGE_BUNDLE_GSTREAMER=${APPIMAGE_BUNDLE_GSTREAMER-0} -TAURI_TRAY_LIBRARY_PATH=${TAURI_TRAY_LIBRARY_PATH-0} - -if [ "$ARCH" == "i686" ]; then - linuxdeploy_arch="i386" -else - linuxdeploy_arch="$ARCH" -fi - -mkdir -p "{{product_name}}.AppDir" -cp -r ../appimage_deb/data/usr "{{product_name}}.AppDir" - -cd "{{product_name}}.AppDir" -mkdir -p "usr/bin" -mkdir -p "usr/lib" - -if [[ "$APPIMAGE_BUNDLE_XDG_OPEN" != "0" ]] && [[ -f "/usr/bin/xdg-open" ]]; then - echo "Copying /usr/bin/xdg-open" - cp /usr/bin/xdg-open usr/bin -fi - -if [[ "$APPIMAGE_BUNDLE_XDG_MIME" != "0" ]] && [[ -f "/usr/bin/xdg-mime" ]]; then - echo "Copying /usr/bin/xdg-mime" - cp /usr/bin/xdg-mime usr/bin -fi - -if [[ "$TAURI_TRAY_LIBRARY_PATH" != "0" ]]; then - echo "Copying appindicator library ${TAURI_TRAY_LIBRARY_PATH}" - cp ${TAURI_TRAY_LIBRARY_PATH} usr/lib - # It looks like we're practicing good hygiene by adding the ABI version. - # But for compatibility we'll symlink this file to what we did before. - # Specifically this prevents breaking libappindicator-sys v0.7.1 and v0.7.2. - if [[ "$TAURI_TRAY_LIBRARY_PATH" == *.so.1 ]]; then - readonly soname=$(basename "$TAURI_TRAY_LIBRARY_PATH") - readonly old_name=$(basename "$TAURI_TRAY_LIBRARY_PATH" .1) - echo "Adding compatibility symlink ${old_name} -> ${soname}" - ln -s ${soname} usr/lib/${old_name} - fi -fi - -# Copy WebKit files. Follow symlinks in case `/usr/lib64` is a symlink to `/usr/lib` -find -L /usr/lib* -name WebKitNetworkProcess -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true -find -L /usr/lib* -name WebKitWebProcess -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true -find -L /usr/lib* -name libwebkit2gtkinjectedbundle.so -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true - -( cd "{{tauri_tools_path}}" && ( wget -q -4 -N https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH} || wget -q -4 -N https://github.com/AppImage/AppImageKit/releases/download/12/AppRun-${ARCH} ) ) -chmod +x "{{tauri_tools_path}}/AppRun-${ARCH}" - -# We need AppRun to be installed as {{product_name}}.AppDir/AppRun. -# Otherwise the linuxdeploy scripts will default to symlinking our main bin instead and will crash on trying to launch. -cp "{{tauri_tools_path}}/AppRun-${ARCH}" AppRun - -cp "{{icon_path}}" .DirIcon -ln -sf "{{icon_path}}" "{{product_name}}.png" - -ln -sf "usr/share/applications/{{product_name}}.desktop" "{{product_name}}.desktop" - -cd .. - -if [[ "$APPIMAGE_BUNDLE_GSTREAMER" != "0" ]]; then - gst_plugin="--plugin gstreamer" - wget -q -4 -N "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gstreamer/master/linuxdeploy-plugin-gstreamer.sh" - chmod +x linuxdeploy-plugin-gstreamer.sh -else - gst_plugin="" -fi - -( cd "{{tauri_tools_path}}" && wget -q -4 -N https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh ) -( cd "{{tauri_tools_path}}" && wget -q -4 -N https://github.com/tauri-apps/binary-releases/releases/download/linuxdeploy/linuxdeploy-${linuxdeploy_arch}.AppImage ) - -chmod +x "{{tauri_tools_path}}/linuxdeploy-plugin-gtk.sh" -chmod +x "{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage" - -dd if=/dev/zero bs=1 count=3 seek=8 conv=notrunc of="{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage" - -OUTPUT="{{appimage_filename}}" "{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage" --appimage-extract-and-run --appdir "{{product_name}}.AppDir" --plugin gtk ${gst_plugin} --output appimage diff --git a/crates/tauri-bundler/src/bundle/settings.rs b/crates/tauri-bundler/src/bundle/settings.rs index 7ee51102d790..082cd05660c5 100644 --- a/crates/tauri-bundler/src/bundle/settings.rs +++ b/crates/tauri-bundler/src/bundle/settings.rs @@ -220,6 +220,8 @@ pub struct DebianSettings { pub struct AppImageSettings { /// The files to include in the Appimage Binary. pub files: HashMap, + /// Whether to include gstreamer plugins for audio/media support. + pub bundle_media_framework: bool, } /// The RPM bundle settings. diff --git a/crates/tauri-cli/src/bundle.rs b/crates/tauri-cli/src/bundle.rs index 5473c4b4690c..20118b224049 100644 --- a/crates/tauri-cli/src/bundle.rs +++ b/crates/tauri-cli/src/bundle.rs @@ -181,24 +181,6 @@ pub fn bundle( _ => log::Level::Trace, }); - // set env vars used by the bundler - #[cfg(target_os = "linux")] - { - if config.bundle.linux.appimage.bundle_media_framework { - std::env::set_var("APPIMAGE_BUNDLE_GSTREAMER", "1"); - } - - if let Some(open) = config.plugins.0.get("shell").and_then(|v| v.get("open")) { - if open.as_bool().is_some_and(|x| x) || open.is_string() { - std::env::set_var("APPIMAGE_BUNDLE_XDG_OPEN", "1"); - } - } - - if settings.deep_link_protocols().is_some() { - std::env::set_var("APPIMAGE_BUNDLE_XDG_MIME", "1"); - } - } - let bundles = tauri_bundler::bundle_project(&settings) .map_err(|e| match e { tauri_bundler::Error::BundlerError(e) => e, diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index 8a407f8eebe7..32f3d5214d6a 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -1234,6 +1234,9 @@ fn tauri_config_to_bundle_settings( #[allow(unused_mut)] let mut depends_rpm = config.linux.rpm.depends.unwrap_or_default(); + #[allow(unused_mut)] + let mut appimage_files = config.linux.appimage.files; + // set env vars used by the bundler and inject dependencies #[cfg(target_os = "linux")] { @@ -1276,7 +1279,12 @@ fn tauri_config_to_bundle_settings( } } - std::env::set_var("TAURI_TRAY_LIBRARY_PATH", path); + // conditionally setting it in case the user provided its own version for some reason + let path = PathBuf::from(path); + if !appimage_files.contains_key(&path) { + // manually construct target path, just in case the source path is something unexpected + appimage_files.insert(Path::new("/usr/lib").join(path.file_name().unwrap()), path); + } } depends_deb.push("libwebkit2gtk-4.1-0".to_string()); @@ -1368,7 +1376,8 @@ fn tauri_config_to_bundle_settings( post_remove_script: config.linux.deb.post_remove_script, }, appimage: AppImageSettings { - files: config.linux.appimage.files, + files: appimage_files, + bundle_media_framework: config.linux.appimage.bundle_media_framework, }, rpm: RpmSettings { depends: if depends_rpm.is_empty() {