From 6da89bcf0d066b951dd1a74a867446b5d2ab058f Mon Sep 17 00:00:00 2001 From: Revertron Date: Sun, 9 May 2021 18:44:09 +0200 Subject: [PATCH] Added more convenient cooldown time formatting. --- src/web_ui.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/web_ui.rs b/src/web_ui.rs index 2c14f9b..f70567b 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -423,13 +423,24 @@ fn action_create_domain(context: Arc>, miner: Arc>, let _ = web_view.eval("domainMiningUnavailable();"); } MineResult::Cooldown { time } => { - event_info(web_view, &format!("You have cooldown, just {} more minutes!", time / 60)); - show_warning(web_view, &format!("You have cooldown, just {} more minutes!", time / 60)); + event_info(web_view, &format!("You have cooldown {}!", format_cooldown(time))); + show_warning(web_view, &format!("You have cooldown {}!", format_cooldown(time))); let _ = web_view.eval("domainMiningUnavailable();"); } } } +fn format_cooldown(time: i64) -> String { + if time <= 60 { + return format!("{} seconds", time); + } + let minutes = time / 60; + if minutes <= 60 { + return format!("{} minutes", minutes); + } + format!("{} hours", minutes / 60) +} + fn show_warning(web_view: &mut WebView<()>, text: &str) { let str = text.replace('\'', "\\'"); match web_view.eval(&format!("showWarning('{}');", &str)) {