Skip to content

Commit 32401db

Browse files
committed
Fix Unicode truncation and fallback for file creation time
1 parent 75c3a68 commit 32401db

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

apps/desktop/src-tauri/src/tray.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ fn screenshots_path(app: &AppHandle) -> PathBuf {
125125
}
126126

127127
fn truncate_title(title: &str) -> String {
128-
if title.len() <= MAX_TITLE_LENGTH {
128+
if title.chars().count() <= MAX_TITLE_LENGTH {
129129
title.to_string()
130130
} else {
131-
format!("{}…", &title[..MAX_TITLE_LENGTH - 1])
131+
let truncate_at = MAX_TITLE_LENGTH - 1;
132+
let byte_index = title
133+
.char_indices()
134+
.nth(truncate_at)
135+
.map(|(i, _)| i)
136+
.unwrap_or(title.len());
137+
format!("{}…", &title[..byte_index])
132138
}
133139
}
134140

@@ -178,7 +184,7 @@ fn load_single_item(
178184
let created_at = path
179185
.metadata()
180186
.and_then(|m| m.created())
181-
.unwrap_or(std::time::SystemTime::UNIX_EPOCH);
187+
.unwrap_or_else(|_| std::time::SystemTime::now());
182188

183189
let is_screenshot = path.extension().and_then(|s| s.to_str()) == Some("cap")
184190
&& path.parent().map(|p| p == screenshots_dir).unwrap_or(false);

0 commit comments

Comments
 (0)