@@ -31,6 +31,7 @@ pub struct CosmicPortal {
31
31
32
32
pub config_handler : Option < cosmic_config:: Config > ,
33
33
pub config : config:: Config ,
34
+ pub tx_conf : Option < tokio:: sync:: watch:: Sender < config:: Config > > ,
34
35
35
36
pub access_args : Option < access:: AccessDialogArgs > ,
36
37
pub access_choices : Vec < ( Option < usize > , Vec < String > ) > ,
@@ -71,10 +72,7 @@ pub enum Msg {
71
72
Background ( background:: Msg ) ,
72
73
Portal ( subscription:: Event ) ,
73
74
Output ( OutputEvent , WlOutput ) ,
74
- ConfigUpdateBackground {
75
- app_id : String ,
76
- choice : Option < background:: PermissionResponse > ,
77
- } ,
75
+ ConfigNotifyWatcher ,
78
76
ConfigSetScreenshot ( config:: screenshot:: Screenshot ) ,
79
77
/// Update config from external changes
80
78
ConfigSubUpdate ( config:: Config ) ,
@@ -136,6 +134,7 @@ impl cosmic::Application for CosmicPortal {
136
134
core,
137
135
config_handler,
138
136
config,
137
+ tx_conf : None ,
139
138
access_args : Default :: default ( ) ,
140
139
access_choices : Default :: default ( ) ,
141
140
file_choosers : Default :: default ( ) ,
@@ -196,36 +195,15 @@ impl cosmic::Application for CosmicPortal {
196
195
subscription:: Event :: Background ( args) => {
197
196
background:: update_args ( self , args) . map ( cosmic:: app:: Message :: App )
198
197
}
199
- subscription:: Event :: BackgroundGetAppPerm ( app_id, tx) => {
200
- let perm = match self . config . background . default_perm {
201
- config:: background:: PermissionDialog :: Allow => {
202
- background:: ConfigAppPerm :: DefaultAllow
203
- }
204
- config:: background:: PermissionDialog :: Deny => {
205
- background:: ConfigAppPerm :: DefaultDeny
206
- }
207
- _ => match self . config . background . apps . get ( & app_id) {
208
- Some ( true ) => background:: ConfigAppPerm :: UserAllow ,
209
- Some ( false ) => background:: ConfigAppPerm :: UserDeny ,
210
- None => background:: ConfigAppPerm :: Unset ,
211
- } ,
212
- } ;
213
- cosmic:: Command :: perform (
214
- async move {
215
- let _ = tx. send ( perm) . await ;
216
- cosmic:: app:: message:: none ( )
217
- } ,
218
- |x| x,
219
- )
220
- }
221
198
subscription:: Event :: Config ( config) => self . update ( Msg :: ConfigSubUpdate ( config) ) ,
222
199
subscription:: Event :: Accent ( _)
223
200
| subscription:: Event :: IsDark ( _)
224
201
| subscription:: Event :: HighContrast ( _)
225
202
| subscription:: Event :: BackgroundToplevels => cosmic:: iced:: Command :: none ( ) ,
226
- subscription:: Event :: Init ( tx ) => {
203
+ subscription:: Event :: Init { tx , tx_conf } => {
227
204
self . tx = Some ( tx) ;
228
- Command :: none ( )
205
+ self . tx_conf = Some ( tx_conf) ;
206
+ self . update ( Msg :: ConfigNotifyWatcher )
229
207
}
230
208
} ,
231
209
Msg :: Screenshot ( m) => screenshot:: update_msg ( self , m) . map ( cosmic:: app:: Message :: App ) ,
@@ -305,20 +283,10 @@ impl cosmic::Application for CosmicPortal {
305
283
306
284
cosmic:: iced:: Command :: none ( )
307
285
}
308
- Msg :: ConfigUpdateBackground { app_id, choice } => {
309
- if let ( Some ( choice) , Some ( handler) ) = ( choice, & mut self . config_handler ) {
310
- self . config
311
- . background
312
- . apps
313
- . insert ( app_id, choice == background:: PermissionResponse :: Allow ) ;
314
- if let Err ( e) = self
315
- . config
316
- . set_background ( handler, self . config . background . clone ( ) )
317
- {
318
- log:: error!( "Failed to save background config: {e}" ) ;
319
- }
286
+ Msg :: ConfigNotifyWatcher => {
287
+ if let Some ( tx) = self . tx_conf . as_mut ( ) {
288
+ tx. send_replace ( self . config . clone ( ) ) ;
320
289
}
321
-
322
290
cosmic:: iced:: Command :: none ( )
323
291
}
324
292
Msg :: ConfigSetScreenshot ( screenshot) => {
@@ -330,12 +298,11 @@ impl cosmic::Application for CosmicPortal {
330
298
}
331
299
None => log:: error!( "Failed to save config: No config handler" ) ,
332
300
}
333
-
334
- cosmic:: iced:: Command :: none ( )
301
+ self . update ( Msg :: ConfigNotifyWatcher )
335
302
}
336
303
Msg :: ConfigSubUpdate ( config) => {
337
304
self . config = config;
338
- cosmic :: iced :: Command :: none ( )
305
+ self . update ( Msg :: ConfigNotifyWatcher )
339
306
}
340
307
}
341
308
}
0 commit comments