Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reqwest = { version = "=0.12.24", default-features = false, features = ["json",
serde = { version = "=1.0.219", features = ["derive"] }
serde_json = "=1.0.140"
uuid = { version = "=1.18.1", features = ["v4"] }
tauri = { version = "=2.11.6", features = ["tray-icon", "image-png"] }
tauri = { version = "=2.11.6", features = ["tray-icon", "image-png", "macos-private-api"] }
tauri-utils = "=2.9.3"
tauri-plugin-autostart = "=2.5.0"
tauri-plugin-opener = "=2.5.3"
Expand Down
40 changes: 35 additions & 5 deletions desktop/src-tauri/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ fn abbreviate_float(value: f64, integer: bool) -> String {
2
};
let rendered = format!("{scaled:.decimals$}");
return format!(
"{}{}",
rendered.trim_end_matches('0').trim_end_matches('.'),
suffix
);
let rendered = if rendered.contains('.') {
rendered.trim_end_matches('0').trim_end_matches('.')
} else {
&rendered
};
return format!("{rendered}{suffix}");
}
}
format!("{value:.0}")
Expand All @@ -76,4 +77,33 @@ mod tests {
assert_eq!(cost(Some(12.345)), "$12.35");
assert_eq!(cost(Some(1_234.0)), "$1.23K");
}

#[test]
fn abbreviations_preserve_integer_trailing_zeros() {
for (unit, suffix) in [
(1_000, "K"),
(1_000_000, "M"),
(1_000_000_000, "B"),
(1_000_000_000_000, "T"),
] {
for multiple in [10, 100, 110] {
let value = unit * multiple;
let expected = format!("{multiple}{suffix}");
assert_eq!(tokens(Some(value)), expected);
assert_eq!(count(Some(value)), expected);
assert_eq!(cost(Some(value as f64)), format!("${expected}"));
}
}
assert_eq!(tokens(Some(9_600_000)), "10M");
assert_eq!(count(Some(99_960_000)), "100M");
}

#[test]
fn fractional_trailing_zeros_are_still_trimmed() {
assert_eq!(count(Some(1_000_000)), "1M");
assert_eq!(count(Some(1_200_000)), "1.2M");
assert_eq!(count(Some(1_234_000)), "1.23M");
assert_eq!(count(Some(12_340_000)), "12.3M");
assert_eq!(cost(Some(1_200.0)), "$1.2K");
}
}
3 changes: 3 additions & 0 deletions desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod logging;
#[cfg(target_os = "macos")]
mod menu;
mod ownership;
mod popup;
mod proxy;
mod resolve;
mod runtime_stop;
Expand Down Expand Up @@ -119,6 +120,7 @@ impl Default for AppState {

#[tauri::command]
fn show_dashboard(app: tauri::AppHandle) {
popup::hide(&app);
if let Some(window) = app.get_webview_window("main") {
window::show(&window);
}
Expand Down Expand Up @@ -160,6 +162,7 @@ pub fn run() {
let builder = tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
if let Some(window) = app.get_webview_window("main") {
popup::hide(app);
window::show(&window);
}
}))
Expand Down
Loading
Loading