-
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 8200f74
Showing
28 changed files
with
1,481 additions
and
14 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,85 @@ | ||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
|
||
name: Backend Demo CI | ||
|
||
jobs: | ||
check: | ||
name: Check | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: ghcr.io/gtk-rs/gtk4-rs/gtk4:latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: sudo dnf install -y gettext-devel | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: check | ||
args: --manifest-path=ashpd-backend-demo/Cargo.toml | ||
|
||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: ghcr.io/gtk-rs/gtk4-rs/gtk4:latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: sudo dnf install -y gettext-devel | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --manifest-path=ashpd-backend-demo/Cargo.toml | ||
|
||
fmt: | ||
name: Rustfmt | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: ghcr.io/gtk-rs/gtk4-rs/gtk4:latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: sudo dnf install -y gettext-devel | ||
- 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=ashpd-backend-demo/Cargo.toml --all -- --check | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: ghcr.io/gtk-rs/gtk4-rs/gtk4:latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: sudo dnf install -y gettext-devel | ||
- 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=ashpd-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
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,4 @@ | ||
[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; | ||
UseIn=gnome |
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::{ | ||
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> { | ||
tracing::debug!("IN GetUserInformation({app_id}, {window_identifier:?}, {options:?})",); | ||
|
||
let response = match UserInformation::current_user().await { | ||
Ok(info) => Response::ok(info), | ||
Err(err) => { | ||
tracing::error!("Failed to get user info: {err}"); | ||
Response::other() | ||
} | ||
}; | ||
|
||
tracing::debug!("OUT GetUserInformation({response:?})",); | ||
response | ||
} | ||
} |
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,44 @@ | ||
use ashpd::backend::Backend; | ||
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"; | ||
|
||
#[tokio::main] | ||
async fn main() -> ashpd::Result<()> { | ||
// Enable debug with `RUST_LOG=xdp_ashpd_gnome=debug COMMAND`. | ||
tracing_subscriber::fmt::init(); | ||
// | ||
tracing::debug!("Starting interfaces at {NAME}"); | ||
let 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,48 @@ | ||
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> { | ||
tracing::debug!("Taking a screenshot"); | ||
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> { | ||
tracing::debug!("Picking 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 from_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
Oops, something went wrong.