Skip to content

Commit a3d8421

Browse files
authored
fix: remove items from internal state when receiving remove event (#17)
Fixes #15
1 parent 20de4bd commit a3d8421

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/client.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,19 @@ impl Client {
283283
{
284284
let connection = connection.clone();
285285
let destination = destination.to_string();
286+
let items = items.clone();
286287
let tx = tx.clone();
287288

288289
spawn(async move {
289-
Self::watch_item_properties(&destination, &path, &connection, properties_proxy, tx)
290-
.await?;
290+
Self::watch_item_properties(
291+
&destination,
292+
&path,
293+
&connection,
294+
properties_proxy,
295+
items,
296+
tx,
297+
)
298+
.await?;
291299

292300
debug!("Stopped watching {destination}{path}");
293301
Ok::<(), Error>(())
@@ -342,6 +350,7 @@ impl Client {
342350
path: &str,
343351
connection: &Connection,
344352
properties_proxy: PropertiesProxy<'_>,
353+
items: Arc<Mutex<State>>,
345354
tx: broadcast::Sender<Event>,
346355
) -> crate::error::Result<()> {
347356
let notifier_item_proxy = StatusNotifierItemProxy::builder(connection)
@@ -380,6 +389,8 @@ impl Client {
380389
error!("{error:?}");
381390
}
382391

392+
items.lock().expect("mutex lock should succeed").remove(&destination.to_string());
393+
383394
tx.send(Event::Remove(destination.to_string()))?;
384395
break Ok(());
385396
}

0 commit comments

Comments
 (0)