@@ -4,7 +4,12 @@ use crate::{
44 Config , Result ,
55} ;
66use base64:: { prelude:: BASE64_STANDARD , Engine } ;
7- use std:: { fmt:: Display , fs:: write} ;
7+ use std:: {
8+ fmt:: Display ,
9+ fs:: { set_permissions, write, Permissions } ,
10+ os:: unix:: fs:: PermissionsExt ,
11+ } ;
12+ use tracing:: debug;
813
914impl PartialEq for App {
1015 fn eq ( & self , other : & Self ) -> bool {
@@ -21,51 +26,57 @@ impl Display for App {
2126impl App {
2227 fn try_as_existing ( & mut self ) -> Result < & mut Self > {
2328 match self . kind . clone ( ) {
24- AppKind :: Detected ( base64) => {
29+ AppKind :: FromBase64 ( base64) => {
2530 let path = icons_dir ( ) ?. join ( format ! ( "{}.png" , self . id) ) ;
2631 write ( path. clone ( ) , BASE64_STANDARD . decode ( base64) ?) ?;
2732
28- self . kind = AppKind :: Existing ( path ) ;
33+ self . kind = AppKind :: Existing ;
2934
3035 Ok ( self )
3136 }
32- AppKind :: Existing ( _ ) => Ok ( self ) ,
37+ AppKind :: Existing => Ok ( self ) ,
3338 }
3439 }
3540
36- fn try_as_desktop_file ( & mut self , exec : String ) -> Result < String > {
41+ fn try_as_desktop_file ( & mut self ) -> Result < String > {
42+ debug ! ( "Writing desktop icon for {}" , self . id) ;
43+
3744 match & self . kind {
38- AppKind :: Detected ( _) => self . try_as_existing ( ) ?. try_as_desktop_file ( exec ) ,
39- AppKind :: Existing ( path ) => Ok ( format ! (
45+ AppKind :: FromBase64 ( _) => self . try_as_existing ( ) ?. try_as_desktop_file ( ) ,
46+ AppKind :: Existing => Ok ( format ! (
4047 "[Desktop Entry]
4148Name={}
42- Exec={exec }
49+ Exec=winapps run { }
4350Terminal=false
4451Type=Application
4552Icon={}
4653StartupWMClass={}
47- Comment={}" ,
54+ Comment={} (WinApps) " ,
4855 self . name,
49- path. to_string_lossy( ) ,
56+ self . id,
57+ icons_dir( ) ?
58+ . join( format!( "{}.png" , self . id) )
59+ . to_string_lossy( ) ,
5060 self . id,
5161 self . name
5262 ) ) ,
5363 }
5464 }
5565
56- pub fn link ( mut self , config : & mut Config , exec : String ) -> Result < ( ) > {
66+ pub fn link ( mut self , config : & mut Config ) -> Result < ( ) > {
5767 self . try_as_existing ( ) ?;
5868
59- write (
60- desktop_dir ( ) ? . join ( format ! ( "{}.desktop" , self . id ) ) ,
61- self . try_as_desktop_file ( exec ) ? ,
62- ) ?;
69+ let path = desktop_dir ( ) ? . join ( format ! ( "{}.desktop" , self . id ) ) ;
70+
71+ write ( & path , self . try_as_desktop_file ( ) ? ) ? ;
72+ set_permissions ( & path , Permissions :: from_mode ( 0o750 ) ) ?;
6373
6474 if !config. linked_apps . contains ( & self ) {
65- config. linked_apps . push ( self )
66- }
75+ debug ! ( "Writing app {} to config" , self . id) ;
6776
68- config. save ( ) ?;
77+ config. linked_apps . push ( self ) ;
78+ config. save ( ) ?;
79+ }
6980
7081 Ok ( ( ) )
7182 }
0 commit comments