mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-22 15:40:41 +00:00
clean up get_desktop_info; increment minor version
This commit is contained in:
parent
482ffe96cd
commit
72d3130aa0
3 changed files with 8 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -105,7 +105,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|||
|
||||
[[package]]
|
||||
name = "microfetch"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"nix",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "microfetch"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -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})"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue