1
1
use cosmic:: app:: Command ;
2
+ use cosmic:: applet:: token:: subscription:: {
3
+ activation_token_subscription, TokenRequest , TokenUpdate ,
4
+ } ;
2
5
use cosmic:: applet:: { menu_button, menu_control_padding, padded_control} ;
6
+ use cosmic:: cctk:: sctk:: reexports:: calloop;
3
7
use cosmic:: iced_widget:: Row ;
4
8
use cosmic:: {
5
9
iced:: {
@@ -93,6 +97,7 @@ struct CosmicNetworkApplet {
93
97
conn : Option < Connection > ,
94
98
timeline : Timeline ,
95
99
toggle_wifi_ctr : u128 ,
100
+ token_tx : Option < calloop:: channel:: Sender < TokenRequest > > ,
96
101
}
97
102
98
103
fn wifi_icon ( strength : u8 ) -> & ' static str {
@@ -181,6 +186,8 @@ pub(crate) enum Message {
181
186
Password ( String ) ,
182
187
SubmitPassword ,
183
188
Frame ( Instant ) ,
189
+ Token ( TokenUpdate ) ,
190
+ OpenSettings ,
184
191
// Errored(String),
185
192
}
186
193
@@ -195,6 +202,7 @@ impl cosmic::Application for CosmicNetworkApplet {
195
202
Self {
196
203
core,
197
204
icon_name : "network-offline-symbolic" . to_string ( ) ,
205
+ token_tx : None ,
198
206
..Default :: default ( )
199
207
} ,
200
208
Command :: none ( ) ,
@@ -392,6 +400,32 @@ impl cosmic::Application for CosmicNetworkApplet {
392
400
self . popup = None ;
393
401
}
394
402
}
403
+ Message :: OpenSettings => {
404
+ let exec = "cosmic-settings network" . to_string ( ) ;
405
+ if let Some ( tx) = self . token_tx . as_ref ( ) {
406
+ let _ = tx. send ( TokenRequest {
407
+ app_id : Self :: APP_ID . to_string ( ) ,
408
+ exec,
409
+ } ) ;
410
+ }
411
+ }
412
+ Message :: Token ( u) => match u {
413
+ TokenUpdate :: Init ( tx) => {
414
+ self . token_tx = Some ( tx) ;
415
+ }
416
+ TokenUpdate :: Finished => {
417
+ self . token_tx = None ;
418
+ }
419
+ TokenUpdate :: ActivationToken { token, .. } => {
420
+ let mut cmd = std:: process:: Command :: new ( "cosmic-settings" ) ;
421
+ cmd. arg ( "network" ) ;
422
+ if let Some ( token) = token {
423
+ cmd. env ( "XDG_ACTIVATION_TOKEN" , & token) ;
424
+ cmd. env ( "DESKTOP_STARTUP_ID" , & token) ;
425
+ }
426
+ cosmic:: process:: spawn ( cmd) ;
427
+ }
428
+ } ,
395
429
}
396
430
Command :: none ( )
397
431
}
@@ -772,7 +806,8 @@ impl cosmic::Application for CosmicNetworkApplet {
772
806
}
773
807
}
774
808
content = content. push ( padded_control ( divider:: horizontal:: default ( ) ) ) ;
775
- content = content. push ( menu_button ( text ( fl ! ( "settings" ) ) . size ( 14 ) ) ) ;
809
+ content = content
810
+ . push ( menu_button ( text ( fl ! ( "settings" ) ) . size ( 14 ) ) . on_press ( Message :: OpenSettings ) ) ;
776
811
self . core
777
812
. applet
778
813
. popup_container ( content. padding ( [ 8 , 0 , 8 , 0 ] ) )
@@ -785,12 +820,14 @@ impl cosmic::Application for CosmicNetworkApplet {
785
820
. timeline
786
821
. as_subscription ( )
787
822
. map ( |( _, now) | Message :: Frame ( now) ) ;
823
+ let token_sub = activation_token_subscription ( 0 ) . map ( Message :: Token ) ;
788
824
789
825
if let Some ( conn) = self . conn . as_ref ( ) {
790
826
let has_popup = self . popup . is_some ( ) ;
791
827
Subscription :: batch ( vec ! [
792
828
timeline,
793
829
network_sub,
830
+ token_sub,
794
831
active_conns_subscription( self . toggle_wifi_ctr, conn. clone( ) )
795
832
. map( Message :: NetworkManagerEvent ) ,
796
833
devices_subscription( self . toggle_wifi_ctr, has_popup, conn. clone( ) )
@@ -799,7 +836,7 @@ impl cosmic::Application for CosmicNetworkApplet {
799
836
. map( Message :: NetworkManagerEvent ) ,
800
837
] )
801
838
} else {
802
- Subscription :: batch ( vec ! [ timeline, network_sub] )
839
+ Subscription :: batch ( vec ! [ timeline, network_sub, token_sub ] )
803
840
}
804
841
}
805
842
0 commit comments