mimick/
watch_path_display.rs1use std::path::Path;
8
9pub fn display_watch_path(path: &str) -> String {
11 if is_document_portal_path(path) {
12 Path::new(path)
13 .file_name()
14 .and_then(|name| name.to_str())
15 .filter(|name| !name.is_empty())
16 .map(|name| name.to_string())
17 .unwrap_or_else(|| "Selected Folder".to_string())
18 } else {
19 path.to_string()
20 }
21}
22
23pub fn watch_path_subtitle(_path: &str) -> Option<&'static str> {
25 None
26}
27
28pub fn display_watch_path_inline(path: &str) -> String {
31 display_watch_path(path)
32}
33
34pub fn is_document_portal_path(path: &str) -> bool {
36 path.starts_with("/run/user/") && path.contains("/doc/")
37}
38
39#[cfg(test)]
40mod tests {
41 use super::{display_watch_path, is_document_portal_path};
42
43 #[test]
44 fn test_display_watch_path_for_portal_folder() {
45 assert_eq!(
46 display_watch_path("/run/user/1000/doc/abcd1234/Screenshots"),
47 "Screenshots"
48 );
49 }
50
51 #[test]
52 fn test_display_watch_path_for_regular_folder() {
53 assert_eq!(
54 display_watch_path("/home/user/Pictures"),
55 "/home/user/Pictures"
56 );
57 assert!(!is_document_portal_path("/home/user/Pictures"));
58 }
59}