From 99ffa88657ee9081c3e9035fdc57fea93517da04 Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Sat, 14 May 2022 18:19:11 -0700 Subject: [PATCH] Add "auth failed" message to unlock dialog --- dialog-gtk3/src/main.rs | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/dialog-gtk3/src/main.rs b/dialog-gtk3/src/main.rs index 3706e8a..38f38fb 100644 --- a/dialog-gtk3/src/main.rs +++ b/dialog-gtk3/src/main.rs @@ -25,6 +25,8 @@ fn main() -> anyhow::Result<()> { gtk::init()?; + let (tx, rx) = glib::MainContext::sync_channel(glib::PRIORITY_DEFAULT, 1); + let top_sg = gtk::SizeGroup::builder() .mode(gtk::SizeGroupMode::Horizontal) .build(); @@ -143,7 +145,31 @@ fn main() -> anyhow::Result<()> { vbox.pack_start(&label, false, false, 0); glib::timeout_add_seconds_local(1, move || { set_time_label(&label); - glib::source::Continue(true) + glib::Continue(true) + }); + + let attrs = gtk::pango::AttrList::new(); + attrs.insert(gtk::pango::AttrFloat::new_scale(gtk::pango::SCALE_XX_LARGE)); + let mut bold_desc = gtk::pango::FontDescription::new(); + bold_desc.set_weight(gtk::pango::Weight::Bold); + attrs.insert(gtk::pango::AttrFontDesc::new(&bold_desc)); + let auth_failed_label = gtk::Label::builder() + .label("Authentication Failed!") + .xalign(0.5) + .yalign(0.5) + .attributes(&attrs) + .opacity(0.0) + .build(); + vbox.pack_start(&auth_failed_label, false, false, 0); + + rx.attach(None, move |exit_status| { + if exit_status != 0 { + auth_failed_label.set_opacity(1.0); + glib::timeout_add_seconds_local_once(2, move || exit(exit_status)); + } else { + exit(exit_status); + } + glib::Continue(true) }); let sep = gtk::Separator::builder() @@ -243,11 +269,12 @@ fn main() -> anyhow::Result<()> { let username = username.clone(); let password = password_box.text().to_string(); + let tx = tx.clone(); thread::spawn(move || { - if authenticate(&username, &password) { - exit(0); - } else { - exit(-1); + let status = if authenticate(&username, &password) { 0 } else { -1 }; + if let Err(err) = tx.send(status) { + error!("Failed to send exit status to main thread: {}", err); + exit(2); } }); }); @@ -268,7 +295,7 @@ fn main() -> anyhow::Result<()> { { let timer = Rc::clone(&timer); let delta = (DIALOG_UPDATE_INTERVAL.as_millis() as f64) / (DIALOG_TIMEOUT.as_millis() as f64); - gtk::glib::source::timeout_add_local(DIALOG_UPDATE_INTERVAL, move || { + glib::timeout_add_local(DIALOG_UPDATE_INTERVAL, move || { let new_fraction = timer.fraction() - delta; if new_fraction <= 0.0 { exit(1);