mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
prevent authorization request spamming windows (#335)
This commit is contained in:
committed by
GitHub
parent
4e5a66340a
commit
0dd413e989
@@ -474,6 +474,9 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn request_authorization(&self, fingerprint: &str) {
|
pub(super) fn request_authorization(&self, fingerprint: &str) {
|
||||||
|
if let Some(w) = self.imp().authorization_window.borrow_mut().take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
let window = AuthorizationWindow::new(fingerprint);
|
let window = AuthorizationWindow::new(fingerprint);
|
||||||
window.set_transient_for(Some(self));
|
window.set_transient_for(Some(self));
|
||||||
window.connect_closure(
|
window.connect_closure(
|
||||||
@@ -496,5 +499,6 @@ impl Window {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
window.present();
|
window.present();
|
||||||
|
self.imp().authorization_window.replace(Some(window));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use gtk::{gdk, gio, glib, Button, CompositeTemplate, Entry, Image, Label, ListBo
|
|||||||
|
|
||||||
use lan_mouse_ipc::{FrontendRequestWriter, DEFAULT_PORT};
|
use lan_mouse_ipc::{FrontendRequestWriter, DEFAULT_PORT};
|
||||||
|
|
||||||
|
use crate::authorization_window::AuthorizationWindow;
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Default)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/de/feschber/LanMouse/window.ui")]
|
#[template(resource = "/de/feschber/LanMouse/window.ui")]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
@@ -49,6 +51,7 @@ pub struct Window {
|
|||||||
pub port: Cell<u16>,
|
pub port: Cell<u16>,
|
||||||
pub capture_active: Cell<bool>,
|
pub capture_active: Cell<bool>,
|
||||||
pub emulation_active: Cell<bool>,
|
pub emulation_active: Cell<bool>,
|
||||||
|
pub authorization_window: RefCell<Option<AuthorizationWindow>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ impl ListenTask {
|
|||||||
async fn run(mut self) {
|
async fn run(mut self) {
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||||
let mut last_response = HashMap::new();
|
let mut last_response = HashMap::new();
|
||||||
|
let mut rejected_connections = HashMap::new();
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
e = self.listener.next() => {match e {
|
e = self.listener.next() => {match e {
|
||||||
@@ -156,7 +157,10 @@ impl ListenTask {
|
|||||||
self.event_tx.send(EmulationEvent::Connected { addr, fingerprint }).expect("channel closed");
|
self.event_tx.send(EmulationEvent::Connected { addr, fingerprint }).expect("channel closed");
|
||||||
}
|
}
|
||||||
Some(ListenEvent::Rejected { fingerprint }) => {
|
Some(ListenEvent::Rejected { fingerprint }) => {
|
||||||
self.event_tx.send(EmulationEvent::ConnectionAttempt { fingerprint }).expect("channel closed");
|
if rejected_connections.insert(fingerprint.clone(), Instant::now())
|
||||||
|
.is_none_or(|i| i.elapsed() >= Duration::from_secs(2)) {
|
||||||
|
self.event_tx.send(EmulationEvent::ConnectionAttempt { fingerprint }).expect("channel closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => break
|
None => break
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user