From 6e66f47887020a02f3e634faa443e9dfeb7048af Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Sat, 22 Mar 2025 20:03:43 +0100 Subject: [PATCH] ask the user to accept unauthorized devices --- .../resources/authorization_window.ui | 102 +++++++++++ .../resources/resources.gresource.xml | 1 + lan-mouse-gtk/src/authorization_window.rs | 19 ++ lan-mouse-gtk/src/authorization_window/imp.rs | 75 ++++++++ lan-mouse-gtk/src/fingerprint_window.rs | 8 +- lan-mouse-gtk/src/lib.rs | 18 +- lan-mouse-gtk/src/window.rs | 34 +++- lan-mouse-gtk/src/window/imp.rs | 2 +- lan-mouse-ipc/src/lib.rs | 15 +- src/emulation.rs | 64 ++++--- src/listen.rs | 162 +++++++++++------- src/service.rs | 20 ++- 12 files changed, 421 insertions(+), 99 deletions(-) create mode 100644 lan-mouse-gtk/resources/authorization_window.ui create mode 100644 lan-mouse-gtk/src/authorization_window.rs create mode 100644 lan-mouse-gtk/src/authorization_window/imp.rs diff --git a/lan-mouse-gtk/resources/authorization_window.ui b/lan-mouse-gtk/resources/authorization_window.ui new file mode 100644 index 0000000..49f0c26 --- /dev/null +++ b/lan-mouse-gtk/resources/authorization_window.ui @@ -0,0 +1,102 @@ + + + + + + diff --git a/lan-mouse-gtk/resources/resources.gresource.xml b/lan-mouse-gtk/resources/resources.gresource.xml index 2a6812f..c94be6b 100644 --- a/lan-mouse-gtk/resources/resources.gresource.xml +++ b/lan-mouse-gtk/resources/resources.gresource.xml @@ -2,6 +2,7 @@ window.ui + authorization_window.ui fingerprint_window.ui client_row.ui key_row.ui diff --git a/lan-mouse-gtk/src/authorization_window.rs b/lan-mouse-gtk/src/authorization_window.rs new file mode 100644 index 0000000..1e1a026 --- /dev/null +++ b/lan-mouse-gtk/src/authorization_window.rs @@ -0,0 +1,19 @@ +mod imp; + +use glib::Object; +use gtk::{gio, glib, subclass::prelude::ObjectSubclassIsExt}; + +glib::wrapper! { + pub struct AuthorizationWindow(ObjectSubclass) + @extends adw::Window, gtk::Window, gtk::Widget, + @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable, + gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager; +} + +impl AuthorizationWindow { + pub(crate) fn new(fingerprint: &str) -> Self { + let window: Self = Object::builder().build(); + window.imp().set_fingerprint(fingerprint); + window + } +} diff --git a/lan-mouse-gtk/src/authorization_window/imp.rs b/lan-mouse-gtk/src/authorization_window/imp.rs new file mode 100644 index 0000000..4792b2b --- /dev/null +++ b/lan-mouse-gtk/src/authorization_window/imp.rs @@ -0,0 +1,75 @@ +use std::sync::OnceLock; + +use adw::prelude::*; +use adw::subclass::prelude::*; +use glib::subclass::InitializingObject; +use gtk::{ + glib::{self, subclass::Signal}, + template_callbacks, Button, CompositeTemplate, Label, +}; + +#[derive(CompositeTemplate, Default)] +#[template(resource = "/de/feschber/LanMouse/authorization_window.ui")] +pub struct AuthorizationWindow { + #[template_child] + pub fingerprint: TemplateChild