Skip to content

Commit 3f2ba11

Browse files
committed
refactor: send initial config after watching for changes
1 parent b2ce4cc commit 3f2ba11

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

cosmic-config/src/dbus.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,6 @@ fn watcher_stream<T: CosmicConfigEntry + Send + Sync + Default + 'static + Clone
8686
unreachable!();
8787
};
8888

89-
let mut config = match T::get_entry(&cosmic_config) {
90-
Ok(config) => config,
91-
Err((errors, default)) => {
92-
if !errors.is_empty() {
93-
eprintln!("Error getting config: {config_id} {errors:?}");
94-
}
95-
default
96-
}
97-
};
98-
99-
if let Err(err) = tx
100-
.send(Update {
101-
errors: Vec::new(),
102-
keys: Vec::new(),
103-
config: config.clone(),
104-
})
105-
.await
106-
{
107-
eprintln!("Failed to send config: {err}");
108-
}
109-
11089
let mut attempts = 0;
11190

11291
loop {
@@ -168,6 +147,29 @@ fn watcher_stream<T: CosmicConfigEntry + Send + Sync + Default + 'static + Clone
168147
let mut owner_changed = owner_changed
169148
.map(|c| Change::OwnerChanged(c.is_some()))
170149
.fuse();
150+
151+
// update now, just in case we missed changes while setting up stream
152+
let mut config = match T::get_entry(&cosmic_config) {
153+
Ok(config) => config,
154+
Err((errors, default)) => {
155+
if !errors.is_empty() {
156+
eprintln!("Error getting config: {config_id} {errors:?}");
157+
}
158+
default
159+
}
160+
};
161+
162+
if let Err(err) = tx
163+
.send(Update {
164+
errors: Vec::new(),
165+
keys: Vec::new(),
166+
config: config.clone(),
167+
})
168+
.await
169+
{
170+
eprintln!("Failed to send config: {err}");
171+
}
172+
171173
loop {
172174
let change: Changed = futures::select! {
173175
c = changes.next() => {

0 commit comments

Comments
 (0)