Added mechanism to skip updates in a module
* This is useful in modules where HTTP API calls are made. Updating them every second is expensive, network intensive and can cause rate limits to be hit * Added get_name() function to modules for easier debug statements
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -2,6 +2,7 @@ use std::str;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use clap::Parser;
|
||||
use crate::common::UpdateResult;
|
||||
|
||||
// Common utilities/types
|
||||
mod common;
|
||||
@@ -17,7 +18,7 @@ mod bar_modules;
|
||||
suitable to use in a status bar")]
|
||||
struct CommandlineArgs {
|
||||
/// Update interval in seconds
|
||||
#[arg(short = 'i', long, default_value = "5")]
|
||||
#[arg(short = 'i', long, default_value = "1")]
|
||||
interval: u64,
|
||||
|
||||
/// Name of the weather station
|
||||
@@ -40,6 +41,11 @@ struct CommandlineArgs {
|
||||
/// but before output is printed
|
||||
#[arg(short = 'M', long)]
|
||||
debug_modules: bool,
|
||||
|
||||
/// Show module debug information after all modules are evaluated
|
||||
/// but before output is printed
|
||||
#[arg(short = 'U', long)]
|
||||
debug_update: bool,
|
||||
}
|
||||
|
||||
//
|
||||
@@ -95,8 +101,17 @@ impl Unibar {
|
||||
//
|
||||
// Following generates ICON+CONTENT string for a module to be displayed
|
||||
// in the bar
|
||||
md.clear();
|
||||
md.generate_data();
|
||||
match md.should_update() {
|
||||
UpdateResult::Update => {
|
||||
md.clear();
|
||||
md.generate_data();
|
||||
}
|
||||
UpdateResult::Skip => {
|
||||
if self.opts.debug_update {
|
||||
println!("Skipping module {}", md.get_name());
|
||||
}
|
||||
}
|
||||
}
|
||||
mod_parts.push(md.get_icon());
|
||||
mod_parts.push(md.get_content());
|
||||
|
||||
@@ -162,6 +177,7 @@ fn main() {
|
||||
music_progress: cmd_args.music_progress,
|
||||
debug: cmd_args.debug,
|
||||
debug_modules: cmd_args.debug_modules,
|
||||
debug_update: cmd_args.debug_update,
|
||||
},
|
||||
bar_modules_enabled: Vec::new(),
|
||||
debug_modules_done: false,
|
||||
|
Reference in New Issue
Block a user