Skip to content

Commit

Permalink
add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeebar committed Feb 23, 2023
1 parent a3b3854 commit 5b64d7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"])
Expand All @@ -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()),
};
}

0 comments on commit 5b64d7c

Please sign in to comment.