From d4f8299b12f107718c70692840a63768d65baaf9 Mon Sep 17 00:00:00 2001 From: yobson1 <45133474+yobson1@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:54:12 +0100 Subject: [PATCH] fix(deep-link): handler not set as default on linux (#2844) Co-authored-by: Fabian-Lars --- .changes/deep-link-xdg-mime-fix.md | 7 +++++++ plugins/deep-link/src/lib.rs | 16 +++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 .changes/deep-link-xdg-mime-fix.md diff --git a/.changes/deep-link-xdg-mime-fix.md b/.changes/deep-link-xdg-mime-fix.md new file mode 100644 index 00000000..6b25d4ea --- /dev/null +++ b/.changes/deep-link-xdg-mime-fix.md @@ -0,0 +1,7 @@ +--- +"deep-link": patch +"deep-link-js": patch +--- + +Fix deep link protocol handler not set as default on linux +Fix duplicate protocols added to MimeType section in .desktop files on linux diff --git a/plugins/deep-link/src/lib.rs b/plugins/deep-link/src/lib.rs index d74864db..1cd13b58 100644 --- a/plugins/deep-link/src/lib.rs +++ b/plugins/deep-link/src/lib.rs @@ -303,12 +303,14 @@ 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")) { - let old_mimes = section.remove("MimeType"); - section.append( - "MimeType", - format!("{mime_type};{}", old_mimes.unwrap_or_default()), - ); - desktop_file.write_to_file(&target_file)?; + // 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(); + + if !old_mimes.split(';').any(|mime| mime == mime_type) { + section.append("MimeType", format!("{mime_type};{old_mimes}")); + desktop_file.write_to_file(&target_file)?; + } } } else { let mut file = File::create(target_file)?; @@ -333,7 +335,7 @@ mod imp { .status()?; Command::new("xdg-mime") - .args(["default", &file_name, _protocol.as_ref()]) + .args(["default", &file_name, mime_type.as_str()]) .status()?; Ok(())