diff --git a/Cargo.lock b/Cargo.lock index a852ccd..811e6d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,14 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" +[[package]] +name = "accessdialog" +version = "0.1.0" +dependencies = [ + "slint", + "slint-build", +] + [[package]] name = "accesskit" version = "0.11.2" @@ -5198,6 +5206,7 @@ dependencies = [ name = "xdg-desktop-portal-luminous" version = "0.3.4" dependencies = [ + "accessdialog", "anyhow", "bitflags 2.4.0", "csscolorparser", diff --git a/Cargo.toml b/Cargo.toml index 303c89f..bc0c9bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } @@ -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" @@ -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" } diff --git a/libs/accessdialog/Cargo.toml b/libs/accessdialog/Cargo.toml new file mode 100644 index 0000000..2a3f659 --- /dev/null +++ b/libs/accessdialog/Cargo.toml @@ -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" diff --git a/libs/accessdialog/build.rs b/libs/accessdialog/build.rs new file mode 100644 index 0000000..5d7cb96 --- /dev/null +++ b/libs/accessdialog/build.rs @@ -0,0 +1,3 @@ +fn main() { + slint_build::compile("ui/dialog.slint").unwrap(); +} diff --git a/libs/accessdialog/src/lib.rs b/libs/accessdialog/src/lib.rs new file mode 100644 index 0000000..27695e9 --- /dev/null +++ b/libs/accessdialog/src/lib.rs @@ -0,0 +1,29 @@ +slint::include_modules!(); + +use std::sync::mpsc; + +fn init_slots(ui: &AppWindow, sender: mpsc::Sender) { + 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 + } +} diff --git a/libs/accessdialog/ui/dialog.slint b/libs/accessdialog/ui/dialog.slint new file mode 100644 index 0000000..6268829 --- /dev/null +++ b/libs/accessdialog/ui/dialog.slint @@ -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 information : "No information"; + in-out property 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() } + } + } + } +} diff --git a/src/access.rs b/src/access.rs index a9df379..a60697d 100644 --- a/src/access.rs +++ b/src/access.rs @@ -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>> { - Ok(PortalResponse::Success(HashMap::new())) + if accessdialog::confirmgui(title, sub_title) { + Ok(PortalResponse::Success(HashMap::new())) + } else { + Ok(PortalResponse::Cancelled) + } } // add code here }