Make the new login button stuff more automatic

By default it'll look at your environment to try to figure out which
display manager is used in order to start a new session.  We first try
the org.freedesktop.DisplayManager dbus interface, and if that fails,
inspect XDG_SESSION_DESKTOP to try to figure out which display manager
is running.

The user can also still specify the correct display manager, or a custom
command.
This commit is contained in:
2022-05-15 20:50:45 -07:00
parent 99ffa88657
commit dda1a53856
8 changed files with 287 additions and 36 deletions

View File

@ -4,9 +4,9 @@ use gethostname::gethostname;
use glib::GString;
use gtk::{prelude::*, Button, Entry, Label, Plug, Window};
use log::{debug, error, warn};
use std::{io::{self, Write}, process::{exit, Command}, rc::Rc, thread, time::Duration};
use std::{io::{self, Write}, process::exit, rc::Rc, thread, time::Duration};
use bscreensaver_util::{init_logging, settings::Configuration};
use bscreensaver_util::{init_logging, settings::Configuration, desktop::NewLoginCommand};
const DIALOG_UPDATE_INTERVAL: Duration = Duration::from_millis(100);
const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
@ -15,11 +15,13 @@ fn main() -> anyhow::Result<()> {
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
glib::log_set_default_handler(glib::rust_log_handler);
let mut config = Configuration::load()?;
let new_login_command = config.new_login_command
.take()
.map(|nlc| shell_words::split(&nlc))
.transpose()?;
let config = Configuration::load()?;
let new_login_command =
if config.new_login_command == NewLoginCommand::Disabled {
None
} else {
Some(config.new_login_command.clone())
};
let standalone = std::env::var("BSCREENSAVER_DIALOG_STANDALONE").is_ok();
@ -245,14 +247,14 @@ fn main() -> anyhow::Result<()> {
.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);
}
let new_login_command = new_login_command.clone();
thread::spawn(move || {
if let Err(err) = new_login_command.run() {
warn!("Failed to run new login command: {}", err);
} else {
exit(1);
}
});
});
hbox.pack_start(&new_login_button, false, true, 8);
}