@@ -312,6 +312,7 @@ enum Message {
312
312
GpuUpdate ( Option < Vec < Gpu > > ) ,
313
313
PinToAppTray ( usize ) ,
314
314
UnPinFromAppTray ( usize ) ,
315
+ DesktopShortcut ( usize ) ,
315
316
AppListConfig ( AppListConfig ) ,
316
317
}
317
318
@@ -760,6 +761,20 @@ impl cosmic::Application for CosmicAppLibrary {
760
761
. remove_pinned ( & pinned_id, & app_list_helper) ;
761
762
}
762
763
}
764
+ Message :: DesktopShortcut ( i) => {
765
+ if let Some ( entry) = self . entry_path_input . get ( i) {
766
+ let entry = Arc :: clone ( entry) ;
767
+ return Task :: perform (
768
+ async move {
769
+ if let Err ( e) = desktop_shortcut ( entry) . await {
770
+ error ! ( "Failed copying desktop entry to desktop: {e:?}" ) ;
771
+ }
772
+ cosmic:: app:: Message :: None
773
+ } ,
774
+ |x| x,
775
+ ) ;
776
+ }
777
+ }
763
778
Message :: AppListConfig ( config) => {
764
779
self . app_list_config = config;
765
780
}
@@ -847,6 +862,14 @@ impl cosmic::Application for CosmicAppLibrary {
847
862
}
848
863
}
849
864
865
+ // Desktop shortcut
866
+ list_column. push ( divider:: horizontal:: light ( ) . into ( ) ) ;
867
+ list_column. push (
868
+ menu_button ( body ( fl ! ( "add-desktop-shortcut" ) ) )
869
+ . on_press ( Message :: DesktopShortcut ( * i) )
870
+ . into ( ) ,
871
+ ) ;
872
+
850
873
// add to pinned
851
874
let svg_accent = Rc :: new ( |theme : & cosmic:: Theme | {
852
875
let color = theme. cosmic ( ) . accent_color ( ) . into ( ) ;
@@ -870,7 +893,6 @@ impl cosmic::Application for CosmicAppLibrary {
870
893
} else {
871
894
Message :: PinToAppTray ( * i)
872
895
} ) ;
873
- list_column. push ( divider:: horizontal:: light ( ) . into ( ) ) ;
874
896
list_column. push ( pin_to_app_tray. into ( ) ) ;
875
897
876
898
if self . cur_group > 0 {
@@ -1448,3 +1470,15 @@ impl cosmic::Application for CosmicAppLibrary {
1448
1470
( self_, Task :: none ( ) )
1449
1471
}
1450
1472
}
1473
+
1474
+ /// Copy application desktop entry to the user's desktop
1475
+ async fn desktop_shortcut ( entry : Arc < DesktopEntryData > ) -> tokio:: io:: Result < u64 > {
1476
+ let source = entry
1477
+ . path
1478
+ . as_deref ( )
1479
+ . ok_or ( tokio:: io:: Error :: other ( "Desktop entry doesn't have a path" ) ) ?;
1480
+ let dest = dirs:: desktop_dir ( )
1481
+ . ok_or ( tokio:: io:: Error :: other ( "User doesn't have a desktop dir" ) ) ?
1482
+ . join ( format ! ( "{}.desktop" , & * entry. name) ) ;
1483
+ tokio:: fs:: copy ( source, dest) . await
1484
+ }
0 commit comments