@@ -284,6 +284,7 @@ enum Message {
284
284
GpuUpdate ( Option < Vec < Gpu > > ) ,
285
285
PinToAppTray ( usize ) ,
286
286
UnPinFromAppTray ( usize ) ,
287
+ DesktopShortcut ( usize ) ,
287
288
AppListConfig ( AppListConfig ) ,
288
289
}
289
290
@@ -730,6 +731,20 @@ impl cosmic::Application for CosmicAppLibrary {
730
731
. remove_pinned ( & pinned_id, & app_list_helper) ;
731
732
}
732
733
}
734
+ Message :: DesktopShortcut ( i) => {
735
+ if let Some ( entry) = self . entry_path_input . get ( i) {
736
+ let entry = Arc :: clone ( entry) ;
737
+ return Command :: perform (
738
+ async move {
739
+ if let Err ( e) = desktop_shortcut ( entry) . await {
740
+ error ! ( "Failed copying desktop entry to desktop: {e:?}" ) ;
741
+ }
742
+ cosmic:: app:: Message :: None
743
+ } ,
744
+ |x| x,
745
+ ) ;
746
+ }
747
+ }
733
748
Message :: AppListConfig ( config) => {
734
749
self . app_list_config = config;
735
750
}
@@ -821,6 +836,14 @@ impl cosmic::Application for CosmicAppLibrary {
821
836
}
822
837
}
823
838
839
+ // Desktop shortcut
840
+ list_column. push ( menu_divider ( spacing) . into ( ) ) ;
841
+ list_column. push (
842
+ menu_button ( body ( fl ! ( "add-desktop-shortcut" ) ) )
843
+ . on_press ( Message :: DesktopShortcut ( * i) )
844
+ . into ( ) ,
845
+ ) ;
846
+
824
847
// add to pinned
825
848
let spacing_xxs = cosmic. spacing . space_xxs ;
826
849
let svg_accent = Rc :: new ( |theme : & cosmic:: Theme | {
@@ -846,7 +869,6 @@ impl cosmic::Application for CosmicAppLibrary {
846
869
} else {
847
870
Message :: PinToAppTray ( * i)
848
871
} ) ;
849
- list_column. push ( menu_divider ( spacing) . into ( ) ) ;
850
872
list_column. push ( pin_to_app_tray. into ( ) ) ;
851
873
852
874
if self . cur_group > 0 {
@@ -1437,3 +1459,15 @@ fn menu_divider<'a>(spacing: &Spacing) -> Container<'a, Message, cosmic::Theme,
1437
1459
. padding ( [ spacing. space_none , spacing. space_xxs ] )
1438
1460
. width ( Length :: Fill )
1439
1461
}
1462
+
1463
+ /// Copy application desktop entry to the user's desktop
1464
+ async fn desktop_shortcut ( entry : Arc < DesktopEntryData > ) -> tokio:: io:: Result < u64 > {
1465
+ let source = entry
1466
+ . path
1467
+ . as_deref ( )
1468
+ . ok_or ( tokio:: io:: Error :: other ( "Desktop entry doesn't have a path" ) ) ?;
1469
+ let dest = dirs:: desktop_dir ( )
1470
+ . ok_or ( tokio:: io:: Error :: other ( "User doesn't have a desktop dir" ) ) ?
1471
+ . join ( format ! ( "{}.desktop" , & * entry. name) ) ;
1472
+ tokio:: fs:: copy ( source, dest) . await
1473
+ }
0 commit comments