@@ -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 ( ) ,
0 commit comments