diff --git a/src/domain/entity/workspace.rs b/src/domain/entity/workspace.rs index 077775f..ec874d5 100644 --- a/src/domain/entity/workspace.rs +++ b/src/domain/entity/workspace.rs @@ -81,6 +81,14 @@ impl Workspace { } /// Strip uri prefix of decoded workspace path + #[cfg(target_os = "windows")] + pub fn strip_decode_path(&self) -> String { + let strip_uri_prefix = Regex::new(r"(file|vscode-remote):[/]+").unwrap(); + strip_uri_prefix.replace(&self.decode_path, "").to_string() + } + + /// Strip uri prefix of decoded workspace path + #[cfg(target_os = "linux")] pub fn strip_decode_path(&self) -> String { let strip_uri_prefix = Regex::new(r"(file|vscode-remote):[/][/]").unwrap(); strip_uri_prefix.replace(&self.decode_path, "").to_string() diff --git a/src/domain/searching/parse.rs b/src/domain/searching/parse.rs index 4874821..4b3fc82 100644 --- a/src/domain/searching/parse.rs +++ b/src/domain/searching/parse.rs @@ -55,7 +55,7 @@ impl From<&str> for SearchingStrategy { let tags = tag_re .captures_iter(origin) .map(|x| x.get(0).unwrap().as_str()) - .map(|x| x.to_string().replace(' ', "").replace('#', "")) + .map(|x| x.to_string().replace([' ', '#'], "")) .filter(|x| !x.is_empty()) .collect::>(); diff --git a/src/domain/system/folder_observer.rs b/src/domain/system/folder_observer.rs index 5561655..3885ad1 100644 --- a/src/domain/system/folder_observer.rs +++ b/src/domain/system/folder_observer.rs @@ -14,14 +14,18 @@ pub fn last_modified(workspace: &Workspace) -> Result { let mut entries = result?; entries.sort_by_cached_key(|f| f.metadata().unwrap().modified().unwrap()); - let last_modified_secs = entries[0] - .metadata() - .unwrap() - .modified() - .unwrap() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs(); + let last_modified_secs = if !(entries.is_empty()) { + entries[0] + .metadata() + .unwrap() + .modified() + .unwrap() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() + } else { + 0u64 + }; Ok(Utc .timestamp_opt(last_modified_secs as i64, 0) diff --git a/src/domain/system/scan.rs b/src/domain/system/scan.rs index 9dc8bb7..091e32a 100644 --- a/src/domain/system/scan.rs +++ b/src/domain/system/scan.rs @@ -38,12 +38,9 @@ pub fn scan_workspaces_path() -> Vec { for json_path in current_workspaces_list.unwrap() { let data = extract_json_file(json_path.as_str()); - match data { - Some(val) => { - s.send(Some(Workspace::from(val))) - .expect("Fail to send Workspace struct to main receive channel."); - } - None => {} + if let Some(val) = data { + s.send(Some(Workspace::from(val))) + .expect("Fail to send Workspace struct to main receive channel."); } } });