refactor: send initial config after watching for changes
This commit is contained in:
parent
b2ce4ccea2
commit
3f2ba11d56
1 changed files with 23 additions and 21 deletions
|
|
@ -86,27 +86,6 @@ fn watcher_stream<T: CosmicConfigEntry + Send + Sync + Default + 'static + Clone
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut config = match T::get_entry(&cosmic_config) {
|
|
||||||
Ok(config) => config,
|
|
||||||
Err((errors, default)) => {
|
|
||||||
if !errors.is_empty() {
|
|
||||||
eprintln!("Error getting config: {config_id} {errors:?}");
|
|
||||||
}
|
|
||||||
default
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(err) = tx
|
|
||||||
.send(Update {
|
|
||||||
errors: Vec::new(),
|
|
||||||
keys: Vec::new(),
|
|
||||||
config: config.clone(),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
eprintln!("Failed to send config: {err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut attempts = 0;
|
let mut attempts = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -168,6 +147,29 @@ fn watcher_stream<T: CosmicConfigEntry + Send + Sync + Default + 'static + Clone
|
||||||
let mut owner_changed = owner_changed
|
let mut owner_changed = owner_changed
|
||||||
.map(|c| Change::OwnerChanged(c.is_some()))
|
.map(|c| Change::OwnerChanged(c.is_some()))
|
||||||
.fuse();
|
.fuse();
|
||||||
|
|
||||||
|
// update now, just in case we missed changes while setting up stream
|
||||||
|
let mut config = match T::get_entry(&cosmic_config) {
|
||||||
|
Ok(config) => config,
|
||||||
|
Err((errors, default)) => {
|
||||||
|
if !errors.is_empty() {
|
||||||
|
eprintln!("Error getting config: {config_id} {errors:?}");
|
||||||
|
}
|
||||||
|
default
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = tx
|
||||||
|
.send(Update {
|
||||||
|
errors: Vec::new(),
|
||||||
|
keys: Vec::new(),
|
||||||
|
config: config.clone(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
eprintln!("Failed to send config: {err}");
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let change: Changed = futures::select! {
|
let change: Changed = futures::select! {
|
||||||
c = changes.next() => {
|
c = changes.next() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue