1
1
use crate :: bluetooth:: { BluerDeviceStatus , BluerRequest , BluerState } ;
2
+ use cosmic:: applet:: token:: subscription:: {
3
+ activation_token_subscription, TokenRequest , TokenUpdate ,
4
+ } ;
5
+ use cosmic:: cctk:: sctk:: reexports:: calloop;
6
+
2
7
use cosmic:: applet:: { menu_button, padded_control} ;
3
8
use cosmic:: Command ;
4
9
use cosmic:: {
@@ -39,6 +44,7 @@ struct CosmicBluetoothApplet {
39
44
// UI state
40
45
show_visible_devices : bool ,
41
46
request_confirmation : Option < ( BluerDevice , String , Sender < bool > ) > ,
47
+ token_tx : Option < calloop:: channel:: Sender < TokenRequest > > ,
42
48
}
43
49
44
50
impl CosmicBluetoothApplet {
@@ -62,6 +68,8 @@ enum Message {
62
68
Request ( BluerRequest ) ,
63
69
Cancel ,
64
70
Confirm ,
71
+ Token ( TokenUpdate ) ,
72
+ OpenSettings ,
65
73
}
66
74
67
75
impl cosmic:: Application for CosmicBluetoothApplet {
@@ -78,6 +86,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
78
86
Self {
79
87
core,
80
88
icon_name : "bluetooth-symbolic" . to_string ( ) ,
89
+ token_tx : None ,
81
90
..Default :: default ( )
82
91
} ,
83
92
Command :: none ( ) ,
@@ -284,6 +293,32 @@ impl cosmic::Application for CosmicBluetoothApplet {
284
293
self . popup = None ;
285
294
}
286
295
}
296
+ Message :: OpenSettings => {
297
+ let exec = "cosmic-settings bluetooth" . to_string ( ) ;
298
+ if let Some ( tx) = self . token_tx . as_ref ( ) {
299
+ let _ = tx. send ( TokenRequest {
300
+ app_id : Self :: APP_ID . to_string ( ) ,
301
+ exec,
302
+ } ) ;
303
+ } ;
304
+ }
305
+ Message :: Token ( u) => match u {
306
+ TokenUpdate :: Init ( tx) => {
307
+ self . token_tx = Some ( tx) ;
308
+ }
309
+ TokenUpdate :: Finished => {
310
+ self . token_tx = None ;
311
+ }
312
+ TokenUpdate :: ActivationToken { token, .. } => {
313
+ let mut cmd = std:: process:: Command :: new ( "cosmic-settings" ) ;
314
+ cmd. arg ( "bluetooth" ) ;
315
+ if let Some ( token) = token {
316
+ cmd. env ( "XDG_ACTIVATION_TOKEN" , & token) ;
317
+ cmd. env ( "DESKTOP_STARTUP_ID" , & token) ;
318
+ }
319
+ cosmic:: process:: spawn ( cmd) ;
320
+ }
321
+ } ,
287
322
}
288
323
self . update_icon ( ) ;
289
324
Command :: none ( )
@@ -492,13 +527,16 @@ impl cosmic::Application for CosmicBluetoothApplet {
492
527
content = content. push ( padded_control ( divider:: horizontal:: default ( ) ) ) ;
493
528
content = content. push (
494
529
menu_button ( text ( fl ! ( "settings" ) ) . size ( 14 ) . width ( Length :: Fill ) )
495
- . on_press ( Message :: Ignore ) ,
530
+ . on_press ( Message :: OpenSettings ) ,
496
531
) ;
497
532
self . core . applet . popup_container ( content) . into ( )
498
533
}
499
534
500
535
fn subscription ( & self ) -> Subscription < Message > {
501
- bluetooth_subscription ( 0 ) . map ( Message :: BluetoothEvent )
536
+ Subscription :: batch ( vec ! [
537
+ activation_token_subscription( 0 ) . map( Message :: Token ) ,
538
+ bluetooth_subscription( 0 ) . map( Message :: BluetoothEvent ) ,
539
+ ] )
502
540
}
503
541
504
542
fn style ( & self ) -> Option < <Theme as application:: StyleSheet >:: Style > {
0 commit comments