Skip to content

Commit d4f8299

Browse files
yobson1FabianLars
andauthored
fix(deep-link): handler not set as default on linux (#2844)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
1 parent 341919e commit d4f8299

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

.changes/deep-link-xdg-mime-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"deep-link": patch
3+
"deep-link-js": patch
4+
---
5+
6+
Fix deep link protocol handler not set as default on linux
7+
Fix duplicate protocols added to MimeType section in .desktop files on linux

plugins/deep-link/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,14 @@ mod imp {
303303

304304
if let Ok(mut desktop_file) = ini::Ini::load_from_file(&target_file) {
305305
if let Some(section) = desktop_file.section_mut(Some("Desktop Entry")) {
306-
let old_mimes = section.remove("MimeType");
307-
section.append(
308-
"MimeType",
309-
format!("{mime_type};{}", old_mimes.unwrap_or_default()),
310-
);
311-
desktop_file.write_to_file(&target_file)?;
306+
// it's ok to remove it - we only write to the file if it's missing
307+
// and in that case we include old_mimes
308+
let old_mimes = section.remove("MimeType").unwrap_or_default();
309+
310+
if !old_mimes.split(';').any(|mime| mime == mime_type) {
311+
section.append("MimeType", format!("{mime_type};{old_mimes}"));
312+
desktop_file.write_to_file(&target_file)?;
313+
}
312314
}
313315
} else {
314316
let mut file = File::create(target_file)?;
@@ -333,7 +335,7 @@ mod imp {
333335
.status()?;
334336

335337
Command::new("xdg-mime")
336-
.args(["default", &file_name, _protocol.as_ref()])
338+
.args(["default", &file_name, mime_type.as_str()])
337339
.status()?;
338340

339341
Ok(())

0 commit comments

Comments
 (0)