From c23fa03f07d5c1c220bcf0bca482364513e3f754 Mon Sep 17 00:00:00 2001 From: Blaine <44733840+Lepidopteran@users.noreply.github.com> Date: Mon, 17 Nov 2025 08:56:02 -0500 Subject: [PATCH] feat(dialog): add `xdg-portal` as an optional feature for `rfd` (#3098) --- ...dg-portal-as-an-optional-feature-for-rfd.md | 6 ++++++ .github/workflows/lint-rust.yml | 1 + .github/workflows/test-rust.yml | 4 ++-- plugins/dialog/Cargo.toml | 7 ++++++- plugins/dialog/README.md | 18 ++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .changes/add-xdg-portal-as-an-optional-feature-for-rfd.md diff --git a/.changes/add-xdg-portal-as-an-optional-feature-for-rfd.md b/.changes/add-xdg-portal-as-an-optional-feature-for-rfd.md new file mode 100644 index 00000000..3b8c5acd --- /dev/null +++ b/.changes/add-xdg-portal-as-an-optional-feature-for-rfd.md @@ -0,0 +1,6 @@ +--- +"dialog-js": minor:feat +"dialog": minor:feat +--- + +Add `xdg-portal` as an optional feature for `rfd` diff --git a/.github/workflows/lint-rust.yml b/.github/workflows/lint-rust.yml index db922ef1..7b4ad191 100644 --- a/.github/workflows/lint-rust.yml +++ b/.github/workflows/lint-rust.yml @@ -154,4 +154,5 @@ jobs: run: cargo clippy --package ${{ matrix.package }} --all-targets -- -D warnings - name: clippy ${{ matrix.package }} --all-features + if: matrix.package != 'tauri-plugin-dialog' run: cargo clippy --package ${{ matrix.package }} --all-targets --all-features -- -D warnings diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 496efe6e..76f2e0ec 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -246,9 +246,9 @@ jobs: run: cargo +stable install cross --git https://github.com/cross-rs/cross - name: test ${{ matrix.package }} - if: matrix.package != 'tauri-plugin-http' + if: ${{ matrix.package != 'tauri-plugin-http' && matrix.package != 'tauri-plugin-dialog' }} run: ${{ matrix.platform.runner }} ${{ matrix.platform.command }} --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets --all-features - name: test ${{ matrix.package }} - if: matrix.package == 'tauri-plugin-http' + if: ${{ matrix.package == 'tauri-plugin-http' || matrix.package == 'tauri-plugin-dialog' }} run: ${{ matrix.platform.runner }} ${{ matrix.platform.command }} --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets diff --git a/plugins/dialog/Cargo.toml b/plugins/dialog/Cargo.toml index 1b5a1a41..0deb48cc 100644 --- a/plugins/dialog/Cargo.toml +++ b/plugins/dialog/Cargo.toml @@ -9,6 +9,11 @@ rust-version = { workspace = true } repository = { workspace = true } links = "tauri-plugin-dialog" +[features] +default = ["gtk3"] +xdg-portal = ["rfd/xdg-portal"] +gtk3 = ["rfd/gtk3"] + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu", "x86_64-linux-android"] @@ -40,7 +45,7 @@ tauri = { workspace = true, features = ["wry"] } [target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] rfd = { version = "0.15", default-features = false, features = [ "tokio", - "gtk3", "common-controls-v6", ] } + raw-window-handle = "0.6" diff --git a/plugins/dialog/README.md b/plugins/dialog/README.md index 8c4f0c22..e062c803 100644 --- a/plugins/dialog/README.md +++ b/plugins/dialog/README.md @@ -31,6 +31,24 @@ tauri-plugin-dialog = "2.0.0" tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } ``` +### Linux XDG Desktop Portal Support + +By default, this plugin uses gtk to show dialogs, however since `v2.5.0` you can switch to using [XDG Desktop Portal](https://flatpak.github.io/xdg-desktop-portal/) by adding the following to your `Cargo.toml` file: + +```toml +[dependencies] +tauri-plugin-dialog = { version = "2.5.0", default-features = false, features = ["xdg-portal"] } +# alternatively with Git: +tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2", default-features = false, features = ["xdg-portal"] } + +``` + +Do note if you use the `xdg-portal` feature, you need to ensure that [`zenity`](https://gitlab.gnome.org/GNOME/zenity) and an [XDG Desktop Portal backend](https://flatpak.github.io/xdg-desktop-portal#using-portals) is installed with your program. + +For more information, see [XDG Desktop Portal documentation](https://flatpak.github.io/xdg-desktop-portal/) and [`rfd` documentation](https://docs.rs/rfd/latest/rfd#xdg-desktop-portal-backend). + +### JavaScript + You can install the JavaScript Guest bindings using your preferred JavaScript package manager: ```sh