4 Commits

Author SHA1 Message Date
e543c2c9be release: v0.1.2
better logging/error handling
2022-10-20 19:20:54 -07:00
4333ea81a5 setup_greeter: convert unwraps to expects with messages 2022-10-20 19:19:56 -07:00
ce4a58c82b set_username: replace some unwraps with recovery paths + logging
i don't actually know much about this path: an `expect` might make more
sense. i'm just trying to make this more debuggable.
2022-10-20 19:10:25 -07:00
37040526b9 configure a logging backend (env_logger) 2022-10-20 19:07:03 -07:00
3 changed files with 158 additions and 11 deletions

130
Cargo.lock generated
View File

@@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "aho-corasick"
version = "0.7.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "atk" name = "atk"
version = "0.8.0" version = "0.8.0"
@@ -28,6 +37,17 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.2.1" version = "1.2.1"
@@ -65,6 +85,25 @@ version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "env_logger"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.4" version = "0.3.4"
@@ -309,6 +348,21 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@@ -390,14 +444,31 @@ dependencies = [
[[package]] [[package]]
name = "lightdm-mobile-greeter" name = "lightdm-mobile-greeter"
version = "0.1.1" version = "0.1.2"
dependencies = [ dependencies = [
"env_logger",
"gdk", "gdk",
"gtk", "gtk",
"libhandy", "libhandy",
"lightdm", "lightdm",
"log",
] ]
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.3.1" version = "1.3.1"
@@ -473,6 +544,23 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "regex"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.2" version = "0.4.2"
@@ -490,8 +578,48 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -1,15 +1,17 @@
[package] [package]
name = "lightdm-mobile-greeter" name = "lightdm-mobile-greeter"
version = "0.1.1" version = "0.1.2"
authors = ["Raatty <me@raatty.club>", "Colin <colin@uninsane.org>"] authors = ["Raatty <me@raatty.club>", "Colin <colin@uninsane.org>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
libhandy = "0.5.0" env_logger = "0.9"
gdk = "0.12.1" gdk = "0.12.1"
gtk = "0.8.1" gtk = "0.8.1"
libhandy = "0.5.0"
lightdm = { git = "https://git.uninsane.org/colin/lightdm-rs.git"} lightdm = { git = "https://git.uninsane.org/colin/lightdm-rs.git"}
log = "0.4"
[profile.release] [profile.release]
panic = "abort" panic = "abort"

View File

@@ -1,20 +1,31 @@
use env_logger;
use gdk; use gdk;
use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk;
use libhandy; use libhandy;
use lightdm;
use lightdm::{GreeterExt, SessionExt, UserExt, UserListExt}; use lightdm::{GreeterExt, SessionExt, UserExt, UserListExt};
use lightdm;
use log;
use std::cell::RefCell; use std::cell::RefCell;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::*; use std::path::*;
use std::rc::Rc; use std::rc::Rc;
use std::{fs, io}; use std::{fs, io};
fn init_logging() {
let conf = env_logger::Env::new().default_filter_or("INFO");
env_logger::Builder::from_env(conf).init();
log::info!("logging initialized");
}
fn main() { fn main() {
init_logging();
if gtk::init().is_err() { if gtk::init().is_err() {
println!("failed to init GTK"); log::error!("failed to init GTK");
return; return;
} }
libhandy::Keypad::new(true, true); libhandy::Keypad::new(true, true);
let builder = gtk::Builder::new_from_string(include_str!("../interface.ui")); let builder = gtk::Builder::new_from_string(include_str!("../interface.ui"));
let handler = Rc::new(RefCell::new(Handler::new())); let handler = Rc::new(RefCell::new(Handler::new()));
@@ -149,9 +160,15 @@ impl Handler {
fn set_username(&mut self) { fn set_username(&mut self) {
if let Some(user_list) = lightdm::UserList::get_instance() { if let Some(user_list) = lightdm::UserList::get_instance() {
if let Some(name) = user_list.get_users().first().unwrap().get_name() { match user_list.get_users().first() {
let name_str = Box::<str>::from(name); Some(user) => match user.get_name() {
self.user = Some(String::from(name_str)); Some(name) => {
let name_str = Box::<str>::from(name);
self.user = Some(String::from(name_str));
},
None => log::warn!("user.get_name() returned None"),
},
None => log::warn!("user_list.get_users() returned empty"),
}; };
} }
} }
@@ -163,11 +180,11 @@ impl Handler {
let handler_borrowed = handler_auth_clone.borrow(); let handler_borrowed = handler_auth_clone.borrow();
if greeter.get_is_authenticated() { if greeter.get_is_authenticated() {
greeter greeter
.start_session_sync(Some(&handler_borrowed.session.clone().unwrap())) .start_session_sync(Some(&handler_borrowed.session.clone().expect("auth handler.session is None")))
.ok(); .ok();
} else { } else {
greeter greeter
.authenticate(Some(&handler_borrowed.user.clone().unwrap())) .authenticate(Some(&handler_borrowed.user.clone().expect("auth handler.user is None")))
.ok(); .ok();
} }
}); });