Skip to content

Port to rust 2024 edition #268

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
authors = ["Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>"]
categories = ["gui", "os::linux-apis", "api-bindings"]
description = "XDG portals wrapper in Rust using zbus"
edition = "2021"
edition = "2024"
exclude = ["interfaces/*.xml", "ashpd-demo/"]
keywords = ["portal", "flatpak", "xdg", "desktop", "dbus"]
license = "MIT"
name = "ashpd"
repository = "https://github.com/bilelmoussaoui/ashpd"
version = "0.11.0"
rust-version = "1.75"
rust-version = "1.85"

[features]
async-std = ["zbus/async-io", "dep:async-fs", "dep:async-net", "futures-util/io"]
Expand Down
2 changes: 1 addition & 1 deletion examples/screen_cast_pw.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::os::fd::{IntoRawFd, OwnedFd};

use ashpd::desktop::{
screencast::{CursorMode, Screencast, SourceType, Stream as ScreencastStream},
PersistMode,
screencast::{CursorMode, Screencast, SourceType, Stream as ScreencastStream},
};
use pipewire as pw;
use pw::{properties::properties, spa};
Expand Down
16 changes: 9 additions & 7 deletions src/activation_token/wayland.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use wayland_backend::sys::client::Backend;
use wayland_client::{
protocol::{wl_registry, wl_surface::WlSurface},
Proxy, QueueHandle,
protocol::{wl_registry, wl_surface::WlSurface},
};
use wayland_protocols::xdg::activation::v1::client::{
xdg_activation_token_v1::{Event, XdgActivationTokenV1},
Expand Down Expand Up @@ -54,13 +54,15 @@ impl ActivationToken {
return None;
}

let backend = Backend::from_foreign_display(display_ptr as *mut _);
let backend = unsafe { Backend::from_foreign_display(display_ptr as *mut _) };
let conn = wayland_client::Connection::from_backend(backend);
let obj_id = wayland_backend::sys::client::ObjectId::from_ptr(
WlSurface::interface(),
surface_ptr as *mut _,
)
.ok()?;
let obj_id = unsafe {
wayland_backend::sys::client::ObjectId::from_ptr(
WlSurface::interface(),
surface_ptr.cast(),
)
.ok()?
};

let surface = WlSurface::from_id(&conn, obj_id).ok()?;

Expand Down
8 changes: 6 additions & 2 deletions src/app_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ mod tests {
assert!(is_valid_app_id("com.org_._SomeApp"));
assert!(is_valid_app_id("com.org._1SomeApp"));
assert!(is_valid_app_id("com.org._1_SomeApp"));
assert!(is_valid_app_id("VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.a111111111111"));
assert!(is_valid_app_id(
"VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.a111111111111"
));

assert!(!is_valid_app_id("com.org-._SomeApp"));
assert!(!is_valid_app_id("package"));
Expand All @@ -225,7 +227,9 @@ mod tests {
assert!(!is_valid_app_id("0P.Starts.With.A.Digit"));
assert!(!is_valid_app_id("com.org.1SomeApp"));
assert!(!is_valid_app_id("Element.Starts.With.A.1Digit"));
assert!(!is_valid_app_id("VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.a1111111111112"));
assert!(!is_valid_app_id(
"VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.VeryLongApplicationId.a1111111111112"
));
assert!(!is_valid_app_id(""));
assert!(!is_valid_app_id("contains.;nvalid.characters"));
assert!(!is_valid_app_id("con\nins.invalid.characters"));
Expand Down
6 changes: 3 additions & 3 deletions src/backend/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{file_chooser::Choice, request::Response, HandleToken, Icon},
desktop::{HandleToken, Icon, file_chooser::Choice, request::Response},
zvariant::{self, DeserializeDict, OwnedObjectPath, SerializeDict},
AppID, WindowIdentifierType,
};

#[derive(DeserializeDict, zvariant::Type)]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{account::UserInformation, request::Response, HandleToken},
desktop::{HandleToken, account::UserInformation, request::Response},
zvariant::{DeserializeDict, OwnedObjectPath, Type},
AppID, WindowIdentifierType,
};

#[derive(Debug, DeserializeDict, Type)]
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
ActivationToken, AppID, PortalError, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier,
request::{Request, RequestImpl},
},
desktop::{HandleToken, Response},
zbus::object_server::{InterfaceRef, ObjectServer},
zvariant::{DeserializeDict, OwnedObjectPath, SerializeDict, Type},
ActivationToken, AppID, PortalError, WindowIdentifierType,
};

#[derive(Debug, DeserializeDict, Type)]
Expand Down
4 changes: 2 additions & 2 deletions src/backend/background.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{collections::HashMap, sync::Arc};

use async_trait::async_trait;
use enumflags2::{bitflags, BitFlags};
use enumflags2::{BitFlags, bitflags};
use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::{
AppID, PortalError,
backend::request::{Request, RequestImpl},
desktop::{HandleToken, Response},
zbus::object_server::SignalEmitter,
zvariant::{OwnedObjectPath, SerializeDict, Type},
AppID, PortalError,
};

#[derive(Serialize_repr, Deserialize_repr, Copy, Clone, PartialEq, Eq, Debug, Type)]
Expand Down
2 changes: 1 addition & 1 deletion src/backend/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use enumflags2::BitFlags;
use zbus::names::{OwnedWellKnownName, WellKnownName};

use crate::backend::{
Result,
access::{AccessImpl, AccessInterface},
account::{AccountImpl, AccountInterface},
app_chooser::{AppChooserImpl, AppChooserInterface},
Expand All @@ -17,7 +18,6 @@ use crate::backend::{
secret::{SecretImpl, SecretInterface},
settings::{SettingsImpl, SettingsInterface},
wallpaper::{WallpaperImpl, WallpaperInterface},
Result,
};

pub struct Builder {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
ActivationToken, AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{request::Response, HandleToken},
desktop::{HandleToken, request::Response},
zvariant::{self, DeserializeDict, OwnedObjectPath},
ActivationToken, AppID, WindowIdentifierType,
};

#[derive(DeserializeDict, zvariant::Type)]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/file_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, FilePath, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{
HandleToken,
file_chooser::{Choice, FileFilter},
request::Response,
HandleToken,
},
zvariant::{DeserializeDict, OwnedObjectPath, SerializeDict, Type},
AppID, FilePath, WindowIdentifierType,
};

#[derive(Debug, Type, SerializeDict, Default)]
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{de::Deserializer, Deserialize};
use serde::{Deserialize, de::Deserializer};
use zbus::zvariant::Type;

use crate::{AppID, WindowIdentifierType};
Expand Down
2 changes: 1 addition & 1 deletion src/backend/permission_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::{collections::HashMap, sync::Arc};
use async_trait::async_trait;

use crate::{
AppID, PortalError,
documents::{DocumentID, Permission},
zbus::object_server::SignalEmitter,
zvariant::{OwnedValue, Value},
AppID, PortalError,
};

#[async_trait]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{
HandleToken,
print::{PageSetup, PreparePrint, Settings},
request::Response,
HandleToken,
},
zvariant::{self, DeserializeDict, OwnedObjectPath},
AppID, WindowIdentifierType,
};

#[derive(DeserializeDict, zvariant::Type)]
Expand Down
2 changes: 1 addition & 1 deletion src/backend/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{boxed::Box, future::Future, sync::Arc};

use async_trait::async_trait;
use futures_util::future::{abortable, AbortHandle};
use futures_util::future::{AbortHandle, abortable};
use tokio::sync::Mutex;
use zbus::zvariant::{ObjectPath, OwnedObjectPath};

Expand Down
6 changes: 3 additions & 3 deletions src/backend/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{
request::Response, screenshot::Screenshot as ScreenshotResponse, Color, HandleToken,
Color, HandleToken, request::Response, screenshot::Screenshot as ScreenshotResponse,
},
zvariant::{DeserializeDict, OwnedObjectPath, Type},
AppID, WindowIdentifierType,
};

#[derive(DeserializeDict, Type, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/backend/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use async_trait::async_trait;
use zbus::zvariant::{self, OwnedValue};

