2
2
3
3
use std:: collections:: { hash_map:: Entry , HashMap } ;
4
4
5
- use cosmic:: { iced:: window, iced_runtime :: command :: Action , widget} ;
5
+ use cosmic:: { iced:: window, widget} ;
6
6
use futures:: { FutureExt , TryFutureExt } ;
7
7
use tokio:: sync:: mpsc:: Sender ;
8
8
use zbus:: { fdo, object_server:: SignalContext , zvariant} ;
@@ -21,17 +21,12 @@ const POP_SHELL_PATH: &str = "/com.System76.PopShell";
21
21
/// https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.impl.portal.Background.html
22
22
pub struct Background {
23
23
tx : Sender < subscription:: Event > ,
24
- config : config:: background:: Background ,
25
24
}
26
25
27
26
impl Background {
28
- pub fn new ( tx : Sender < subscription:: Event > ) -> Self {
29
- // FIXME: Will need to change this to handle external updates (e.g. from cosmic-settings)
30
- let config = config:: Config :: load ( ) . 0 . background ;
31
- Self { tx, config }
27
+ pub const fn new ( tx : Sender < subscription:: Event > ) -> Self {
28
+ Self { tx }
32
29
}
33
-
34
- // fn dialog(name: &str) -> widget::Dialog<'_, PermissionResponse> {}
35
30
}
36
31
37
32
#[ zbus:: interface( name = "org.freedesktop.impl.portal.Background" ) ]
@@ -48,7 +43,7 @@ impl Background {
48
43
49
44
/// Notifies the user that an app is running in the background
50
45
async fn notify_background (
51
- & mut self ,
46
+ & self ,
52
47
// #[zbus(connection)] connection: &zbus::Connection,
53
48
#[ zbus( signal_context) ] context : SignalContext < ' _ > ,
54
49
handle : zvariant:: ObjectPath < ' _ > ,
@@ -57,6 +52,18 @@ impl Background {
57
52
) -> PortalResponse < NotifyBackgroundResult > {
58
53
log:: debug!( "[background] Request handle: {handle:?}" ) ;
59
54
55
+ // Request only what's needed to avoid cloning and receiving the entire config
56
+ // This is also cleaner than storing the config because it's difficult to keep it
57
+ // updated without synch primitives
58
+ let ( tx, mut rx) = tokio:: sync:: mpsc:: channel ( 1 ) ;
59
+ let config = self
60
+ . tx
61
+ . send ( subscription:: Event :: BackgroundReq ( tx, app_id. clone ( ) ) )
62
+ . inspect_err ( |e| log:: error!( "[background] Failed receiving background config from main app {e:?}" ) )
63
+ . and_then ( |_| rx. recv ( ) )
64
+ . unwrap_or_default ( )
65
+ . await ;
66
+
60
67
match self . config . apps . entry ( app_id) {
61
68
// Skip dialog based on default response set in configs
62
69
_ if self . config . default_perm == PermissionDialog :: Allow => {
0 commit comments