Skip to content

Commit e25a933

Browse files
fix(deep-link): update the Exec= in handler if the executable path changes (#3019)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
1 parent 92f98a9 commit e25a933

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"deep-link": patch
3+
"deep-link-js": patch
4+
---
5+
6+
Fix Exec= field in desktop handler if executable path changes

plugins/deep-link/src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ mod imp {
293293
.unwrap_or_else(|| bin.into_os_string())
294294
.to_string_lossy()
295295
.to_string();
296+
let qualified_exec = format!("{} %u", exec);
296297

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

@@ -304,12 +305,28 @@ mod imp {
304305

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

311+
// if the mime type is not present, append it to the list
311312
if !old_mimes.split(';').any(|mime| mime == mime_type) {
312313
section.append("MimeType", format!("{mime_type};{old_mimes}"));
314+
change = true;
315+
} else {
316+
section.insert("MimeType".to_string(), old_mimes);
317+
}
318+
319+
// if the exec command doesnt match, update to the new one
320+
let old_exec = section.remove("Exec").unwrap_or_default();
321+
if old_exec != qualified_exec {
322+
section.append("Exec", qualified_exec);
323+
change = true;
324+
} else {
325+
section.insert("Exec".to_string(), old_exec.to_string());
326+
}
327+
328+
// if any property has changed, rewrite the .desktop file
329+
if change {
313330
desktop_file.write_to_file(&target_file)?;
314331
}
315332
}
@@ -324,7 +341,7 @@ mod imp {
324341
.product_name
325342
.clone()
326343
.unwrap_or_else(|| file_name.clone()),
327-
exec = exec,
344+
qualified_exec = qualified_exec,
328345
mime_type = mime_type
329346
)
330347
.as_bytes(),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Desktop Entry]
22
Type=Application
33
Name={name}
4-
Exec={exec} %u
4+
Exec={qualified_exec}
55
Terminal=false
66
MimeType={mime_type}
7-
NoDisplay=true
7+
NoDisplay=true

0 commit comments

Comments
 (0)