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]]
|
[[package]]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"nix",
|
"nix",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,26 +1,19 @@
|
||||||
use std::{env, io};
|
use std::{env, io};
|
||||||
|
|
||||||
pub fn get_desktop_info() -> Result<String, io::Error> {
|
pub fn get_desktop_info() -> Result<String, io::Error> {
|
||||||
let desktop_env = env::var("XDG_CURRENT_DESKTOP").unwrap_or_default();
|
let desktop_env = env::var("XDG_CURRENT_DESKTOP");
|
||||||
let display_backend = env::var("XDG_SESSION_TYPE").unwrap_or_default();
|
let display_backend = env::var("XDG_SESSION_TYPE");
|
||||||
|
|
||||||
// Trim "none+" from the start of desktop_env if present
|
// 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"
|
// XXX: This is a workaround for NixOS modules that set XDG_CURRENT_DESKTOP to "none+foo"
|
||||||
// instead of just "foo"
|
// instead of just "foo"
|
||||||
let desktop_env = desktop_env.trim_start_matches("none+");
|
|
||||||
|
|
||||||
// Use "Unknown" if desktop_env or display_backend is empty
|
// Use "Unknown" if desktop_env or display_backend is empty
|
||||||
let desktop_env = if desktop_env.is_empty() {
|
let desktop_env = match desktop_env {
|
||||||
"Unknown"
|
Err(_) => String::from("Unknown"),
|
||||||
} else {
|
Ok(s) => s.trim_start_matches("none+").to_owned(),
|
||||||
desktop_env
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let display_backend = if display_backend.is_empty() {
|
let display_backend = display_backend.unwrap_or_else(|_| String::from("Unknown"));
|
||||||
"Unknown"
|
|
||||||
} else {
|
|
||||||
&display_backend
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(format!("{desktop_env} ({display_backend})"))
|
Ok(format!("{desktop_env} ({display_backend})"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue