diff --git a/Cargo.toml b/Cargo.toml index 4878082..0a8520b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,15 @@ name = "authenticator" version = "4.3.1" rust-version = "1.70" +[profile.release] +debug = true + +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 3 + [dependencies] adw = {package = "libadwaita", version = "0.5", features = ["v1_4"]} aes-gcm = "0.10" diff --git a/src/application.rs b/src/application.rs index e5a39f4..04619cd 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,4 +1,7 @@ -use std::collections::HashMap; +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; use adw::prelude::*; use futures_util::StreamExt; @@ -36,7 +39,7 @@ mod imp { pub model: ProvidersModel, #[property(get, set, construct)] pub is_locked: Cell, - pub lock_timeout_id: RefCell>, + pub lock_timeout_id: RefCell>, #[property(get, set, construct)] pub can_be_locked: Cell, #[property(get, set, construct_only)] @@ -326,20 +329,33 @@ impl Application { self.cancel_lock_timeout(); if !self.is_locked() && self.can_be_locked() { - let id = glib::timeout_add_seconds_local( + let (tx, rx) = futures_channel::oneshot::channel::<()>(); + let tx = Arc::new(Mutex::new(Some(tx))); + let id = glib::source::timeout_source_new_seconds( timeout, - clone!(@weak self as app => @default-return glib::ControlFlow::Break, move || { - app.set_is_locked(true); + None, + glib::Priority::HIGH, + clone!(@strong tx => move || { + let Some(tx) = tx.lock().unwrap().take() else { + return glib::ControlFlow::Break; + }; + tx.send(()).unwrap(); glib::ControlFlow::Break }), ); + spawn(clone!(@strong self as app => async move { + if let Ok(()) = rx.await { + app.set_is_locked(true); + } + })); + id.attach(Some(&glib::MainContext::default())); imp.lock_timeout_id.replace(Some(id)); } } fn cancel_lock_timeout(&self) { if let Some(id) = self.imp().lock_timeout_id.borrow_mut().take() { - id.remove(); + id.destroy(); } }