Skip to content

Commit

Permalink
backend: Add basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
A6GibKm authored and bilelmoussaoui committed Feb 28, 2023
1 parent ec5c623 commit 8a77700
Show file tree
Hide file tree
Showing 37 changed files with 3,144 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: --features "gtk4,pipewire,wayland,raw_handle"
args: --features "gtk4,pipewire,wayland,raw_handle,backend"
- uses: actions-rs/cargo@v1
with:
command: check
args: --features "gtk3,pipewire,wayland,raw_handle"
args: --features "gtk3,pipewire,wayland,raw_handle,backend"

test:
name: Test Suite
Expand All @@ -46,11 +46,11 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --features "gtk4,pipewire,wayland,raw_handle"
args: --features "gtk4,pipewire,wayland,raw_handle,backend"
- uses: actions-rs/cargo@v1
with:
command: test
args: --features "gtk3,pipewire,wayland,raw_handle"
args: --features "gtk3,pipewire,wayland,raw_handle,backend"

fmt:
name: Rustfmt
Expand Down Expand Up @@ -90,8 +90,8 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --features "gtk4,pipewire,wayland,raw_handle" -- -D warnings
args: --features "gtk4,pipewire,wayland,raw_handle,backend" -- -D warnings
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --features "gtk3,pipewire,wayland,raw_handle" -- -D warnings
args: --features "gtk3,pipewire,wayland,raw_handle,backend" -- -D warnings
85 changes: 85 additions & 0 deletions .github/workflows/backend-demo-ci.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ ashpd-demo/_build/
ashpd-demo/builddir/
ashpd-demo/src/config.rs
ashpd-demo/target/
ashpd-backend-demo/target

.flatpak
.vscode
_build/
builddir/
session-test
.fenv
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ version = "0.4.0-alpha.4"

[features]
default = ["async-std"]
backend = ["async-trait", "futures", "nix"]
backend_gtk3 = ["backend_gtk3_x11", "backend_gtk3_wayland"]
backend_gtk3_x11 = ["x11", "gtk3_x11"]
backend_gtk3_wayland = ["gtk3_wayland"]
backend_gtk4 = ["backend_gtk4_x11", "backend_gtk4_wayland"]
backend_gtk4_x11 = ["x11", "gtk4_x11", "gdk4x11/xlib"]
backend_gtk4_wayland = ["gtk4_wayland"]

gtk3_x11 = ["gdk3x11", "dep:gtk3"]
gtk3_wayland = ["gdk3wayland", "dep:gtk3"]
gtk3 = ["gtk3_x11", "gtk3_wayland"]
Expand All @@ -33,6 +41,9 @@ gdk4wayland = {package = "gdk4-wayland", version = "0.6", optional = true}
gdk4x11 = {package = "gdk4-x11", version = "0.6", optional = true}
gtk4 = {version = "0.6", optional = true}

x11 = { version = "2.18.1", features = ["xlib"], optional = true }
nix = {version = "0.26", features = ["user"], default-features=false, optional=true}

pw = {package= "pipewire", version = "0.6", optional = true}
serde = {version = "1.0", features = ["derive"]}
serde_repr = "0.1"
Expand All @@ -50,6 +61,8 @@ async-std = {version = "1.12", optional = true}
tokio = {version = "1.21", features = ["fs", "io-util"], optional = true, default-features = false}
once_cell = "1.14"
url = {version = "2.3", features = ["serde"]}
async-trait = {version = "0.1.60", optional = true}
futures = { version = "0.3.25", features = ["executor", "thread-pool"], optional = true}

[dev-dependencies]
serde_json = "1.0"
Expand Down
25 changes: 25 additions & 0 deletions ashpd-backend-demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "ashpd-backend-demo"
version = "0.1.0"
edition = "2021"

[dependencies]
adw = {package = "libadwaita", version = "0.3", features = ["v1_2"] }
anyhow = "1.0"
async-trait = "0.1.60"
byteorder = "1.4.3"
futures-channel = "0.3.25"
futures-util = "0.3.25"
gettext-rs = "0.7.0"
gtk = { version = "0.6", package = "gtk4", features = ["v4_10"] }
log = "0.4.17"
serde = { version = "1.0", features = ["derive"] }
tracing-subscriber = "0.3.16"
url = "2.3.1"

zbus = {version = "3.6.2", features = ["gvariant"] }
once_cell = "1.17.0"

[dependencies.ashpd]
path = "../"
features = ["backend", "gtk4", "backend_gtk4", "tracing"]
4 changes: 4 additions & 0 deletions ashpd-backend-demo/data/ashpd-gnome.portal
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
60 changes: 60 additions & 0 deletions ashpd-backend-demo/src/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::ops::ControlFlow;

use ashpd::{
backend::{
account::{AccountImpl, UserInformationOptions},
request::RequestImpl,
},
desktop::{account::UserInformation, Response},
AppID, ExternalWindow, WindowIdentifierType,
};
use async_trait::async_trait;
use gtk::prelude::*;

use crate::account_preview::AccountPreview;

#[derive(Default)]
pub struct Account;

#[async_trait]
impl RequestImpl for Account {
async fn close(&self) {
log::debug!("IN Close()");
}
}

#[async_trait]
impl AccountImpl for Account {
async fn get_user_information(
&self,
app_id: AppID,
window_identifier: WindowIdentifierType,
options: UserInformationOptions,
) -> Response<UserInformation> {
log::debug!("IN GetUserInformation({app_id}, {window_identifier:?}, {options:?})",);
let flow: ControlFlow<(), UserInformation> = {
log::debug!("Opening account preview");
let preview = AccountPreview::default();
preview.set_heading(&app_id, options.reason());
{
let external_window = ExternalWindow::new(window_identifier);
let fake_window = ExternalWindow::fake(external_window.as_ref());
preview.set_transient_for(Some(&fake_window));

if let Some(ref external) = external_window {
gtk::Widget::realize(preview.upcast_ref());
external.set_parent_of(&preview.surface());
}
}
preview.present_and_wait().await
};

let response = match flow {
ControlFlow::Break(()) => Response::cancelled(),
ControlFlow::Continue(user_info) => Response::Ok(user_info),
};

log::debug!("OUT GetUserInformation({response:?})",);
response
}
}
Loading

0 comments on commit 8a77700

Please sign in to comment.