1
1
use std:: {
2
2
env,
3
3
fmt:: Display ,
4
- fs:: { self , create_dir , read, read_to_string} ,
4
+ fs:: { self , read, read_to_string} ,
5
5
io,
6
6
path:: { Path , PathBuf } ,
7
7
process:: Command ,
@@ -42,19 +42,23 @@ impl Display for ClientSetupError {
42
42
}
43
43
44
44
pub async fn server ( containers : ContainerList , owner : & str ) -> Result < ( ) , ClientSetupError > {
45
- let home = match env:: var ( "RUNTIME_DIRECTORY" ) {
46
- Ok ( h) => h,
47
- Err ( _) => {
48
- log:: error!( "RUNTIME_DIRECTORY NOT FOUND. Make sure you're using the service!" ) ;
49
- panic ! ( )
50
- }
51
- } ;
45
+ let runtime_dir_str = env:: var ( "RUNTIME_DIRECTORY" ) . unwrap_or ( format ! (
46
+ "/run/user/{}/container-desktop-entries/" ,
47
+ env:: var( "UID" ) . unwrap_or( "1000" . to_string( ) )
48
+ ) ) ;
49
+ let tmp_dir = Path :: new ( & runtime_dir_str) ;
50
+ if !tmp_dir. exists ( ) {
51
+ log:: warn!(
52
+ "tmp_dir {} does not exist! creating directory..." ,
53
+ tmp_dir. to_str( ) . unwrap( )
54
+ ) ;
55
+ fs:: create_dir ( tmp_dir) . unwrap ( ) ;
56
+ }
52
57
let connection = Connection :: session ( ) . await ?;
53
58
let proxy = DesktopEntryProxy :: new ( & connection) . await ?;
54
59
if let Err ( e) = proxy. remove_session_owner ( & owner) . await {
55
60
log:: error!( "could not remove owner container-desktop-entries: {:?}" , e) ;
56
61
}
57
- let to_path = Path :: new ( & home) . join ( Path :: new ( ".cache/container-desktop-entries/" ) ) ;
58
62
for ( container_name, container_type) in containers. containers {
59
63
if container_type. not_supported ( ) {
60
64
log:: error!(
@@ -63,7 +67,7 @@ pub async fn server(containers: ContainerList, owner: &str) -> Result<(), Client
63
67
) ;
64
68
continue ;
65
69
}
66
- if let Err ( kind) = set_up_client ( & container_name, container_type, & to_path , owner) . await {
70
+ if let Err ( kind) = set_up_client ( & container_name, container_type, & tmp_dir , owner) . await {
67
71
log:: error!( "Error setting up client {}: {:?}" , container_name, kind) ;
68
72
}
69
73
}
@@ -78,21 +82,6 @@ async fn set_up_client(
78
82
) -> Result < ( ) , ClientSetupError > {
79
83
// Start client if client is not running
80
84
start_client ( container_name, container_type) ?;
81
- if !to_path. exists ( ) {
82
- log:: warn!(
83
- "Runtime directory {} does not exist! Attempting to create directory manually..." ,
84
- to_path. to_str( ) . unwrap( )
85
- ) ;
86
- match create_dir ( to_path) {
87
- Ok ( _) => {
88
- log:: info!( "App directory created!" ) ;
89
- }
90
- Err ( e) => {
91
- log:: error!( "App directory could not be created. Reason: {}" , e) ;
92
- panic ! ( "App directory could not be created" ) ;
93
- }
94
- }
95
- }
96
85
let _ = fs:: create_dir ( & to_path. join ( "applications" ) ) ;
97
86
let _ = fs:: create_dir ( & to_path. join ( "icons" ) ) ;
98
87
let _ = fs:: create_dir ( & to_path. join ( "pixmaps" ) ) ;
0 commit comments