Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Zenity backend optional #160

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ documentation = "https://docs.rs/rfd"
default = ["gtk3"]
file-handle-inner = []
gtk3 = ["gtk-sys", "glib-sys", "gobject-sys"]
xdg-portal = ["ashpd", "urlencoding", "pollster", "async-io", "futures-util"]
xdg-portal = ["ashpd", "urlencoding", "pollster"]
# Enables message dialogs on Linux when gtk3 is disabled and the end
# user has zenity installed
zenity = ["async-io", "futures-util"]
common-controls-v6 = ["windows-sys/Win32_UI_Controls"]

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/backend/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "zenity")]
mod child_stdout;
#[cfg(feature = "zenity")]
pub(crate) mod zenity;
9 changes: 8 additions & 1 deletion src/backend/xdg_desktop_portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use std::path::PathBuf;

use crate::backend::DialogFutureType;
use crate::file_dialog::Filter;
#[cfg(feature = "zenity")]
use crate::message_dialog::MessageDialog;
use crate::{FileDialog, FileHandle, MessageButtons, MessageDialogResult};
use crate::{FileDialog, FileHandle};
#[cfg(feature = "zenity")]
use crate::{MessageButtons, MessageDialogResult};

use ashpd::desktop::file_chooser::{FileFilter, OpenFileRequest, SaveFileRequest};
// TODO: convert raw_window_handle::RawWindowHandle to ashpd::WindowIdentifier
Expand Down Expand Up @@ -192,14 +195,18 @@ impl AsyncFileSaveDialogImpl for FileDialog {
}
}

#[cfg(feature = "zenity")]
use crate::backend::MessageDialogImpl;
#[cfg(feature = "zenity")]
impl MessageDialogImpl for MessageDialog {
fn show(self) -> MessageDialogResult {
block_on(self.show_async())
}
}

#[cfg(feature = "zenity")]
use crate::backend::AsyncMessageDialogImpl;
#[cfg(feature = "zenity")]
impl AsyncMessageDialogImpl for MessageDialog {
fn show_async(self) -> DialogFutureType<MessageDialogResult> {
Box::pin(async move {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
//! they can all be installed simultaneously).
//!
//! The XDG Desktop Portal has no API for message dialogs, so the [MessageDialog] and
//! [AsyncMessageDialog] structs will not build with this backend.
//! [AsyncMessageDialog] structs will not build with this backend unless the `zenity` feature is
//! enabled. However, `zenity`-based dialogs will silently fail if the end user does not have the
//! `zenity` binary in `$PATH`.
//!
//! # macOS non-windowed applications, async, and threading
//!
Expand Down
9 changes: 7 additions & 2 deletions src/message_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#[cfg(any(not(target_os = "linux"), feature = "zenity"))]
use crate::backend::AsyncMessageDialogImpl;
#[cfg(any(not(target_os = "linux"), feature = "zenity"))]
use crate::backend::MessageDialogImpl;
use std::fmt::{Display, Formatter};

#[cfg(any(not(target_os = "linux"), feature = "zenity"))]
use std::future::Future;

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};

/// Synchronous Message Dialog. Supported platforms:
/// * Windows
/// * macOS
/// * Linux (GTK only)
/// * Linux (GTK or Zenity only)
/// * WASM
#[derive(Default, Debug, Clone)]
pub struct MessageDialog {
Expand Down Expand Up @@ -71,6 +74,7 @@ impl MessageDialog {
}

/// Shows a message dialog and returns the button that was pressed.
#[cfg(any(not(target_os = "linux"), any(feature = "zenity", feature = "gtk3")))]
pub fn show(self) -> MessageDialogResult {
MessageDialogImpl::show(self)
}
Expand All @@ -79,7 +83,7 @@ impl MessageDialog {
/// Asynchronous Message Dialog. Supported platforms:
/// * Windows
/// * macOS
/// * Linux (GTK only)
/// * Linux (GTK or Zenity only)
/// * WASM
#[derive(Default, Debug, Clone)]
pub struct AsyncMessageDialog(MessageDialog);
Expand Down Expand Up @@ -131,6 +135,7 @@ impl AsyncMessageDialog {
}

/// Shows a message dialog and returns the button that was pressed.
#[cfg(any(not(target_os = "linux"), any(feature = "zenity", feature = "gtk3")))]
pub fn show(self) -> impl Future<Output = MessageDialogResult> {
AsyncMessageDialogImpl::show_async(self.0)
}
Expand Down
Loading