-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47aa993
commit ad1618b
Showing
29 changed files
with
1,462 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
|
||
name: Backend Demo CI | ||
|
||
jobs: | ||
check: | ||
name: Check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: check | ||
args: --manifest-path=backend-demo/Cargo.toml | ||
|
||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --manifest-path=backend-demo/Cargo.toml | ||
|
||
fmt: | ||
name: Rustfmt | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- run: rustup component add rustfmt | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --manifest-path=backend-demo/Cargo.toml --all -- --check | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- run: rustup component add clippy | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: --manifest-path=backend-demo/Cargo.toml -- -D warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "ashpd-backend-demo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
async-trait = "0.1.60" | ||
tokio = { version = "1.0", features = ["io-util", "net", "time", "macros", "rt-multi-thread"] } | ||
byteorder = "1.4.3" | ||
futures-channel = "0.3.25" | ||
futures-util = "0.3.25" | ||
tracing = "0.1" | ||
tracing-subscriber = "0.3.16" | ||
url = "2.3.1" | ||
zbus = "4.2" | ||
|
||
[dependencies.ashpd] | ||
path = "../" | ||
features = ["backend", "tracing"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[portal] | ||
DBusName=org.freedesktop.impl.portal.desktop.ashpd-backend-demo | ||
Interfaces=org.freedesktop.impl.portal.Account;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Wallpaper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::num::NonZeroU32; | ||
|
||
use ashpd::{ | ||
backend::{ | ||
account::{AccountImpl, UserInformationOptions}, | ||
request::RequestImpl, | ||
}, | ||
desktop::{account::UserInformation, Response}, | ||
AppID, WindowIdentifierType, | ||
}; | ||
use async_trait::async_trait; | ||
|
||
#[derive(Default)] | ||
pub struct Account; | ||
|
||
#[async_trait] | ||
impl RequestImpl for Account { | ||
async fn close(&self) { | ||
tracing::debug!("IN Close()"); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AccountImpl for Account { | ||
const VERSION: NonZeroU32 = NonZeroU32::MIN; | ||
|
||
async fn get_information( | ||
&self, | ||
_app_id: AppID, | ||
_window_identifier: Option<WindowIdentifierType>, | ||
_options: UserInformationOptions, | ||
) -> Response<UserInformation> { | ||
match UserInformation::current_user().await { | ||
Ok(info) => Response::ok(info), | ||
Err(err) => { | ||
tracing::error!("Failed to get user info: {err}"); | ||
Response::other() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use futures_util::future::pending; | ||
mod account; | ||
mod screenshot; | ||
mod wallpaper; | ||
|
||
use account::Account; | ||
use screenshot::Screenshot; | ||
use wallpaper::Wallpaper; | ||
|
||
// NOTE Uncomment if you have ashpd-backend-demo.portal installed. | ||
// const NAME: &str = "org.freedesktop.impl.portal.desktop.ashpd-backend-demo"; | ||
const NAME: &str = "org.freedesktop.impl.portal.desktop.gnome"; | ||
// Run with | ||
// RUST_LOG=ashpd_backend_demo=debug,ashpd=debug cargo run --manifest-path ./backend-demo/Cargo.toml | ||
|
||
#[tokio::main] | ||
async fn main() -> ashpd::Result<()> { | ||
// Enable debug with `RUST_LOG=ashpd_backend_demo=debug COMMAND`. | ||
tracing_subscriber::fmt::init(); | ||
|
||
tracing::debug!("Serving interfaces at {NAME}"); | ||
let backend = ashpd::backend::Backend::new(NAME).await?; | ||
let account = ashpd::backend::account::Account::new(Account, &backend).await?; | ||
tokio::task::spawn(async move { | ||
loop { | ||
account.try_next().await.unwrap(); | ||
} | ||
}); | ||
let wallpaper = ashpd::backend::wallpaper::Wallpaper::new(Wallpaper, &backend).await?; | ||
tokio::task::spawn(async move { | ||
loop { | ||
wallpaper.try_next().await.unwrap(); | ||
} | ||
}); | ||
let screenshot = ashpd::backend::screenshot::Screenshot::new(Screenshot, &backend).await?; | ||
tokio::task::spawn(async move { | ||
loop { | ||
screenshot.try_next().await.unwrap(); | ||
} | ||
}); | ||
|
||
loop { | ||
pending::<()>().await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::num::NonZeroU32; | ||
|
||
use ashpd::{ | ||
backend::{ | ||
request::RequestImpl, | ||
screenshot::{ColorOptions, ScreenshotImpl, ScreenshotOptions}, | ||
}, | ||
desktop::{screenshot::Screenshot as ScreenshotResponse, Color, Response}, | ||
AppID, WindowIdentifierType, | ||
}; | ||
use async_trait::async_trait; | ||
|
||
#[derive(Default)] | ||
pub struct Screenshot; | ||
|
||
#[async_trait] | ||
impl RequestImpl for Screenshot { | ||
async fn close(&self) { | ||
tracing::debug!("IN Close()"); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ScreenshotImpl for Screenshot { | ||
const VERSION: NonZeroU32 = NonZeroU32::MIN; | ||
|
||
async fn screenshot( | ||
&self, | ||
_app_id: AppID, | ||
_window_identifier: Option<WindowIdentifierType>, | ||
_options: ScreenshotOptions, | ||
) -> Response<ScreenshotResponse> { | ||
Response::ok(ScreenshotResponse::new( | ||
url::Url::parse("file:///some/sreenshot").unwrap(), | ||
)) | ||
} | ||
|
||
async fn pick_color( | ||
&self, | ||
_app_id: AppID, | ||
_window_identifier: Option<WindowIdentifierType>, | ||
_options: ColorOptions, | ||
) -> Response<Color> { | ||
Response::ok(Color::new(1.0, 1.0, 1.0)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::num::NonZeroU32; | ||
|
||
use ashpd::{ | ||
backend::{ | ||
request::RequestImpl, | ||
wallpaper::{WallpaperImpl, WallpaperOptions}, | ||
}, | ||
desktop::Response, | ||
AppID, WindowIdentifierType, | ||
}; | ||
use async_trait::async_trait; | ||
|
||
#[derive(Default)] | ||
pub struct Wallpaper; | ||
|
||
#[async_trait] | ||
impl RequestImpl for Wallpaper { | ||
async fn close(&self) { | ||
tracing::debug!("IN Close()"); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl WallpaperImpl for Wallpaper { | ||
const VERSION: NonZeroU32 = NonZeroU32::MIN; | ||
|
||
async fn with_uri( | ||
&self, | ||
app_id: AppID, | ||
window_identifier: Option<WindowIdentifierType>, | ||
uri: url::Url, | ||
options: WallpaperOptions, | ||
) -> Response<()> { | ||
tracing::debug!( | ||
"IN SetWallpaperURI({app_id}, {window_identifier:?}, {}, {options:?})", | ||
uri.as_str() | ||
); | ||
|
||
tracing::debug!("OUT SetWallpaperURI",); | ||
Response::ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::collections::HashMap; | ||
|
||
use zbus::zvariant::{OwnedValue, Value}; | ||
|
||
use crate::{ | ||
desktop::{request::Response, HandleToken, ResponseError}, | ||
AppID, WindowIdentifierType, | ||
}; | ||
|
||
pub struct Access {} | ||
|
||
#[zbus::interface(name = "org.freedesktop.impl.portal.Access")] | ||
impl Access { | ||
fn access_dialog( | ||
&self, | ||
_handle: HandleToken, | ||
_app_id: AppID, | ||
window_identifier: &str, | ||
_title: &str, | ||
_subtitle: &str, | ||
_body: &str, | ||
_options: HashMap<&str, Value<'_>>, | ||
) -> Response<HashMap<String, OwnedValue>> { | ||
#[cfg(feature = "tracing")] | ||
tracing::debug!("Access::AccessDialog"); | ||
let _window_identifier = if window_identifier.is_empty() { | ||
None | ||
} else { | ||
window_identifier.parse::<WindowIdentifierType>().ok() | ||
}; | ||
Response::Err(ResponseError::Cancelled) | ||
} | ||
} |
Oops, something went wrong.