@@ -122,6 +122,111 @@ pub enum Status {
122
122
Exited ,
123
123
}
124
124
125
+ #[ cfg( feature = "autostart" ) ]
126
+ fn autostart ( autostart_env : & [ ( String , String ) ] ) {
127
+ info ! ( "looking for autostart folders" ) ;
128
+ let mut directories_to_scan = Vec :: new ( ) ;
129
+
130
+ // we start by taking user specific directories, so that we can deduplicate and ensure
131
+ // user overrides are respected
132
+
133
+ // user specific directories
134
+ if let Some ( user_config_dir) = dirs:: config_dir ( ) {
135
+ directories_to_scan. push ( user_config_dir. join ( AUTOSTART_DIR ) ) ;
136
+ }
137
+
138
+ // system-wide directories
139
+ if let Some ( xdg_config_dirs) = env:: var_os ( "XDG_CONFIG_DIRS" ) {
140
+ let xdg_config_dirs = xdg_config_dirs
141
+ . into_string ( )
142
+ . expect ( "Invalid XDG_CONFIG_DIRS" ) ;
143
+ let dir_list = xdg_config_dirs. split ( ":" ) ;
144
+
145
+ for dir in dir_list {
146
+ directories_to_scan. push ( PathBuf :: from ( dir) . join ( AUTOSTART_DIR ) ) ;
147
+ }
148
+ } else {
149
+ directories_to_scan. push ( PathBuf :: from ( "/etc/xdg/" ) . join ( AUTOSTART_DIR ) ) ;
150
+ }
151
+
152
+ info ! ( "found autostart folders: {:?}" , directories_to_scan) ;
153
+
154
+ let mut dedupe = HashSet :: new ( ) ;
155
+
156
+ let iter = freedesktop_desktop_entry:: Iter :: new ( directories_to_scan. into_iter ( ) ) ;
157
+ for entry in iter. entries :: < & str > ( None ) {
158
+ // we've already tried to execute this!
159
+ if dedupe. contains ( & entry. appid ) {
160
+ continue ;
161
+ }
162
+
163
+ // skip if we have an OnlyShowIn entry that doesn't include COSMIC
164
+ if let Some ( only_show_in) = entry. only_show_in ( ) {
165
+ if !only_show_in. contains ( & ENVIRONMENT_NAME ) {
166
+ continue ;
167
+ }
168
+ }
169
+
170
+ // ... OR we have a NotShowIn entry that includes COSMIC
171
+ if let Some ( not_show_in) = entry. not_show_in ( ) {
172
+ if not_show_in. contains ( & ENVIRONMENT_NAME ) {
173
+ continue ;
174
+ }
175
+ }
176
+
177
+ info ! (
178
+ "trying to start appid {} ({})" ,
179
+ entry. appid,
180
+ entry. path. display( )
181
+ ) ;
182
+
183
+ if let Some ( exec_raw) = entry. exec ( ) {
184
+ let mut exec_words = exec_raw. split ( " " ) ;
185
+
186
+ if let Some ( program_name) = exec_words. next ( ) {
187
+ // filter out any placeholder args, since we might not be able to deal with them
188
+ let filtered_args = exec_words. filter ( |s| !s. starts_with ( "%" ) ) . collect_vec ( ) ;
189
+
190
+ // escape them
191
+ let escaped_args = shell_words:: split ( & * filtered_args. join ( " " ) ) ;
192
+ if let Ok ( args) = escaped_args {
193
+ info ! ( "trying to start {} {}" , program_name, args. join( " " ) ) ;
194
+
195
+ let mut command = Command :: new ( program_name) ;
196
+ command. args ( args) ;
197
+
198
+ // add relevant envs
199
+ for ( k, v) in autostart_env {
200
+ command. env ( k, v) ;
201
+ }
202
+
203
+ // detach stdin/out/err (should we?)
204
+ let child = command
205
+ . stdin ( Stdio :: null ( ) )
206
+ . stdout ( Stdio :: null ( ) )
207
+ . stderr ( Stdio :: null ( ) )
208
+ . spawn ( ) ;
209
+
210
+ if let Ok ( child) = child {
211
+ info ! (
212
+ "successfully started program {} {}" ,
213
+ entry. appid,
214
+ child. id( )
215
+ ) ;
216
+ dedupe. insert ( entry. appid ) ;
217
+ } else {
218
+ info ! ( "could not start program {}" , entry. appid) ;
219
+ }
220
+ } else {
221
+ let why = escaped_args. unwrap_err ( ) ;
222
+ error ! ( ?why, "could not parse arguments" ) ;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ info ! ( "started {} programs" , dedupe. len( ) ) ;
228
+ }
229
+
125
230
async fn start (
126
231
session_tx : Sender < SessionRequest > ,
127
232
session_rx : & mut Receiver < SessionRequest > ,
@@ -451,111 +556,12 @@ async fn start(
451
556
. await ;
452
557
}
453
558
454
- #[ cfg( feature = "autostart" ) ]
559
+ #[ cfg( all ( feature = "autostart" , feature = "systemd" ) ) ]
455
560
if !* is_systemd_used ( ) {
456
- info ! ( "looking for autostart folders" ) ;
457
- let mut directories_to_scan = Vec :: new ( ) ;
458
-
459
- // we start by taking user specific directories, so that we can deduplicate and ensure
460
- // user overrides are respected
461
-
462
- // user specific directories
463
- if let Some ( user_config_dir) = dirs:: config_dir ( ) {
464
- directories_to_scan. push ( user_config_dir. join ( AUTOSTART_DIR ) ) ;
465
- }
466
-
467
- // system-wide directories
468
- if let Some ( xdg_config_dirs) = env:: var_os ( "XDG_CONFIG_DIRS" ) {
469
- let xdg_config_dirs = xdg_config_dirs
470
- . into_string ( )
471
- . expect ( "Invalid XDG_CONFIG_DIRS" ) ;
472
- let dir_list = xdg_config_dirs. split ( ":" ) ;
473
-
474
- for dir in dir_list {
475
- directories_to_scan. push ( PathBuf :: from ( dir) . join ( AUTOSTART_DIR ) ) ;
476
- }
477
- } else {
478
- directories_to_scan. push ( PathBuf :: from ( "/etc/xdg/" ) . join ( AUTOSTART_DIR ) ) ;
479
- }
480
-
481
- info ! ( "found autostart folders: {:?}" , directories_to_scan) ;
482
-
483
- let mut dedupe = HashSet :: new ( ) ;
484
-
485
- let iter = freedesktop_desktop_entry:: Iter :: new ( directories_to_scan. into_iter ( ) ) ;
486
- let autostart_env = env_vars. clone ( ) ;
487
- for entry in iter. entries :: < & str > ( None ) {
488
- // we've already tried to execute this!
489
- if dedupe. contains ( & entry. appid ) {
490
- continue ;
491
- }
492
-
493
- // skip if we have an OnlyShowIn entry that doesn't include COSMIC
494
- if let Some ( only_show_in) = entry. only_show_in ( ) {
495
- if !only_show_in. contains ( & ENVIRONMENT_NAME ) {
496
- continue ;
497
- }
498
- }
499
-
500
- // ... OR we have a NotShowIn entry that includes COSMIC
501
- if let Some ( not_show_in) = entry. not_show_in ( ) {
502
- if not_show_in. contains ( & ENVIRONMENT_NAME ) {
503
- continue ;
504
- }
505
- }
506
-
507
- info ! (
508
- "trying to start appid {} ({})" ,
509
- entry. appid,
510
- entry. path. display( )
511
- ) ;
512
-
513
- if let Some ( exec_raw) = entry. exec ( ) {
514
- let mut exec_words = exec_raw. split ( " " ) ;
515
-
516
- if let Some ( program_name) = exec_words. next ( ) {
517
- // filter out any placeholder args, since we might not be able to deal with them
518
- let filtered_args = exec_words. filter ( |s| !s. starts_with ( "%" ) ) . collect_vec ( ) ;
519
-
520
- // escape them
521
- let escaped_args = shell_words:: split ( & * filtered_args. join ( " " ) ) ;
522
- if let Ok ( args) = escaped_args {
523
- info ! ( "trying to start {} {}" , program_name, args. join( " " ) ) ;
524
-
525
- let mut command = Command :: new ( program_name) ;
526
- command. args ( args) ;
527
-
528
- // add relevant envs
529
- for ( k, v) in & autostart_env {
530
- command. env ( k, v) ;
531
- }
532
-
533
- // detach stdin/out/err (should we?)
534
- let child = command
535
- . stdin ( Stdio :: null ( ) )
536
- . stdout ( Stdio :: null ( ) )
537
- . stderr ( Stdio :: null ( ) )
538
- . spawn ( ) ;
539
-
540
- if let Ok ( child) = child {
541
- info ! (
542
- "successfully started program {} {}" ,
543
- entry. appid,
544
- child. id( )
545
- ) ;
546
- dedupe. insert ( entry. appid ) ;
547
- } else {
548
- info ! ( "could not start program {}" , entry. appid) ;
549
- }
550
- } else {
551
- let why = escaped_args. unwrap_err ( ) ;
552
- error ! ( ?why, "could not parse arguments" ) ;
553
- }
554
- }
555
- }
556
- }
557
- info ! ( "started {} programs" , dedupe. len( ) ) ;
561
+ autostart ( & env_vars) ;
558
562
}
563
+ #[ cfg( all( feature = "autostart" , not( feature = "systemd" ) ) ) ]
564
+ autostart ( & env_vars) ;
559
565
560
566
let mut signals = Signals :: new ( vec ! [ libc:: SIGTERM , libc:: SIGINT ] ) . unwrap ( ) ;
561
567
let mut status = Status :: Exited ;
0 commit comments