Skip to content

Commit

Permalink
chore: base accessdialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2023
1 parent a5a0770 commit 0123170
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 11 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ version = "0.3.4"
edition = "2021"

[workspace]
members = ["libs/screenshotdialog", "."]
members = ["libs/screenshotdialog", "libs/accessdialog", "."]

[dependencies]
screenshotdialog = { path = "libs/screenshotdialog" }
accessdialog = { path = "libs/accessdialog" }

zbus = { version = "3", default-features = false, features = ["tokio", "url"] }
tokio = { version = "1.32.0", features = ["full"] }
Expand All @@ -17,10 +18,10 @@ tracing-subscriber = "0.3.17"
url = { version = "2.4", features = ["serde"] }
serde_repr = "0.1"
image = { version = "0.24", default-features = false, features = [
"jpeg",
"png",
"pnm",
"qoi",
"jpeg",
"png",
"pnm",
"qoi",
] }

bitflags = "2.4.0"
Expand All @@ -37,14 +38,14 @@ rustix = { version = "0.38.13", features = ["fs", "use-libc"] }

# REMOTE
wayland-protocols = { version = "0.31.0", default-features = false, features = [
"unstable",
"client",
"unstable",
"client",
] }
#wayland-protocols = { version = "=0.30.0-beta.13", features = ["client", "unstable"] }


wayland-protocols-wlr = { version = "0.2.0", default-features = false, features = [
"client",
"client",
] }
wayland-client = { version = "0.31.1" }

Expand Down
12 changes: 12 additions & 0 deletions libs/accessdialog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "accessdialog"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
slint = "1.2.1"

[build-dependencies]
slint-build = "1.2.1"
3 changes: 3 additions & 0 deletions libs/accessdialog/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
slint_build::compile("ui/dialog.slint").unwrap();
}
29 changes: 29 additions & 0 deletions libs/accessdialog/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
slint::include_modules!();

use std::sync::mpsc;

fn init_slots(ui: &AppWindow, sender: mpsc::Sender<bool>) {
let global = ConfirmSlots::get(ui);
let send_confirm = sender.clone();
global.on_Reject(move || {
let _ = sender.send(false);
let _ = slint::quit_event_loop();
});
global.on_Confirm(move || {
let _ = send_confirm.send(true);
let _ = slint::quit_event_loop();
});
}

pub fn confirmgui(title: String, information: String) -> bool {
let ui = AppWindow::new().unwrap();
ui.set_init_title(title.into());
ui.set_information(information.into());
let (sender, receiver) = mpsc::channel();
init_slots(&ui, sender);
if let Ok(message) = receiver.recv_timeout(std::time::Duration::from_nanos(300)) {
message
} else {
false
}
}
34 changes: 34 additions & 0 deletions libs/accessdialog/ui/dialog.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Button, VerticalBox, HorizontalBox} from "std-widgets.slint";

export global ConfirmSlots {
callback Confirm();
callback Reject();
}

export component AppWindow inherits Window {
in-out property <string> information : "No information";
in-out property <string> init_title : "AccessWindow";
title: init_title;
width: 400px;
height: 100px;
VerticalBox {
Text {
horizontal-alignment: center;
text: information;
font-size: 25px;
}
HorizontalBox {
alignment: center;
Button {
height: 30px;
text: "Reject";
clicked => { ConfirmSlots.Reject() }
}
Button {
height: 30px;
text: "Accept";
clicked => { ConfirmSlots.Confirm() }
}
}
}
}
10 changes: 7 additions & 3 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ impl AccessBackend {
_request_handle: ObjectPath<'_>,
_app_id: String,
_parrent_window: String,
_title: String,
_sub_title: String,
title: String,
sub_title: String,
_body: String,
_options: AccessOption,
) -> fdo::Result<PortalResponse<HashMap<String, OwnedValue>>> {
Ok(PortalResponse::Success(HashMap::new()))
if accessdialog::confirmgui(title, sub_title) {
Ok(PortalResponse::Success(HashMap::new()))
} else {
Ok(PortalResponse::Cancelled)
}
}
// add code here
}

0 comments on commit 0123170

Please sign in to comment.