Show auth is happening after clicking Unlock
Changes the auth failed label into an auth status label, and prints a dot once every half second while authenticating. Also reduces the post-auth-failed pause to 1 second; 2 seconds is longer than it seems.
This commit is contained in:
parent
50a5e94307
commit
f0bbc9d982
@ -1,7 +1,7 @@
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use gdkx11::X11Window;
|
use gdkx11::X11Window;
|
||||||
use gethostname::gethostname;
|
use gethostname::gethostname;
|
||||||
use glib::GString;
|
use glib::{GString, clone, SourceId};
|
||||||
use gtk::{prelude::*, Button, Entry, Label, Plug, Window};
|
use gtk::{prelude::*, Button, Entry, Label, Plug, Window};
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use std::{io::{self, Write}, process::exit, rc::Rc, thread, time::Duration};
|
use std::{io::{self, Write}, process::exit, rc::Rc, thread, time::Duration};
|
||||||
@ -155,24 +155,26 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let mut bold_desc = gtk::pango::FontDescription::new();
|
let mut bold_desc = gtk::pango::FontDescription::new();
|
||||||
bold_desc.set_weight(gtk::pango::Weight::Bold);
|
bold_desc.set_weight(gtk::pango::Weight::Bold);
|
||||||
attrs.insert(gtk::pango::AttrFontDesc::new(&bold_desc));
|
attrs.insert(gtk::pango::AttrFontDesc::new(&bold_desc));
|
||||||
let auth_failed_label = gtk::Label::builder()
|
let auth_status_label = gtk::Label::builder()
|
||||||
.label("Authentication Failed!")
|
.label("")
|
||||||
.xalign(0.5)
|
.xalign(0.5)
|
||||||
.yalign(0.5)
|
.yalign(0.5)
|
||||||
.attributes(&attrs)
|
.attributes(&attrs)
|
||||||
.opacity(0.0)
|
.opacity(0.0)
|
||||||
.build();
|
.build();
|
||||||
vbox.pack_start(&auth_failed_label, false, false, 0);
|
vbox.pack_start(&auth_status_label, false, false, 0);
|
||||||
|
|
||||||
rx.attach(None, move |exit_status| {
|
rx.attach(None, clone!(@strong auth_status_label => move |(exit_status, auth_dots_id): (i32, SourceId)| {
|
||||||
|
auth_dots_id.remove();
|
||||||
if exit_status != 0 {
|
if exit_status != 0 {
|
||||||
auth_failed_label.set_opacity(1.0);
|
auth_status_label.set_label("Authentication Failed!");
|
||||||
glib::timeout_add_seconds_local_once(2, move || exit(exit_status));
|
auth_status_label.set_opacity(1.0);
|
||||||
|
glib::timeout_add_seconds_local_once(1, move || exit(exit_status));
|
||||||
} else {
|
} else {
|
||||||
exit(exit_status);
|
exit(exit_status);
|
||||||
}
|
}
|
||||||
glib::Continue(true)
|
glib::Continue(true)
|
||||||
});
|
}));
|
||||||
|
|
||||||
let sep = gtk::Separator::builder()
|
let sep = gtk::Separator::builder()
|
||||||
.orientation(gtk::Orientation::Vertical)
|
.orientation(gtk::Orientation::Vertical)
|
||||||
@ -220,14 +222,14 @@ fn main() -> anyhow::Result<()> {
|
|||||||
label_sg.add_widget(&label);
|
label_sg.add_widget(&label);
|
||||||
hbox.pack_start(&label, false, true, 8);
|
hbox.pack_start(&label, false, true, 8);
|
||||||
|
|
||||||
let password_box = Rc::new(Entry::builder()
|
let password_box = Entry::builder()
|
||||||
.visibility(false)
|
.visibility(false)
|
||||||
.input_purpose(gtk::InputPurpose::Password)
|
.input_purpose(gtk::InputPurpose::Password)
|
||||||
.activates_default(true)
|
.activates_default(true)
|
||||||
.width_chars(25)
|
.width_chars(25)
|
||||||
.build());
|
.build();
|
||||||
entry_sg.add_widget(&*password_box);
|
entry_sg.add_widget(&password_box);
|
||||||
hbox.pack_start(&*password_box, true, true, 8);
|
hbox.pack_start(&password_box, true, true, 8);
|
||||||
password_box.connect_key_press_event(|_, ev| {
|
password_box.connect_key_press_event(|_, ev| {
|
||||||
if ev.keyval().name() == Some(GString::from("Escape")) {
|
if ev.keyval().name() == Some(GString::from("Escape")) {
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -262,25 +264,34 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let unlock_button = Button::builder()
|
let unlock_button = Button::builder()
|
||||||
.label("Unlock")
|
.label("Unlock")
|
||||||
.build();
|
.build();
|
||||||
{
|
unlock_button.connect_clicked(clone!(@strong password_box, @strong auth_status_label => move |unlock_button| {
|
||||||
let password_box = Rc::clone(&password_box);
|
|
||||||
unlock_button.connect_clicked(move |unlock_button| {
|
|
||||||
unlock_button.set_sensitive(false);
|
unlock_button.set_sensitive(false);
|
||||||
password_box.set_sensitive(false);
|
password_box.set_sensitive(false);
|
||||||
|
|
||||||
let username = username.clone();
|
let username = username.clone();
|
||||||
let password = password_box.text().to_string();
|
let password = password_box.text().to_string();
|
||||||
|
|
||||||
|
auth_status_label.set_label("Authenticating");
|
||||||
|
auth_status_label.set_opacity(1.0);
|
||||||
|
let auth_dots_id = glib::timeout_add_local(Duration::from_millis(500), clone!(@strong auth_status_label => move || {
|
||||||
|
let s = auth_status_label.label();
|
||||||
|
auth_status_label.set_label(&(s.as_str().to_string() + "."));
|
||||||
|
Continue(true)
|
||||||
|
}));
|
||||||
|
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let status = if authenticate(&username, &password) { 0 } else { -1 };
|
let status = if authenticate(&username, &password) {
|
||||||
if let Err(err) = tx.send(status) {
|
0
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
};
|
||||||
|
if let Err(err) = tx.send((status, auth_dots_id)) {
|
||||||
error!("Failed to send exit status to main thread: {}", err);
|
error!("Failed to send exit status to main thread: {}", err);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
}
|
|
||||||
hbox.pack_end(&unlock_button, false, true, 8);
|
hbox.pack_end(&unlock_button, false, true, 8);
|
||||||
unlock_button.set_can_default(true);
|
unlock_button.set_can_default(true);
|
||||||
unlock_button.set_has_default(true);
|
unlock_button.set_has_default(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user