Skip to content

Commit 4d3f653

Browse files
committed
Truncate target name in project filename formatting
1 parent d0f5aae commit 4d3f653

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,22 @@ pub fn format_project_name<'a>(
376376
datetime: Option<chrono::DateTime<chrono::Local>>,
377377
) -> String {
378378
const DEFAULT_FILENAME_TEMPLATE: &str = "{target_name} ({target_kind}) {date} {time}";
379+
const MAX_TARGET_NAME_CHARS: usize = 180;
379380
let datetime = datetime.unwrap_or(chrono::Local::now());
380381

382+
let truncated_target_name: std::borrow::Cow<'_, str> =
383+
if target_name.chars().count() > MAX_TARGET_NAME_CHARS {
384+
std::borrow::Cow::Owned(
385+
target_name
386+
.chars()
387+
.take(MAX_TARGET_NAME_CHARS)
388+
.collect::<String>()
389+
+ "...",
390+
)
391+
} else {
392+
std::borrow::Cow::Borrowed(target_name)
393+
};
394+
381395
lazy_static! {
382396
static ref DATE_REGEX: Regex = Regex::new(r"\{date(?::([^}]+))?\}").unwrap();
383397
static ref TIME_REGEX: Regex = Regex::new(r"\{time(?::([^}]+))?\}").unwrap();
@@ -402,7 +416,7 @@ pub fn format_project_name<'a>(
402416
};
403417

404418
let result = AC
405-
.try_replace_all(haystack, &[recording_mode, mode, target_kind, target_name])
419+
.try_replace_all(haystack, &[recording_mode, mode, target_kind, &truncated_target_name])
406420
.expect("AhoCorasick replace should never fail with default configuration");
407421

408422
let result = DATE_REGEX.replace_all(&result, |caps: &regex::Captures| {

0 commit comments

Comments
 (0)