-
Notifications
You must be signed in to change notification settings - Fork 47
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 f664cf3
Showing
30 changed files
with
1,646 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,21 @@ | ||
[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"] | ||
default-features = false |
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,54 @@ | ||
use futures_util::future::pending; | ||
mod account; | ||
mod screenshot; | ||
mod secret; | ||
mod wallpaper; | ||
|
||
use account::Account; | ||
use screenshot::Screenshot; | ||
use secret::Secret; | ||
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(); | ||
} | ||
}); | ||
let secret = ashpd::backend::secret::Secret::new(Secret, &backend).await?; | ||
tokio::task::spawn(async move { | ||
loop { | ||
secret.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,32 @@ | ||
use std::{collections::HashMap, num::NonZeroU32}; | ||
|
||
use ashpd::{ | ||
backend::{request::RequestImpl, secret::SecretImpl}, | ||
desktop::Response, | ||
zbus::zvariant::{self, OwnedValue}, | ||
AppID, | ||
}; | ||
use async_trait::async_trait; | ||
|
||
#[derive(Default)] | ||
pub struct Secret; | ||
|
||
#[async_trait] | ||
impl RequestImpl for Secret { | ||
async fn close(&self) { | ||
tracing::debug!("IN Close()"); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl SecretImpl for Secret { | ||
const VERSION: NonZeroU32 = NonZeroU32::MIN; | ||
|
||
async fn retrieve( | ||
&self, | ||
app_id: AppID, | ||
fd: zvariant::OwnedFd, | ||
) -> Response<HashMap<String, OwnedValue>> { | ||
Response::Ok(Default::default()) | ||
} | ||
} |
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,36 @@ | ||
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<()> { | ||
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
Oops, something went wrong.