Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/deep-link-fix-different-exec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"deep-link": patch
"deep-link-js": patch
---

Fix Exec= field in desktop handler if executable path changes
23 changes: 20 additions & 3 deletions plugins/deep-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ mod imp {
.unwrap_or_else(|| bin.into_os_string())
.to_string_lossy()
.to_string();
let qualified_exec = format!("{} %u", exec);

let target = self.app.path().data_dir()?.join("applications");

Expand All @@ -304,12 +305,28 @@ mod imp {

if let Ok(mut desktop_file) = ini::Ini::load_from_file(&target_file) {
if let Some(section) = desktop_file.section_mut(Some("Desktop Entry")) {
// it's ok to remove it - we only write to the file if it's missing
// and in that case we include old_mimes
let old_mimes = section.remove("MimeType").unwrap_or_default();
let mut change = false;

// if the mime type is not present, append it to the list
if !old_mimes.split(';').any(|mime| mime == mime_type) {
section.append("MimeType", format!("{mime_type};{old_mimes}"));
change = true;
} else {
section.insert("MimeType".to_string(), old_mimes);
}

// if the exec command doesnt match, update to the new one
let old_exec = section.remove("Exec").unwrap_or_default();
if old_exec != qualified_exec {
section.append("Exec", qualified_exec);
change = true;
} else {
section.insert("Exec".to_string(), old_exec.to_string());
}

// if any property has changed, rewrite the .desktop file
if change {
desktop_file.write_to_file(&target_file)?;
}
}
Expand All @@ -324,7 +341,7 @@ mod imp {
.product_name
.clone()
.unwrap_or_else(|| file_name.clone()),
exec = exec,
qualified_exec = qualified_exec,
mime_type = mime_type
)
.as_bytes(),
Expand Down
4 changes: 2 additions & 2 deletions plugins/deep-link/src/template.desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Desktop Entry]
Type=Application
Name={name}
Exec={exec} %u
Exec={qualified_exec}
Terminal=false
MimeType={mime_type}
NoDisplay=true
NoDisplay=true
Loading