use crate::{
AppID,
backend::{
request::{Request, RequestImpl},
Result,
request::{Request, RequestImpl},
},
desktop::{HandleToken, Response},
AppID,
};

#[async_trait]
Expand Down
8 changes: 4 additions & 4 deletions src/backend/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::{collections::HashMap, sync::Arc};
use async_trait::async_trait;

use crate::{
PortalError,
desktop::{
Color,
settings::{
ColorScheme, Contrast, Namespace, ACCENT_COLOR_SCHEME_KEY, APPEARANCE_NAMESPACE,
COLOR_SCHEME_KEY, CONTRAST_KEY,
ACCENT_COLOR_SCHEME_KEY, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY,
ColorScheme, Contrast, Namespace,
},
Color,
},
zbus::object_server::SignalEmitter,
zvariant::{OwnedValue, Value},
PortalError,
};

#[async_trait]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::sync::Arc;
use async_trait::async_trait;

use crate::{
AppID, WindowIdentifierType,
backend::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
request::{Request, RequestImpl},
},
desktop::{request::ResponseType, wallpaper::SetOn, HandleToken},
desktop::{HandleToken, request::ResponseType, wallpaper::SetOn},
zvariant::{DeserializeDict, OwnedObjectPath, Type},
AppID, WindowIdentifierType,
};

#[derive(DeserializeDict, Type, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use zbus::zvariant::{DeserializeDict, SerializeDict, Type};

use super::HandleToken;
use crate::{desktop::request::Request, proxy::Proxy, Error, WindowIdentifier};
use crate::{Error, WindowIdentifier, desktop::request::Request, proxy::Proxy};

#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use serde::Serialize;
use zbus::zvariant::{DeserializeDict, SerializeDict, Type};

use super::{HandleToken, Request};
use crate::{proxy::Proxy, Error, WindowIdentifier};
use crate::{Error, WindowIdentifier, proxy::Proxy};

#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use pipewire::{context::Context, main_loop::MainLoop};
use zbus::zvariant::{self, SerializeDict, Type, Value};

use super::{HandleToken, Request};
use crate::{proxy::Proxy, Error};
use crate::{Error, proxy::Proxy};

#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
Expand Down
4 changes: 2 additions & 2 deletions src/desktop/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::collections::HashMap;
use futures_util::{Stream, StreamExt};
use zbus::zvariant::{DeserializeDict, OwnedFd, OwnedObjectPath, SerializeDict, Type, Value};

use super::{remote_desktop::RemoteDesktop, Session};
use crate::{proxy::Proxy, Result};
use super::{Session, remote_desktop::RemoteDesktop};
use crate::{Result, proxy::Proxy};

#[derive(Debug, Type, SerializeDict)]
#[zvariant(signature = "dict")]
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use serde::{Deserialize, Serialize};
use zbus::zvariant::{SerializeDict, Type};

use super::{HandleToken, Request};
use crate::{proxy::Proxy, Error, Pid};
use crate::{Error, Pid, proxy::Proxy};

#[derive(SerializeDict, Type, Debug, Default)]
/// Specified options for a [`DeviceProxy::access_device`] request.
Expand Down
4 changes: 2 additions & 2 deletions src/desktop/dynamic_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

use std::collections::HashMap;

use enumflags2::{bitflags, BitFlags};
use enumflags2::{BitFlags, bitflags};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use zbus::zvariant::{self, DeserializeDict, OwnedValue, SerializeDict, Type, Value};

use super::{HandleToken, Icon, Request};
use crate::{proxy::Proxy, ActivationToken, Error, WindowIdentifier};
use crate::{ActivationToken, Error, WindowIdentifier, proxy::Proxy};

#[bitflags]
#[derive(Default, Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Copy, Clone, Type)]
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use serde::Serialize;
use zbus::zvariant::{self, SerializeDict, Type};

use super::{HandleToken, Request};
use crate::{proxy::Proxy, ActivationToken, Error, WindowIdentifier};
use crate::{ActivationToken, Error, WindowIdentifier, proxy::Proxy};

#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
Expand Down
Loading
Loading