From 63568a8d9c5885ca08eff54bd6d3e810a6d6c030 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 15 Jul 2026 15:24:46 -0400 Subject: [PATCH] improv: feature gate for xdg_portal --- Cargo.toml | 2 +- iced | 2 +- src/app/action.rs | 2 +- src/app/cosmic.rs | 8 ++++---- src/command.rs | 6 +++--- src/dialog/file_chooser/mod.rs | 4 ++-- src/dialog/file_chooser/open.rs | 30 +++++++++++++++--------------- src/dialog/file_chooser/save.rs | 32 ++++++++++++++++---------------- src/dialog/mod.rs | 2 +- src/lib.rs | 2 +- src/theme/mod.rs | 2 +- src/widget/dnd_destination.rs | 14 +++++++------- 12 files changed, 53 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b3871c7..5268098d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,7 +120,6 @@ x11 = ["iced/x11", "iced_winit/x11"] [dependencies] apply = "0.3.0" -ashpd = { version = "0.12.3", default-features = false, optional = true } async-fs = { version = "2.2", optional = true } async-std = { workspace = true, optional = true } auto_enums = "0.8.8" @@ -174,6 +173,7 @@ cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-c cosmic-config = { path = "cosmic-config", features = ["dbus"] } cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings" } zbus.workspace = true +ashpd = { version = "0.12.3", default-features = false, optional = true } [target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" } diff --git a/iced b/iced index 7177c92b..7b5d58ec 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 7177c92bb0b10382acafdec1af7441312138c69e +Subproject commit 7b5d58ecbde79b105baf938e8065ab4ba4e5a35d diff --git a/src/app/action.rs b/src/app/action.rs index 1308335e..873622da 100644 --- a/src/app/action.rs +++ b/src/app/action.rs @@ -76,6 +76,6 @@ pub enum Action { /// Capabilities the window manager supports #[cfg(wayland_platform)] WmCapabilities(iced::window::Id, WindowManagerCapabilities), - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] DesktopSettings(crate::theme::portal::Desktop), } diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index f3f51e05..13e3ee83 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -678,7 +678,7 @@ where }) .map(crate::Action::Cosmic), window_events.map(crate::Action::Cosmic), - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] crate::theme::portal::desktop_settings() .map(Action::DesktopSettings) .map(crate::Action::Cosmic), @@ -1250,7 +1250,7 @@ impl Cosmic { return self.app.dbus_connection(conn); } - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] Action::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => { use ashpd::desktop::settings::ColorScheme; if match THEME.lock().unwrap().theme_type { @@ -1332,7 +1332,7 @@ impl Cosmic { } } } - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] Action::DesktopSettings(crate::theme::portal::Desktop::Accent(c)) => { use palette::Srgba; let c = Srgba::new(c.red() as f32, c.green() as f32, c.blue() as f32, 1.0); @@ -1361,7 +1361,7 @@ impl Cosmic { } } } - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] Action::DesktopSettings(crate::theme::portal::Desktop::Contrast(_)) => { // TODO when high contrast is integrated in settings and all custom themes } diff --git a/src/command.rs b/src/command.rs index 6bb16e8d..64184f46 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,7 +1,7 @@ // Copyright 2023 System76 // SPDX-License-Identifier: MPL-2.0 -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] use std::os::fd::AsFd; use iced::window; @@ -47,7 +47,7 @@ pub fn toggle_maximize(id: window::Id) -> iced::Task> { iced_runtime::window::toggle_maximize(id) } -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub fn file_transfer_send( writeable: bool, auto_stop: bool, @@ -63,7 +63,7 @@ pub fn file_transfer_send( /// Receive the files offered over the xdg share portal using the `key`. /// Returns a list of file paths. -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub fn file_transfer_receive(key: String) -> iced::Task>> { iced::Task::future(async move { let file_transfer = ashpd::documents::FileTransfer::new().await?; diff --git a/src/dialog/file_chooser/mod.rs b/src/dialog/file_chooser/mod.rs index 186f7625..d1b385a0 100644 --- a/src/dialog/file_chooser/mod.rs +++ b/src/dialog/file_chooser/mod.rs @@ -90,7 +90,7 @@ pub mod open; /// Save file dialog. pub mod save; -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub use ashpd::desktop::file_chooser::{Choice, FileFilter}; use thiserror::Error; @@ -139,7 +139,7 @@ pub enum Error { UrlAbsolute, } -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub type DialogError = ashpd::Error; #[cfg(feature = "rfd")] diff --git a/src/dialog/file_chooser/open.rs b/src/dialog/file_chooser/open.rs index f24afda9..c15a5b91 100644 --- a/src/dialog/file_chooser/open.rs +++ b/src/dialog/file_chooser/open.rs @@ -6,7 +6,7 @@ //! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog) //! example in our repository. -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub use portal::{FileResponse, MultiFileResponse, file, files, folder, folders}; #[cfg(feature = "rfd")] @@ -24,7 +24,7 @@ pub struct Dialog { title: String, /// The label for the accept button. Mnemonic underlines are allowed. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] accept_label: Option, @@ -39,17 +39,17 @@ pub struct Dialog { file_name: Option, /// Modal dialogs require user input before continuing the program. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] modal: bool, /// Adds a list of choices. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] choices: Vec, /// Specifies the default file filter. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] current_filter: Option, @@ -62,36 +62,36 @@ impl Dialog { pub const fn new() -> Self { Self { title: String::new(), - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] accept_label: None, directory: None, file_name: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] modal: true, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] current_filter: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] choices: Vec::new(), filters: Vec::new(), } } /// The label for the accept button. Mnemonic underlines are allowed. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn accept_label(mut self, label: impl Into) -> Self { self.accept_label = Some(label.into()); self } /// Adds a choice. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn choice(mut self, choice: impl Into) -> Self { self.choices.push(choice.into()); self } /// Specifies the default file filter. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn current_filter(mut self, filter: impl Into) -> Self { self.current_filter = Some(filter.into()); self @@ -104,7 +104,7 @@ impl Dialog { } /// Modal dialogs require user input before continuing the program. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn modal(mut self, modal: bool) -> Self { self.modal = modal; self @@ -131,7 +131,7 @@ impl Dialog { } } -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] mod portal { use super::Dialog; use crate::dialog::file_chooser::Error; @@ -147,7 +147,7 @@ mod portal { } /// Creates a new file dialog, and begins to await its responses. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub async fn create( dialog: super::Dialog, folders: bool, diff --git a/src/dialog/file_chooser/save.rs b/src/dialog/file_chooser/save.rs index d7a2a34e..aa8c1398 100644 --- a/src/dialog/file_chooser/save.rs +++ b/src/dialog/file_chooser/save.rs @@ -6,7 +6,7 @@ //! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog) //! example in our repository. -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub use portal::{Response, file}; #[cfg(feature = "rfd")] @@ -23,12 +23,12 @@ pub struct Dialog { title: String, /// The label for the accept button. Mnemonic underlines are allowed. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] accept_label: Option, /// Modal dialogs require user input before continuing the program. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] modal: bool, @@ -41,17 +41,17 @@ pub struct Dialog { directory: Option, /// Sets the absolute path of the file - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] current_file: Option, /// Adds a list of choices. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] choices: Vec, /// Specifies the default file filter. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[setters(skip)] current_filter: Option, @@ -64,38 +64,38 @@ impl Dialog { pub const fn new() -> Self { Self { title: String::new(), - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] accept_label: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] modal: true, file_name: None, directory: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] current_file: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] current_filter: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] choices: Vec::new(), filters: Vec::new(), } } /// The label for the accept button. Mnemonic underlines are allowed. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn accept_label(mut self, label: impl Into) -> Self { self.accept_label = Some(label.into()); self } /// Adds a choice. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn choice(mut self, choice: impl Into) -> Self { self.choices.push(choice.into()); self } /// Set the current file filter. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn current_filter(mut self, filter: impl Into) -> Self { self.current_filter = Some(filter.into()); self @@ -108,7 +108,7 @@ impl Dialog { } /// Modal dialogs require user input before continuing the program. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] pub fn modal(mut self, modal: bool) -> Self { self.modal = modal; self @@ -126,7 +126,7 @@ impl Default for Dialog { } } -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] mod portal { use super::Dialog; use crate::dialog::file_chooser::Error; diff --git a/src/dialog/mod.rs b/src/dialog/mod.rs index 66b3cec7..d67b7f3b 100644 --- a/src/dialog/mod.rs +++ b/src/dialog/mod.rs @@ -3,7 +3,7 @@ //! Create dialogs for retrieving user input. -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub use ashpd; pub mod file_chooser; diff --git a/src/lib.rs b/src/lib.rs index 38230db5..c44700e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,7 +136,7 @@ pub use dbus_activation::DbusActivation; #[cfg(feature = "desktop")] pub mod desktop; -#[cfg(any(feature = "xdg-portal", feature = "rfd"))] +#[cfg(any(xdg_portal, feature = "rfd"))] pub mod dialog; pub mod executor; diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 830746a1..65ea9314 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -3,7 +3,7 @@ //! Contains the [`Theme`] type and its widget stylesheet implementations. -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub mod portal; pub mod style; diff --git a/src/widget/dnd_destination.rs b/src/widget/dnd_destination.rs index 0ebff3dc..54d77808 100644 --- a/src/widget/dnd_destination.rs +++ b/src/widget/dnd_destination.rs @@ -29,7 +29,7 @@ pub fn dnd_destination_for_data<'a, T: AllowedMimeTypes, Message: 'static>( static DRAG_ID_COUNTER: AtomicU64 = AtomicU64::new(0); const DND_DEST_LOG_TARGET: &str = "libcosmic::widget::dnd_destination"; -#[cfg(feature = "xdg-portal")] +#[cfg(xdg_portal)] pub const FILE_TRANSFER_MIME: &str = "application/vnd.portal.filetransfer"; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -64,7 +64,7 @@ pub struct DndDestination<'a, Message> { on_action_selected: Option Message>>, on_data_received: Option) -> Message>>, on_finish: Option, DndAction, f64, f64) -> Message>>, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] on_file_transfer: Option Message>>, } @@ -92,7 +92,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> { on_action_selected: None, on_data_received: None, on_finish: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] on_file_transfer: None, } } @@ -119,7 +119,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> { on_finish: Some(Box::new(move |mime, data, action, _, _| { on_finish(T::try_from((data, mime)).ok(), action) })), - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] on_file_transfer: None, } } @@ -156,7 +156,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> { on_action_selected: None, on_data_received: None, on_finish: None, - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] on_file_transfer: None, } } @@ -239,7 +239,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> { /// Add a message that will be emitted instead of [`on_data_received`](Self::on_data_received) if the dropped files /// are offered through the xdg share portal. You can then use [`crate::command::file_transfer_receive`] /// with the key to receive the files. - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] #[must_use] pub fn on_file_transfer(mut self, f: impl Fn(String) -> Message + 'static) -> Self { match self.mime_types.iter().position(|v| v == "text/uri-list") { @@ -514,7 +514,7 @@ impl Widget data.len() ); - #[cfg(feature = "xdg-portal")] + #[cfg(xdg_portal)] if mime_type == FILE_TRANSFER_MIME && let Some(f) = self.on_file_transfer.as_ref() && let Ok(s) = String::from_utf8(data[..data.len() - 1].to_vec())