Skip to content

Commit

Permalink
backend: Make AppID optional
Browse files Browse the repository at this point in the history
As some of the portals might be used just fine for unsandboxed apps
make it optional where it makes sense
  • Loading branch information
bilelmoussaoui committed Aug 10, 2024
1 parent 1168740 commit 409124b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion backend-demo/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl RequestImpl for Account {
impl AccountImpl for Account {
async fn get_information(
&self,
_app_id: AppID,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: UserInformationOptions,
) -> Response<UserInformation> {
Expand Down
4 changes: 2 additions & 2 deletions backend-demo/src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl RequestImpl for Screenshot {
impl ScreenshotImpl for Screenshot {
async fn screenshot(
&self,
_app_id: AppID,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: ScreenshotOptions,
) -> Response<ScreenshotResponse> {
Expand All @@ -33,7 +33,7 @@ impl ScreenshotImpl for Screenshot {

async fn pick_color(
&self,
_app_id: AppID,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_options: ColorOptions,
) -> Response<Color> {
Expand Down
2 changes: 1 addition & 1 deletion backend-demo/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl RequestImpl for Wallpaper {
impl WallpaperImpl for Wallpaper {
async fn with_uri(
&self,
_app_id: AppID,
_app_id: Option<AppID>,
_window_identifier: Option<WindowIdentifierType>,
_uri: url::Url,
_options: WallpaperOptions,
Expand Down
11 changes: 11 additions & 0 deletions src/app_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ impl AppID {
}
}

impl AppID {
#[cfg(feature = "backend")]
pub(crate) fn from_maybe_str(val: &str) -> Option<Self> {
if val.is_empty() {
None
} else {
val.parse::<Self>().ok()
}
}
}

impl FromStr for AppID {
type Err = crate::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
Expand Down
15 changes: 6 additions & 9 deletions src/backend/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl AccessOptions {
}
}

#[derive(SerializeDict, zvariant::Type, Default)]
#[derive(SerializeDict, Debug, zvariant::Type, Default)]
#[zvariant(signature = "dict")]
pub struct AccessResponse {
choices: Option<Vec<(String, String)>>,
Expand All @@ -74,7 +74,7 @@ impl AccessResponse {
pub trait AccessImpl {
async fn access_dialog(
&self,
app_id: AppID,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
title: String,
subtitle: String,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<T: AccessImpl + RequestImpl> Access<T> {
enum Action {
AccessDialog(
OwnedObjectPath,
AppID,
Option<AppID>,
Option<WindowIdentifierType>,
String,
String,
Expand Down Expand Up @@ -182,7 +182,7 @@ impl AccessInterface {
async fn access_dialog(
&self,
handle: OwnedObjectPath,
app_id: AppID,
app_id: &str,
window_identifier: &str,
title: String,
subtitle: String,
Expand All @@ -193,11 +193,8 @@ impl AccessInterface {
#[cfg(feature = "tracing")]
tracing::debug!("Access::AccessDialog");

let window_identifier = if window_identifier.is_empty() {
None
} else {
window_identifier.parse::<WindowIdentifierType>().ok()
};
let window_identifier = WindowIdentifierType::from_maybe_str(window_identifier);
let app_id = AppID::from_maybe_str(app_id);

let _ = self
.sender
Expand Down
13 changes: 5 additions & 8 deletions src/backend/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl UserInformationOptions {
pub trait AccountImpl: RequestImpl {
async fn get_information(
&self,
app_id: AppID,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
options: UserInformationOptions,
) -> Response<UserInformation>;
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<T: AccountImpl + RequestImpl> Account<T> {
enum Action {
GetUserInformation(
OwnedObjectPath,
AppID,
Option<AppID>,
Option<WindowIdentifierType>,
UserInformationOptions,
oneshot::Sender<Response<UserInformation>>,
Expand Down Expand Up @@ -131,19 +131,16 @@ impl AccountInterface {
async fn get_user_information(
&self,
handle: OwnedObjectPath,
app_id: AppID,
app_id: &str,
window_identifier: &str,
options: UserInformationOptions,
) -> Response<UserInformation> {
let (sender, receiver) = futures_channel::oneshot::channel();
#[cfg(feature = "tracing")]
tracing::debug!("Account::GetUserInformation");

let window_identifier = if window_identifier.is_empty() {
None
} else {
window_identifier.parse::<WindowIdentifierType>().ok()
};
let window_identifier = WindowIdentifierType::from_maybe_str(window_identifier);
let app_id = AppID::from_maybe_str(app_id);

let _ = self
.sender
Expand Down
30 changes: 14 additions & 16 deletions src/backend/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ pub struct ColorOptions;
pub trait ScreenshotImpl {
async fn screenshot(
&self,
app_id: AppID,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
options: ScreenshotOptions,
) -> Response<ScreenshotResponse>;

async fn pick_color(
&self,
app_id: AppID,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
options: ColorOptions,
) -> Response<Color>;
Expand Down Expand Up @@ -151,14 +151,14 @@ impl<T: ScreenshotImpl + RequestImpl> Screenshot<T> {
enum Action {
Screenshot(
OwnedObjectPath,
AppID,
Option<AppID>,
Option<WindowIdentifierType>,
ScreenshotOptions,
oneshot::Sender<Response<ScreenshotResponse>>,
),
PickColor(
OwnedObjectPath,
AppID,
Option<AppID>,
Option<WindowIdentifierType>,
ColorOptions,
oneshot::Sender<Response<Color>>,
Expand Down Expand Up @@ -188,18 +188,17 @@ impl ScreenshotInterface {
async fn screenshot(
&self,
handle: OwnedObjectPath,
app_id: AppID,
app_id: &str,
window_identifier: &str,
options: ScreenshotOptions,
) -> Response<ScreenshotResponse> {
#[cfg(feature = "tracing")]
tracing::debug!("Screenshot::Screenshot");
let (sender, receiver) = futures_channel::oneshot::channel();
let window_identifier = if window_identifier.is_empty() {
None
} else {
window_identifier.parse::<WindowIdentifierType>().ok()
};

let window_identifier = WindowIdentifierType::from_maybe_str(window_identifier);
let app_id = AppID::from_maybe_str(app_id);

let _ = self
.sender
.lock()
Expand All @@ -222,19 +221,18 @@ impl ScreenshotInterface {
async fn pick_color(
&self,
handle: OwnedObjectPath,
app_id: AppID,
app_id: &str,
window_identifier: &str,
options: ColorOptions,
) -> Response<Color> {
#[cfg(feature = "tracing")]
tracing::debug!("Screenshot::PickColor");

let (sender, receiver) = futures_channel::oneshot::channel();
let window_identifier = if window_identifier.is_empty() {
None
} else {
window_identifier.parse::<WindowIdentifierType>().ok()
};

let window_identifier = WindowIdentifierType::from_maybe_str(window_identifier);
let app_id = AppID::from_maybe_str(app_id);

let _ = self
.sender
.lock()
Expand Down
14 changes: 6 additions & 8 deletions src/backend/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl WallpaperOptions {
pub trait WallpaperImpl {
async fn with_uri(
&self,
app_id: AppID,
app_id: Option<AppID>,
window_identifier: Option<WindowIdentifierType>,
uri: url::Url,
options: WallpaperOptions,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<T: WallpaperImpl + RequestImpl> Wallpaper<T> {
enum Action {
SetWallpaperURI(
OwnedObjectPath,
AppID,
Option<AppID>,
Option<WindowIdentifierType>,
url::Url,
WallpaperOptions,
Expand Down Expand Up @@ -141,7 +141,7 @@ impl WallpaperInterface {
async fn set_wallpaper_uri(
&self,
handle: OwnedObjectPath,
app_id: AppID,
app_id: &str,
window_identifier: &str,
uri: url::Url,
options: WallpaperOptions,
Expand All @@ -150,11 +150,9 @@ impl WallpaperInterface {
tracing::debug!("Wallpaper::SetWallpaperURI");

let (sender, receiver) = futures_channel::oneshot::channel();
let window_identifier = if window_identifier.is_empty() {
None
} else {
window_identifier.parse::<WindowIdentifierType>().ok()
};

let window_identifier = WindowIdentifierType::from_maybe_str(window_identifier);
let app_id = AppID::from_maybe_str(app_id);

let _ = self
.sender
Expand Down
11 changes: 11 additions & 0 deletions src/window_identifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ pub enum WindowIdentifierType {
Wayland(String),
}

impl WindowIdentifierType {
#[cfg(feature = "backend")]
pub(crate) fn from_maybe_str(val: &str) -> Option<Self> {
if val.is_empty() {
None
} else {
val.parse::<Self>().ok()
}
}
}

impl fmt::Display for WindowIdentifierType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down

0 comments on commit 409124b

Please sign in to comment.