~goorzhel/radm

7354b52b8dce1f5a22d6ba59b44dfc5dcce203a8 — Antonio Gurgel 3 months ago b6f7f05
Document more functions
3 files changed, 7 insertions(+), 3 deletions(-)

M src/cli.rs
M src/session.rs
M src/user.rs
M src/cli.rs => src/cli.rs +1 -0
@@ 92,6 92,7 @@ impl Options {
            return Ok(None);
        }
        match Group::from_name(self.autologin_group.as_ref().unwrap())? {
            // unwrap: autologin_group has just been proven to be Some.
            Some(g) => Ok(Some(g.gid)),
            None => return Err(anyhow!("Autologin group doesn't exist")),
        }

M src/session.rs => src/session.rs +5 -3
@@ 17,6 17,7 @@ use xdg::BaseDirectories;

use crate::tui::{prompt, EchoInput};

/// Converts a `Result<T, E>` to an `Option<T>`, and logs `E` if existent.
fn log_if_err<T, E: Display>(result: Result<T, E>, msg: String) -> Option<T> {
    match result {
        Ok(v) => Some(v),


@@ 143,14 144,15 @@ pub fn choose_session(sessions: &[Desktop], xdg: &BaseDirectories) -> Result<Des
    }
}

/// Writes the name of the chosen session to `$XDG_CACHE_HOME/radm-last`.
fn cache_session(xdg: &BaseDirectories, session: &Desktop) -> Result<()> {
    let mut path = xdg.get_cache_home();
    path.push("radm-last");
    let mut cache = xdg.get_cache_home();
    cache.push("radm-last");
    let mut file = OpenOptions::new()
        .write(true)
        .create(true)
        .truncate(true)
        .open(&path)
        .open(&cache)
        .context("Couldn't open cache for writing")?;
    file.write_all(session.name.as_bytes())
        .context("Couldn't write to cache")?;

M src/user.rs => src/user.rs +1 -0
@@ 46,6 46,7 @@ impl FromStr for User {
    }
}

/// Environment variables to load from the authenticated user's environment.
const USEFUL_ENV_VARS: &[&str] = &["XDG_RUNTIME_DIR", "XDG_CACHE_HOME", "XDG_STATE_HOME"];

// Many of these function take `xdg: &BaseDirectories` as an argument because