From d322017e096dd96247b57fd811ef69db8a8baa00 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 23 Jan 2025 13:02:51 -0700 Subject: [PATCH] Support URL arguments --- res/com.system76.CosmicFiles.desktop | 2 +- src/lib.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/res/com.system76.CosmicFiles.desktop b/res/com.system76.CosmicFiles.desktop index 5d3f0a6..f25060d 100644 --- a/res/com.system76.CosmicFiles.desktop +++ b/res/com.system76.CosmicFiles.desktop @@ -3,7 +3,7 @@ Name=COSMIC Files Name[pl]=Pliki COSMIC Name[pt-BR]=Arquivos do COSMIC -Exec=cosmic-files %F +Exec=cosmic-files %U Terminal=false Type=Application StartupNotify=true diff --git a/src/lib.rs b/src/lib.rs index c6ca345..e0c1e47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,10 +98,21 @@ pub fn main() -> Result<(), Box> { } else if &arg == "--trash" { Location::Trash } else { - match fs::canonicalize(&arg) { + //TODO: support more URLs + let path = match url::Url::parse(&arg) { + Ok(url) => match url.to_file_path() { + Ok(path) => path, + Err(()) => { + log::warn!("invalid argument {:?}", arg); + continue; + } + }, + Err(_) => PathBuf::from(arg), + }; + match fs::canonicalize(&path) { Ok(absolute) => Location::Path(absolute), Err(err) => { - log::warn!("failed to canonicalize {:?}: {}", arg, err); + log::warn!("failed to canonicalize {:?}: {}", path, err); continue; } }