improv: feature gate for xdg_portal

This commit is contained in:
Ashley Wulber 2026-07-15 15:24:46 -04:00 • committed by Ashley Wulber
parent 8e6aea650a
commit 63568a8d9c
12 changed files with 53 additions and 53 deletions

View file

@ -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" }

2
iced

@ -1 +1 @@
Subproject commit 7177c92bb0b10382acafdec1af7441312138c69e
Subproject commit 7b5d58ecbde79b105baf938e8065ab4ba4e5a35d

View file

@ -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),
}

View file

@ -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<T: Application> Cosmic<T> {
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<T: Application> Cosmic<T> {
}
}
}
#[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<T: Application> Cosmic<T> {
}
}
}
#[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
}

View file

@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// 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<M>(id: window::Id) -> iced::Task<crate::Action<M>> {
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<ashpd::Result<Vec<String>>> {
iced::Task::future(async move {
let file_transfer = ashpd::documents::FileTransfer::new().await?;

View file

@ -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")]

View file

@ -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<String>,
@ -39,17 +39,17 @@ pub struct Dialog {
file_name: Option<String>,
/// 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<super::Choice>,
/// Specifies the default file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_filter: Option<super::FileFilter>,
@ -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<String>) -> 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<super::Choice>) -> 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<super::FileFilter>) -> 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,

View file

@ -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<String>,
/// 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<PathBuf>,
/// Sets the absolute path of the file
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_file: Option<PathBuf>,
/// Adds a list of choices.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
choices: Vec<super::Choice>,
/// Specifies the default file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_filter: Option<super::FileFilter>,
@ -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<String>) -> 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<super::Choice>) -> 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<super::FileFilter>) -> 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;

View file

@ -3,7 +3,7 @@
//! Create dialogs for retrieving user input.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub use ashpd;
pub mod file_chooser;

View file

@ -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;

View file

@ -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;

View file

@ -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<Box<dyn Fn(DndAction) -> Message>>,
on_data_received: Option<Box<dyn Fn(String, Vec<u8>) -> Message>>,
on_finish: Option<Box<dyn Fn(String, Vec<u8>, DndAction, f64, f64) -> Message>>,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
on_file_transfer: Option<Box<dyn Fn(String) -> 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<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
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())