Skip to content

Commit

Permalink
Allow setting activation_token
Browse files Browse the repository at this point in the history
  • Loading branch information
apricotbucket28 committed Jun 20, 2024
1 parent cf99f85 commit 229d250
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
20 changes: 17 additions & 3 deletions src/desktop/dynamic_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ impl std::fmt::Debug for PrepareInstallResponse {
}
}

#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
/// Options to pass to [`DynamicLauncherProxy::launch`]
pub struct LaunchOptions {
activation_token: Option<String>,
}

impl LaunchOptions {
/// Sets the token that can be used to activate the chosen application.
#[must_use]
pub fn activation_token<'a>(mut self, activation_token: impl Into<Option<&'a str>>) -> Self {
self.activation_token = activation_token.into().map(ToOwned::to_owned);
self
}
}

#[derive(Debug)]
/// Wrong type of [`crate::desktop::Icon`] was used.
pub struct UnexpectedIconError;
Expand Down Expand Up @@ -321,9 +337,7 @@ impl<'a> DynamicLauncherProxy<'a> {
/// See also [`Launch`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.DynamicLauncher.html#org-freedesktop-portal-dynamiclauncher-launch).
#[doc(alias = "Launch")]
#[doc(alias = "xdp_portal_dynamic_launcher_launch")]
pub async fn launch(&self, desktop_file_id: &str) -> Result<(), Error> {
// TODO: handle activation_token
let options: HashMap<&str, zvariant::Value<'_>> = HashMap::new();
pub async fn launch(&self, desktop_file_id: &str, options: LaunchOptions) -> Result<(), Error> {
self.0.call("Launch", &(desktop_file_id, &options)).await
}

Expand Down
7 changes: 2 additions & 5 deletions src/desktop/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct EmailOptions {
subject: Option<String>,
body: Option<String>,
attachment_fds: Option<Vec<zvariant::OwnedFd>>,
// TODO Expose activation_token in the api
activation_token: Option<String>,
}

Expand Down Expand Up @@ -177,11 +176,9 @@ impl EmailRequest {
self
}

// TODO Added in version 4 of the interface.
/// Sets the activation token.
#[allow(dead_code)]
/// Sets the token that can be used to activate the chosen application.
#[must_use]
fn activation_token<'a>(mut self, activation_token: impl Into<Option<&'a str>>) -> Self {
pub fn activation_token<'a>(mut self, activation_token: impl Into<Option<&'a str>>) -> Self {
self.options.activation_token = activation_token.into().map(ToOwned::to_owned);
self
}
Expand Down
14 changes: 14 additions & 0 deletions src/desktop/open_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ impl OpenFileRequest {
self
}

/// Sets the token that can be used to activate the chosen application.
#[must_use]
pub fn activation_token<'a>(mut self, activation_token: impl Into<Option<&'a str>>) -> Self {
self.options.activation_token = activation_token.into().map(ToOwned::to_owned);
self
}

/// Send the request for a file.
pub async fn send_file(self, file: &BorrowedFd<'_>) -> Result<Request<()>, Error> {
let proxy = OpenURIProxy::new().await?;
Expand Down Expand Up @@ -203,6 +210,13 @@ impl OpenDirectoryRequest {
self
}

/// Sets the token that can be used to activate the chosen application.
#[must_use]
pub fn activation_token<'a>(mut self, activation_token: impl Into<Option<&'a str>>) -> Self {
self.options.activation_token = activation_token.into().map(ToOwned::to_owned);
self
}

/// Send the request.
pub async fn send(self, directory: &BorrowedFd<'_>) -> Result<Request<()>, Error> {
let proxy = OpenURIProxy::new().await?;
Expand Down

0 comments on commit 229d250

Please sign in to comment.