Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Once running, it will appear in your taskbar and as one or more tray icons in th
- Right-click the taskbar widget or tray icon for refresh, displayed models, update frequency, Start with Windows, reset position, language, updates, and exit
- Left-click the tray icon to toggle the taskbar widget on or off
- Enable `Start with Windows` from the right-click menu if you want it to launch automatically when you sign in
- Enable `Show detailed remaining time` under right-click `Settings` to add minutes alongside hours (5h window) and hours alongside days (7d window)

### Models

Expand Down
1 change: 1 addition & 0 deletions src/localization/dutch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "Instellingen",
start_with_windows: "Opstarten met Windows",
reset_position: "Positie herstellen",
show_detailed_remaining: "Gedetailleerde resterende tijd tonen",
language: "Taal",
system_default: "Systeemstandaard",
check_for_updates: "Controleren op updates",
Expand Down
1 change: 1 addition & 0 deletions src/localization/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "Settings",
start_with_windows: "Start with Windows",
reset_position: "Reset Position",
show_detailed_remaining: "Show detailed remaining time",
language: "Language",
system_default: "System Default",
check_for_updates: "Check for Updates",
Expand Down
1 change: 1 addition & 0 deletions src/localization/french.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "Paramètres",
start_with_windows: "Démarrer avec Windows",
reset_position: "Réinitialiser la position",
show_detailed_remaining: "Afficher le temps restant détaillé",
language: "Langue",
system_default: "Par défaut du système",
check_for_updates: "Vérifier les mises à jour",
Expand Down
1 change: 1 addition & 0 deletions src/localization/german.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "Einstellungen",
start_with_windows: "Mit Windows starten",
reset_position: "Position zurücksetzen",
show_detailed_remaining: "Detaillierte Restzeit anzeigen",
language: "Sprache",
system_default: "Systemstandard",
check_for_updates: "Nach Updates suchen",
Expand Down
1 change: 1 addition & 0 deletions src/localization/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "設定",
start_with_windows: "Windows と同時に開始",
reset_position: "位置をリセット",
show_detailed_remaining: "残り時間を詳細表示",
language: "言語",
system_default: "システム既定",
check_for_updates: "更新を確認",
Expand Down
1 change: 1 addition & 0 deletions src/localization/korean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "설정",
start_with_windows: "Windows 시작 시 자동 실행",
reset_position: "위치 초기화",
show_detailed_remaining: "남은 시간 상세 표시",
language: "언어",
system_default: "시스템 기본값",
check_for_updates: "업데이트 확인",
Expand Down
1 change: 1 addition & 0 deletions src/localization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub struct Strings {
pub settings: &'static str,
pub start_with_windows: &'static str,
pub reset_position: &'static str,
pub show_detailed_remaining: &'static str,
pub language: &'static str,
pub system_default: &'static str,
pub check_for_updates: &'static str,
Expand Down
1 change: 1 addition & 0 deletions src/localization/spanish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "Configuración",
start_with_windows: "Iniciar con Windows",
reset_position: "Restablecer posición",
show_detailed_remaining: "Mostrar tiempo restante detallado",
language: "Idioma",
system_default: "Predeterminado del sistema",
check_for_updates: "Buscar actualizaciones",
Expand Down
1 change: 1 addition & 0 deletions src/localization/traditional_chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) const STRINGS: Strings = Strings {
settings: "設定",
start_with_windows: "開機時啟動",
reset_position: "重置位置",
show_detailed_remaining: "顯示詳細剩餘時間",
language: "語言",
system_default: "系統預設",
check_for_updates: "檢查更新",
Expand Down
54 changes: 42 additions & 12 deletions src/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,17 +1021,17 @@ fn is_leap(y: u64) -> bool {
}

/// Format a usage section as "X% · Yh" style text
pub fn format_line(section: &UsageSection, strings: Strings) -> String {
pub fn format_line(section: &UsageSection, strings: Strings, detailed: bool) -> String {
let pct = format!("{:.0}%", section.percentage);
let cd = format_countdown(section.resets_at, strings);
let cd = format_countdown(section.resets_at, strings, detailed);
if cd.is_empty() {
pct
} else {
format!("{pct} \u{00b7} {cd}")
}
}

fn format_countdown(resets_at: Option<SystemTime>, strings: Strings) -> String {
fn format_countdown(resets_at: Option<SystemTime>, strings: Strings, detailed: bool) -> String {
let reset = match resets_at {
Some(t) => t,
None => return String::new(),
Expand All @@ -1042,41 +1042,71 @@ fn format_countdown(resets_at: Option<SystemTime>, strings: Strings) -> String {
Err(_) => return strings.now.to_string(),
};

format_countdown_from_secs(remaining.as_secs(), strings)
format_countdown_from_secs(remaining.as_secs(), strings, detailed)
}

/// Calculate how long until the display text would change
pub fn time_until_display_change(resets_at: Option<SystemTime>) -> Option<Duration> {
pub fn time_until_display_change(
resets_at: Option<SystemTime>,
detailed: bool,
) -> Option<Duration> {
let reset = resets_at?;
let remaining = reset.duration_since(SystemTime::now()).ok()?;
Some(time_until_display_change_from_secs(remaining.as_secs()))
Some(time_until_display_change_from_secs(
remaining.as_secs(),
detailed,
))
}

fn format_countdown_from_secs(total_secs: u64, strings: Strings) -> String {
fn format_countdown_from_secs(total_secs: u64, strings: Strings, detailed: bool) -> String {
let total_mins = total_secs / 60;
let total_hours = total_secs / 3600;
let total_days = total_secs / 86400;

if total_days >= 1 {
format!("{total_days}{}", strings.day_suffix)
if detailed {
let hours = total_hours % 24;
format!(
"{total_days}{} {hours}{}",
strings.day_suffix, strings.hour_suffix
)
} else {
format!("{total_days}{}", strings.day_suffix)
}
} else if total_hours >= 1 {
format!("{total_hours}{}", strings.hour_suffix)
if detailed {
let mins = total_mins % 60;
format!(
"{total_hours}{} {mins}{}",
strings.hour_suffix, strings.minute_suffix
)
} else {
format!("{total_hours}{}", strings.hour_suffix)
}
} else if total_mins >= 1 {
format!("{total_mins}{}", strings.minute_suffix)
} else {
format!("{total_secs}{}", strings.second_suffix)
}
}

fn time_until_display_change_from_secs(total_secs: u64) -> Duration {
fn time_until_display_change_from_secs(total_secs: u64, detailed: bool) -> Duration {
let total_mins = total_secs / 60;
let total_hours = total_secs / 3600;
let total_days = total_secs / 86400;

let current_bucket_start = if total_days >= 1 {
total_days * 86400
if detailed {
total_hours * 3600
} else {
total_days * 86400
}
} else if total_hours >= 1 {
total_hours * 3600
if detailed {
total_mins * 60
} else {
total_hours * 3600
}
} else if total_mins >= 1 {
total_mins * 60
} else {
Expand Down
Loading