From 44f45fd8e1214b6ccce9994256b3dae6068cff06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sun, 11 Aug 2024 16:38:25 +0800 Subject: [PATCH] fix: DDS static messages only work when at least two instances are running (#1467) --- yazi-dds/src/pubsub.rs | 10 +++++----- yazi-dds/src/server.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yazi-dds/src/pubsub.rs b/yazi-dds/src/pubsub.rs index c016889c..845df3e2 100644 --- a/yazi-dds/src/pubsub.rs +++ b/yazi-dds/src/pubsub.rs @@ -72,10 +72,10 @@ impl Pubsub { return Self::pub_(body); } - let (kind, peers) = (body.kind(), PEERS.read()); - if receiver == 0 && peers.values().any(|c| c.able(kind)) { + let kind = body.kind(); + if receiver == 0 && Self::any_remote_own(kind) { Client::push(body); - } else if peers.get(&receiver).is_some_and(|c| c.able(kind)) { + } else if PEERS.read().get(&receiver).is_some_and(|c| c.able(kind)) { Client::push(body.with_receiver(receiver)); } } @@ -140,7 +140,7 @@ impl Pubsub { if LOCAL.read().contains_key("@yank") { Self::pub_(BodyYank::dummy()); } - if Self::own_static_ability("@yank") { + if Self::any_remote_own("@yank") { Client::push(BodyYank::borrowed(cut, urls)); } if BOOT.local_events.contains("@yank") { @@ -185,7 +185,7 @@ impl Pubsub { } #[inline] - fn own_static_ability(kind: &str) -> bool { + fn any_remote_own(kind: &str) -> bool { REMOTE.read().contains_key(kind) // Owned abilities || PEERS.read().values().any(|p| p.able(kind)) // Remote peers' abilities || BOOT.remote_events.contains(kind) // Owned abilities from the command-line argument diff --git a/yazi-dds/src/server.rs b/yazi-dds/src/server.rs index 8085fe51..1e0ae37c 100644 --- a/yazi-dds/src/server.rs +++ b/yazi-dds/src/server.rs @@ -72,7 +72,7 @@ impl Server { } line.push('\n'); - clients.into_iter().filter(|c| c.id != id).for_each(|c| _ = c.tx.send(line.clone())); + clients.into_iter().for_each(|c| _ = c.tx.send(line.clone())); } else => break }