Move config parsing to util crate

This commit is contained in:
2022-05-04 15:37:28 -07:00
parent 7ef720467f
commit fcb997bfb3
7 changed files with 110 additions and 108 deletions

View File

@ -6,7 +6,7 @@ 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 bscreensaver_util::{init_logging, load_configuration};
use bscreensaver_util::{init_logging, settings::Configuration};
const DIALOG_UPDATE_INTERVAL: Duration = Duration::from_millis(100);
const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
@ -14,21 +14,11 @@ const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
fn main() -> anyhow::Result<()> {
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
let config_tomls = load_configuration()?;
let mut config_tomls_iter = config_tomls.into_iter().rev();
let mut new_login_command: Option<Vec<String>> = loop {
if let Some(config_toml) = config_tomls_iter.next() {
if let Some(nlc) = config_toml.get("new-login-command")
.and_then(|nlc| nlc.as_str().map(|s| s.to_string()))
.map(|nlc| shell_words::split(&nlc))
.transpose()?
{
break Some(nlc);
}
} else {
break None;
}
};
let mut config = Configuration::load()?;
let new_login_command = config.new_login_command
.take()
.map(|nlc| shell_words::split(&nlc))
.transpose()?;
let standalone = std::env::var("BSCREENSAVER_DIALOG_STANDALONE").is_ok();
@ -224,7 +214,7 @@ fn main() -> anyhow::Result<()> {
.build();
vbox.pack_start(&hbox, true, true, 2);
if let Some(new_login_command) = new_login_command.take() {
if let Some(new_login_command) = new_login_command {
let new_login_button = Button::builder()
.label("New Login")
.build();