Add 'New Login' button to unlock dialog
This commit is contained in:
@ -15,4 +15,4 @@ gdk-sys = "0.15"
|
||||
gdkx11 = "0.15"
|
||||
log = "0.4"
|
||||
pam = "0.7"
|
||||
#x11 = "2.19"
|
||||
shell-words = "1"
|
||||
|
@ -3,10 +3,10 @@ use gdkx11::X11Window;
|
||||
use gethostname::gethostname;
|
||||
use glib::GString;
|
||||
use gtk::{prelude::*, Button, Entry, Label, Plug, Window};
|
||||
use log::{debug, error};
|
||||
use std::{io::{self, Write}, process::exit, rc::Rc, thread, time::Duration};
|
||||
use log::{debug, error, warn};
|
||||
use std::{io::{self, Write}, process::{exit, Command}, rc::Rc, thread, time::Duration};
|
||||
|
||||
use bscreensaver_util::init_logging;
|
||||
use bscreensaver_util::{init_logging, load_configuration};
|
||||
|
||||
const DIALOG_UPDATE_INTERVAL: Duration = Duration::from_millis(100);
|
||||
const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
@ -14,6 +14,12 @@ const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
fn main() -> anyhow::Result<()> {
|
||||
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
|
||||
|
||||
let mut new_login_command = load_configuration()?.and_then(|config_toml| {
|
||||
config_toml.get("new-login-command")
|
||||
.and_then(|nlc| nlc.as_str().map(|s| s.to_string()))
|
||||
.map(|nlc| shell_words::split(&nlc))
|
||||
}).transpose()?.filter(|nlc| !nlc.is_empty());
|
||||
|
||||
let standalone = std::env::var("BSCREENSAVER_DIALOG_STANDALONE").is_ok();
|
||||
|
||||
unsafe { glib::log_writer_default_set_use_stderr(true) };
|
||||
@ -208,13 +214,30 @@ fn main() -> anyhow::Result<()> {
|
||||
.build();
|
||||
vbox.pack_start(&hbox, true, true, 2);
|
||||
|
||||
let button = Button::builder()
|
||||
if let Some(new_login_command) = new_login_command.take() {
|
||||
let new_login_button = Button::builder()
|
||||
.label("New Login")
|
||||
.build();
|
||||
new_login_button.connect_clicked(move |_| {
|
||||
let cmd = &new_login_command[0];
|
||||
let empty = Vec::<String>::new();
|
||||
let args = if new_login_command.len() > 1 { &new_login_command[1..] } else { &empty };
|
||||
if let Err(err) = Command::new(cmd).args(args).spawn() {
|
||||
warn!("Failed to run new login command: {}", err);
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
hbox.pack_start(&new_login_button, false, true, 8);
|
||||
}
|
||||
|
||||
let unlock_button = Button::builder()
|
||||
.label("Unlock")
|
||||
.build();
|
||||
{
|
||||
let password_box = Rc::clone(&password_box);
|
||||
button.connect_clicked(move |button| {
|
||||
button.set_sensitive(false);
|
||||
unlock_button.connect_clicked(move |unlock_button| {
|
||||
unlock_button.set_sensitive(false);
|
||||
password_box.set_sensitive(false);
|
||||
|
||||
let username = username.clone();
|
||||
@ -229,9 +252,9 @@ fn main() -> anyhow::Result<()> {
|
||||
});
|
||||
});
|
||||
}
|
||||
hbox.pack_end(&button, false, true, 8);
|
||||
button.set_can_default(true);
|
||||
button.set_has_default(true);
|
||||
hbox.pack_end(&unlock_button, false, true, 8);
|
||||
unlock_button.set_can_default(true);
|
||||
unlock_button.set_has_default(true);
|
||||
|
||||
let timer = Rc::new(gtk::ProgressBar::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
|
Reference in New Issue
Block a user