clean up get_desktop_info; increment minor version

This commit is contained in:
raf 2024-08-04 22:04:23 +03:00
parent 482ffe96cd
commit 72d3130aa0
Signed by: NotAShelf
GPG key ID: AF26552424E53993
3 changed files with 8 additions and 15 deletions

2
Cargo.lock generated
View file

@ -105,7 +105,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "microfetch"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"color-eyre",
"nix",

View file

@ -1,6 +1,6 @@
[package]
name = "microfetch"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
[dependencies]

View file

@ -1,26 +1,19 @@
use std::{env, io};
pub fn get_desktop_info() -> Result<String, io::Error> {
let desktop_env = env::var("XDG_CURRENT_DESKTOP").unwrap_or_default();
let display_backend = env::var("XDG_SESSION_TYPE").unwrap_or_default();
let desktop_env = env::var("XDG_CURRENT_DESKTOP");
let display_backend = env::var("XDG_SESSION_TYPE");
// Trim "none+" from the start of desktop_env if present
// XXX: This is a workaround for NixOS modules that set XDG_CURRENT_DESKTOP to "none+foo"
// instead of just "foo"
let desktop_env = desktop_env.trim_start_matches("none+");
// Use "Unknown" if desktop_env or display_backend is empty
let desktop_env = if desktop_env.is_empty() {
"Unknown"
} else {
desktop_env
let desktop_env = match desktop_env {
Err(_) => String::from("Unknown"),
Ok(s) => s.trim_start_matches("none+").to_owned(),
};
let display_backend = if display_backend.is_empty() {
"Unknown"
} else {
&display_backend
};
let display_backend = display_backend.unwrap_or_else(|_| String::from("Unknown"));
Ok(format!("{desktop_env} ({display_backend})"))
}