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

backend: Pass handle token to method calls for easier identification and association with their backend logic #252

Merged
merged 4 commits into from
Dec 24, 2024
Merged
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
7 changes: 4 additions & 3 deletions backend-demo/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ashpd::{
request::RequestImpl,
Result,
},
desktop::account::UserInformation,
desktop::{account::UserInformation, HandleToken},
AppID, WindowIdentifierType,
};
use async_trait::async_trait;
Expand All @@ -14,8 +14,8 @@ pub struct Account;

#[async_trait]
impl RequestImpl for Account {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand All @@ -39,6 +39,7 @@ mod fdo_account {
impl AccountImpl for Account {
async fn get_user_information(
&self,
_token: HandleToken,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: UserInformationOptions,
Expand Down
8 changes: 5 additions & 3 deletions backend-demo/src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ashpd::{
screenshot::{ColorOptions, ScreenshotImpl, ScreenshotOptions},
Result,
},
desktop::{screenshot::Screenshot as ScreenshotResponse, Color},
desktop::{screenshot::Screenshot as ScreenshotResponse, Color, HandleToken},
AppID, WindowIdentifierType,
};
use async_trait::async_trait;
Expand All @@ -14,15 +14,16 @@ pub struct Screenshot;

#[async_trait]
impl RequestImpl for Screenshot {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

#[async_trait]
impl ScreenshotImpl for Screenshot {
async fn screenshot(
&self,
_token: HandleToken,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: ScreenshotOptions,
Expand All @@ -34,6 +35,7 @@ impl ScreenshotImpl for Screenshot {

async fn pick_color(
&self,
_token: HandleToken,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: ColorOptions,
Expand Down
6 changes: 4 additions & 2 deletions backend-demo/src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;

use ashpd::{
backend::{request::RequestImpl, secret::SecretImpl, Result},
desktop::HandleToken,
zbus::zvariant::OwnedValue,
AppID,
};
Expand All @@ -12,15 +13,16 @@ pub struct Secret;

#[async_trait]
impl RequestImpl for Secret {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

#[async_trait]
impl SecretImpl for Secret {
async fn retrieve(
&self,
_token: HandleToken,
_app_id: AppID,
_fd: std::os::fd::OwnedFd,
) -> Result<HashMap<String, OwnedValue>> {
Expand Down
9 changes: 6 additions & 3 deletions backend-demo/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use ashpd::{
request::RequestImpl,
settings::{SettingsImpl, SettingsSignalEmitter},
},
desktop::settings::{ColorScheme, Namespace, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY},
desktop::{
arun-mani-j marked this conversation as resolved.
Show resolved Hide resolved
settings::{ColorScheme, Namespace, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY},
HandleToken,
},
zbus::zvariant::OwnedValue,
PortalError,
};
Expand All @@ -20,8 +23,8 @@ pub struct Settings {

#[async_trait]
impl RequestImpl for Settings {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
6 changes: 4 additions & 2 deletions backend-demo/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ashpd::{
wallpaper::{WallpaperImpl, WallpaperOptions},
Result,
},
desktop::HandleToken,
AppID, WindowIdentifierType,
};
use async_trait::async_trait;
Expand All @@ -13,15 +14,16 @@ pub struct Wallpaper;

#[async_trait]
impl RequestImpl for Wallpaper {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

#[async_trait]
impl WallpaperImpl for Wallpaper {
async fn with_uri(
&self,
_token: HandleToken,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_uri: url::Url,
Expand Down
7 changes: 5 additions & 2 deletions src/backend/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
},
desktop::{file_chooser::Choice, request::Response, Icon},
desktop::{file_chooser::Choice, request::Response, HandleToken, Icon},
zvariant::{self, DeserializeDict, OwnedObjectPath, SerializeDict},
AppID, WindowIdentifierType,
};
Expand Down Expand Up @@ -63,8 +63,10 @@ impl AccessResponse {

#[async_trait]
pub trait AccessImpl: RequestImpl {
#[allow(clippy::too_many_arguments)]
async fn access_dialog(
&self,
token: HandleToken,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
title: String,
Expand Down Expand Up @@ -109,10 +111,11 @@ impl AccessInterface {
Request::spawn(
"Access::AccessDialog",
&self.cnx,
handle,
handle.clone(),
Arc::clone(&self.imp),
async move {
imp.access_dialog(
HandleToken::try_from(&handle).unwrap(),
app_id.inner(),
window_identifier.inner(),
title,
Expand Down
14 changes: 10 additions & 4 deletions src/backend/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
},
desktop::{account::UserInformation, request::Response},
desktop::{account::UserInformation, request::Response, HandleToken},
zvariant::{DeserializeDict, OwnedObjectPath, Type},
AppID, WindowIdentifierType,
};
Expand All @@ -28,6 +28,7 @@ impl UserInformationOptions {
pub trait AccountImpl: RequestImpl {
async fn get_user_information(
&self,
token: HandleToken,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
options: UserInformationOptions,
Expand Down Expand Up @@ -66,11 +67,16 @@ impl AccountInterface {
Request::spawn(
"Account::GetUserInformation",
&self.cnx,
handle,
handle.clone(),
Arc::clone(&self.imp),
async move {
imp.get_user_information(app_id.inner(), window_identifier.inner(), options)
.await
imp.get_user_information(
HandleToken::try_from(&handle).unwrap(),
app_id.inner(),
window_identifier.inner(),
options,
)
.await
},
)
.await
Expand Down
15 changes: 11 additions & 4 deletions src/backend/app_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier,
},
desktop::Response,
desktop::{HandleToken, Response},
zbus::object_server::{InterfaceRef, ObjectServer},
zvariant::{DeserializeDict, OwnedObjectPath, SerializeDict, Type},
ActivationToken, AppID, PortalError, WindowIdentifierType,
Expand Down Expand Up @@ -79,6 +79,7 @@ impl Choice {
pub trait AppChooserImpl: RequestImpl {
async fn choose_application(
&self,
token: HandleToken,
app_id: Option<AppID>,
parent_window: Option<WindowIdentifierType>,
choices: Vec<AppID>,
Expand Down Expand Up @@ -124,11 +125,17 @@ impl AppChooserInterface {
Request::spawn(
"AppChooser::ChooseApplication",
&self.cnx,
handle,
handle.clone(),
Arc::clone(&self.imp),
async move {
imp.choose_application(app_id.inner(), parent_window.inner(), choices, options)
.await
imp.choose_application(
HandleToken::try_from(&handle).unwrap(),
app_id.inner(),
parent_window.inner(),
choices,
options,
)
.await
},
)
.await
Expand Down
17 changes: 12 additions & 5 deletions src/backend/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::{
backend::request::{Request, RequestImpl},
desktop::Response,
desktop::{HandleToken, Response},
zbus::object_server::SignalEmitter,
zvariant::{OwnedObjectPath, SerializeDict, Type},
AppID, PortalError,
Expand Down Expand Up @@ -56,8 +56,12 @@ pub trait BackgroundSignalEmitter: Send + Sync {
pub trait BackgroundImpl: RequestImpl {
async fn get_app_state(&self) -> Result<HashMap<AppID, AppState>, PortalError>;

async fn notify_background(&self, app_id: AppID, name: &str)
-> Result<Background, PortalError>;
async fn notify_background(
&self,
token: HandleToken,
app_id: AppID,
name: &str,
) -> Result<Background, PortalError>;

async fn enable_autostart(
&self,
Expand Down Expand Up @@ -128,9 +132,12 @@ impl BackgroundInterface {
Request::spawn(
"Background::NotifyBackground",
&self.cnx,
handle,
handle.clone(),
Arc::clone(&self.imp),
async move { imp.notify_background(app_id, &name).await },
async move {
imp.notify_background(HandleToken::try_from(&handle).unwrap(), app_id, &name)
.await
},
)
.await
}
Expand Down
14 changes: 10 additions & 4 deletions src/backend/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
request::{Request, RequestImpl},
MaybeAppID, MaybeWindowIdentifier, Result,
},
desktop::request::Response,
desktop::{request::Response, HandleToken},
zvariant::{self, DeserializeDict, OwnedObjectPath},
ActivationToken, AppID, WindowIdentifierType,
};
Expand Down Expand Up @@ -63,6 +63,7 @@ impl Options {
pub trait EmailImpl: RequestImpl {
async fn compose(
&self,
token: HandleToken,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
options: Options,
Expand Down Expand Up @@ -100,11 +101,16 @@ impl EmailInterface {
Request::spawn(
"Email::ComposeEmail",
&self.cnx,
handle,
handle.clone(),
Arc::clone(&self.imp),
async move {
imp.compose(app_id.inner(), window_identifier.inner(), options)
.await
imp.compose(
HandleToken::try_from(&handle).unwrap(),
app_id.inner(),
window_identifier.inner(),
options,
)
.await
},
)
.await
Expand Down
Loading