1
1
mod localize;
2
2
mod subscriptions;
3
-
3
+ use cosmic:: applet:: token:: subscription:: {
4
+ activation_token_subscription, TokenRequest , TokenUpdate ,
5
+ } ;
4
6
use cosmic:: applet:: { menu_button, menu_control_padding, padded_control} ;
7
+ use cosmic:: cctk:: sctk:: reexports:: calloop;
5
8
use cosmic:: cosmic_config:: { config_subscription, Config , CosmicConfigEntry } ;
6
9
use cosmic:: iced:: wayland:: popup:: { destroy_popup, get_popup} ;
7
10
use cosmic:: iced:: Limits ;
@@ -23,7 +26,6 @@ use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline};
23
26
use std:: borrow:: Cow ;
24
27
use std:: collections:: HashMap ;
25
28
use std:: path:: PathBuf ;
26
- use std:: process;
27
29
use tokio:: sync:: mpsc:: Sender ;
28
30
use tracing:: info;
29
31
@@ -52,6 +54,7 @@ struct Notifications {
52
54
timeline : Timeline ,
53
55
dbus_sender : Option < Sender < subscriptions:: dbus:: Input > > ,
54
56
cards : Vec < ( id:: Cards , Vec < Notification > , bool , String , String , String ) > ,
57
+ token_tx : Option < calloop:: channel:: Sender < TokenRequest > > ,
55
58
}
56
59
57
60
impl Notifications {
@@ -84,14 +87,15 @@ enum Message {
84
87
TogglePopup ,
85
88
CloseRequested ( window:: Id ) ,
86
89
DoNotDisturb ( chain:: Toggler , bool ) ,
87
- Settings ,
88
90
Frame ( Instant ) ,
89
91
NotificationEvent ( Notification ) ,
90
92
Config ( NotificationsConfig ) ,
91
93
DbusEvent ( subscriptions:: dbus:: Output ) ,
92
94
Dismissed ( u32 ) ,
93
95
ClearAll ( String ) ,
94
96
CardsToggled ( String , bool ) ,
97
+ Token ( TokenUpdate ) ,
98
+ OpenSettings ,
95
99
}
96
100
97
101
impl cosmic:: Application for Notifications {
@@ -167,6 +171,7 @@ impl cosmic::Application for Notifications {
167
171
. map( |( _, now) | Message :: Frame ( now) ) ,
168
172
subscriptions:: dbus:: proxy( ) . map( Message :: DbusEvent ) ,
169
173
subscriptions:: notifications:: notifications( ) . map( Message :: NotificationEvent ) ,
174
+ activation_token_subscription( 0 ) . map( Message :: Token ) ,
170
175
] )
171
176
}
172
177
@@ -210,9 +215,6 @@ impl cosmic::Application for Notifications {
210
215
}
211
216
}
212
217
}
213
- Message :: Settings => {
214
- let _ = process:: Command :: new ( "cosmic-settings notifications" ) . spawn ( ) ;
215
- }
216
218
Message :: NotificationEvent ( n) => {
217
219
if let Some ( c) = self
218
220
. cards
@@ -311,6 +313,32 @@ impl cosmic::Application for Notifications {
311
313
self . popup = None ;
312
314
}
313
315
}
316
+ Message :: OpenSettings => {
317
+ let exec = "cosmic-settings notifications" . to_string ( ) ;
318
+ if let Some ( tx) = self . token_tx . as_ref ( ) {
319
+ let _ = tx. send ( TokenRequest {
320
+ app_id : Self :: APP_ID . to_string ( ) ,
321
+ exec,
322
+ } ) ;
323
+ }
324
+ }
325
+ Message :: Token ( u) => match u {
326
+ TokenUpdate :: Init ( tx) => {
327
+ self . token_tx = Some ( tx) ;
328
+ }
329
+ TokenUpdate :: Finished => {
330
+ self . token_tx = None ;
331
+ }
332
+ TokenUpdate :: ActivationToken { token, .. } => {
333
+ let mut cmd = std:: process:: Command :: new ( "cosmic-settings" ) ;
334
+ cmd. arg ( "notifications" ) ;
335
+ if let Some ( token) = token {
336
+ cmd. env ( "XDG_ACTIVATION_TOKEN" , & token) ;
337
+ cmd. env ( "DESKTOP_STARTUP_ID" , & token) ;
338
+ }
339
+ cosmic:: process:: spawn ( cmd) ;
340
+ }
341
+ } ,
314
342
} ;
315
343
self . update_icon ( ) ;
316
344
Command :: none ( )
@@ -335,8 +363,8 @@ impl cosmic::Application for Notifications {
335
363
. text_size( 14 )
336
364
. width( Length :: Fill ) ] ) ;
337
365
338
- let settings =
339
- menu_button ( text ( fl ! ( "notification-settings" ) ) . size ( 14 ) ) . on_press ( Message :: Settings ) ;
366
+ let settings = menu_button ( text ( fl ! ( "notification-settings" ) ) . size ( 14 ) )
367
+ . on_press ( Message :: OpenSettings ) ;
340
368
341
369
let notifications = if self . cards . is_empty ( ) {
342
370
row ! [ container(
0 commit comments