diff --git a/Cargo.lock b/Cargo.lock index 861e35f..f8079b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "waybar-module-pacman-updates" -version = "0.1.0" +version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 36e0baa..ec48987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "waybar-module-pacman-updates" description = "waybar module for Arch to show system updates available" -version = "0.2.0" +version = "0.2.1" edition = "2021" exclude = ["target", "Cargo.lock", "screenshot.png"] readme = "README.md" diff --git a/README.md b/README.md index b8f7570..ff0d267 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ - This module will provide relevant local information constantly and periodically update data from the network in backgroud. Direct "checkupdates" will only give you one of two things: updating the information with a long delay or having the module constantly active on the network. - This module has 2 states which gives you the ability to display different icons depending on status. - Waybar expects JSON in an infinite loop from modules. So we have this. +- See updates list in tooltip. This small program will give you fast updates with less network usage. After you have installed all the updates, the module will immediately go into the Updated state. You don't need to send signals to waybar to update this module state. diff --git a/screenshot.png b/screenshot.png index da36358..b52ef9e 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/main.rs b/src/main.rs index 5086e9b..73eaa0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,11 +16,12 @@ fn main() -> Result<(), Error> { sync_database(); iter = 0; } - let updates = get_updates_count(); + let (updates, stdout) = get_updates(); if updates > 0 { - println!("{{\"text\": \"{}\", \"class\": \"has-updates\", \"alt\": \"has-updates\"}}", updates); + let tooltip = stdout.trim_end().replace("\"", "\\\"").replace("\n", "\\n"); + println!( "{{\"text\": \"{}\",\"tooltip\":\"{}\",\"class\":\"has-updates\",\"alt\":\"has-updates\"}}", updates, tooltip); } else { - println!("{{\"text\": \"\", \"class\": \"updated\", \"alt\": \"updated\"}}",); + println!("{{\"text\":\"\",\"tooltip\":\"System updated\",\"class\": \"updated\",\"alt\":\"updated\"}}",); } iter += 1; std::thread::sleep(SLEEP_DURATION); @@ -36,8 +37,8 @@ fn sync_database() { .expect("failed to execute process"); } -// get updates count without network operations -fn get_updates_count() -> u16 { +// get updates info without network operations +fn get_updates() -> (u16, String) { // checkupdates --nosync --nocolor let output = Command::new("checkupdates") .args(["--nosync", "--nocolor"]) @@ -47,10 +48,10 @@ fn get_updates_count() -> u16 { Some(_code) => { let stdout = String::from_utf8_lossy(&output.stdout).to_string(); if stdout == "" { - return 0; + return (0, "".to_string()); } - (stdout.split(" -> ").count() as u16) - 1 + return ((stdout.split(" -> ").count() as u16) - 1, stdout); } - None => 0, + None => (0, "".to_string()), }; }