Try to open with mime apps before trying xdg-open
This commit is contained in:
parent
c3a189aa28
commit
3767a61f2a
1 changed files with 28 additions and 6 deletions
34
src/app.rs
34
src/app.rs
|
|
@ -528,15 +528,15 @@ pub struct App {
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn open_file(&mut self, path: &PathBuf) {
|
fn open_file(&mut self, path: &PathBuf) {
|
||||||
let mut found_desktop_exec = false;
|
|
||||||
let mime = mime_icon::mime_for_path(path);
|
let mime = mime_icon::mime_for_path(path);
|
||||||
if mime == "application/x-desktop" {
|
if mime == "application/x-desktop" {
|
||||||
|
// Try opening desktop application
|
||||||
match freedesktop_entry_parser::parse_entry(path) {
|
match freedesktop_entry_parser::parse_entry(path) {
|
||||||
Ok(entry) => match entry.section("Desktop Entry").attr("Exec") {
|
Ok(entry) => match entry.section("Desktop Entry").attr("Exec") {
|
||||||
Some(exec) => match mime_app::exec_to_command(exec, None) {
|
Some(exec) => match mime_app::exec_to_command(exec, None) {
|
||||||
Some(mut command) => match spawn_detached(&mut command) {
|
Some(mut command) => match spawn_detached(&mut command) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
found_desktop_exec = true;
|
return;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("failed to execute {:?}: {}", path, err);
|
log::warn!("failed to execute {:?}: {}", path, err);
|
||||||
|
|
@ -555,6 +555,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if mime == "application/x-executable" || mime == "application/vnd.appimage" {
|
} else if mime == "application/x-executable" || mime == "application/vnd.appimage" {
|
||||||
|
// Try opening executable
|
||||||
let mut command = std::process::Command::new(path);
|
let mut command = std::process::Command::new(path);
|
||||||
match spawn_detached(&mut command) {
|
match spawn_detached(&mut command) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
|
|
@ -571,10 +572,15 @@ impl App {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
found_desktop_exec = true;
|
return;
|
||||||
}
|
}
|
||||||
if !found_desktop_exec {
|
|
||||||
match open::that_detached(path) {
|
// Try mime apps, which should be faster than xdg-open
|
||||||
|
for app in mime_app::mime_apps(&mime) {
|
||||||
|
let Some(mut command) = app.command(Some(path.clone().into())) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
match spawn_detached(&mut command) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let _ = recently_used_xbel::update_recently_used(
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
path,
|
path,
|
||||||
|
|
@ -582,12 +588,28 @@ impl App {
|
||||||
"cosmic-files".to_string(),
|
"cosmic-files".to_string(),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("failed to open {:?}: {}", path, err);
|
log::warn!("failed to open {:?} with {:?}: {}", path, app.id, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fall back to using open crate
|
||||||
|
match open::that_detached(path) {
|
||||||
|
Ok(()) => {
|
||||||
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
|
path,
|
||||||
|
App::APP_ID.to_string(),
|
||||||
|
"cosmic-files".to_string(),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::warn!("failed to open {:?}: {}", path, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_tab_entity(
|
fn open_tab_entity(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue