Support URL arguments

This commit is contained in:
Jeremy Soller 2025-01-23 13:02:51 -07:00
parent 1467351211
commit d322017e09
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
2 changed files with 14 additions and 3 deletions

View file

@ -3,7 +3,7 @@
Name=COSMIC Files Name=COSMIC Files
Name[pl]=Pliki COSMIC Name[pl]=Pliki COSMIC
Name[pt-BR]=Arquivos do COSMIC Name[pt-BR]=Arquivos do COSMIC
Exec=cosmic-files %F Exec=cosmic-files %U
Terminal=false Terminal=false
Type=Application Type=Application
StartupNotify=true StartupNotify=true

View file

@ -98,10 +98,21 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if &arg == "--trash" { } else if &arg == "--trash" {
Location::Trash Location::Trash
} else { } 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), Ok(absolute) => Location::Path(absolute),
Err(err) => { Err(err) => {
log::warn!("failed to canonicalize {:?}: {}", arg, err); log::warn!("failed to canonicalize {:?}: {}", path, err);
continue; continue;
} }
} }