fix(deep-link): duplicate MimeType entries added to .desktop

just check that it isn't already in there before appending it
pull/2844/head
Brad 4 days ago
parent 860175853c
commit 218ec686bb
No known key found for this signature in database
GPG Key ID: A2DE32BF0B799596

@ -4,3 +4,4 @@
--- ---
Fix deep link protocol handler not set as default on linux Fix deep link protocol handler not set as default on linux
Fix duplicate protocols added to MimeType section in .desktop files on linux

@ -303,12 +303,15 @@ mod imp {
if let Ok(mut desktop_file) = ini::Ini::load_from_file(&target_file) { if let Ok(mut desktop_file) = ini::Ini::load_from_file(&target_file) {
if let Some(section) = desktop_file.section_mut(Some("Desktop Entry")) { if let Some(section) = desktop_file.section_mut(Some("Desktop Entry")) {
let old_mimes = section.remove("MimeType"); // it's ok to remove it - we only write to the file if it's missing
section.append( // and in that case we include old_mimes
"MimeType", let old_mimes = section.remove("MimeType").unwrap_or_default();
format!("{mime_type};{}", old_mimes.unwrap_or_default()),
); if !old_mimes.split(';').any(|mime| mime == mime_type) {
desktop_file.write_to_file(&target_file)?; section.remove("MimeType");
section.append("MimeType", format!("{mime_type};{}", old_mimes));
desktop_file.write_to_file(&target_file)?;
}
} }
} else { } else {
let mut file = File::create(target_file)?; let mut file = File::create(target_file)?;

Loading…
Cancel
Save