mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat!: include the sender ID in static messages
This commit is contained in:
parent
0f84717a1b
commit
5816d81f1b
6 changed files with 14 additions and 59 deletions
|
|
@ -45,20 +45,6 @@ impl Body<'static> {
|
|||
BodyCustom::from_lua(kind, value)
|
||||
}
|
||||
|
||||
pub fn tab(kind: &str, body: &str) -> usize {
|
||||
match kind {
|
||||
"cd" | "hover" | "bulk" | "rename" => {}
|
||||
_ => return 0,
|
||||
}
|
||||
|
||||
match Self::from_str(kind, body) {
|
||||
Ok(Self::Cd(b)) => b.tab,
|
||||
Ok(Self::Hover(b)) => b.tab,
|
||||
Ok(Self::Rename(b)) => b.tab,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate(kind: &str) -> Result<()> {
|
||||
if matches!(
|
||||
kind,
|
||||
|
|
@ -111,11 +97,6 @@ impl<'a> Body<'a> {
|
|||
|
||||
#[inline]
|
||||
pub fn with_sender(self, sender: u64) -> Payload<'a> { Payload::new(self).with_sender(sender) }
|
||||
|
||||
#[inline]
|
||||
pub fn with_severity(self, severity: u16) -> Payload<'a> {
|
||||
Payload::new(self).with_severity(severity)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoLua<'_> for Body<'static> {
|
||||
|
|
|
|||
|
|
@ -41,11 +41,6 @@ impl<'a> Payload<'a> {
|
|||
self.sender = sender;
|
||||
self
|
||||
}
|
||||
|
||||
pub(super) fn with_severity(mut self, severity: u16) -> Self {
|
||||
self.sender = severity as u64;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Payload<'static> {
|
||||
|
|
|
|||
|
|
@ -80,12 +80,6 @@ impl Pubsub {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pub_static(severity: u16, body: Body) {
|
||||
if Self::own_static_ability(body.kind()) {
|
||||
Client::push(body.with_severity(severity));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pub_from_hi() -> bool {
|
||||
let abilities = REMOTE.read().keys().cloned().collect();
|
||||
let abilities = BOOT.remote_events.union(&abilities).map(|s| s.as_str()).collect();
|
||||
|
|
@ -98,8 +92,8 @@ impl Pubsub {
|
|||
if LOCAL.read().contains_key("cd") {
|
||||
Self::pub_(BodyCd::dummy(tab));
|
||||
}
|
||||
if Self::own_static_ability("cd") {
|
||||
Client::push(BodyCd::borrowed(tab, url).with_severity(100));
|
||||
if PEERS.read().values().any(|p| p.able("cd")) {
|
||||
Client::push(BodyCd::borrowed(tab, url));
|
||||
}
|
||||
if BOOT.local_events.contains("cd") {
|
||||
BodyCd::borrowed(tab, url).with_receiver(*ID).flush();
|
||||
|
|
@ -110,8 +104,8 @@ impl Pubsub {
|
|||
if LOCAL.read().contains_key("hover") {
|
||||
Self::pub_(BodyHover::dummy(tab));
|
||||
}
|
||||
if Self::own_static_ability("hover") {
|
||||
Client::push(BodyHover::borrowed(tab, url).with_severity(200));
|
||||
if PEERS.read().values().any(|p| p.able("hover")) {
|
||||
Client::push(BodyHover::borrowed(tab, url));
|
||||
}
|
||||
if BOOT.local_events.contains("hover") {
|
||||
BodyHover::borrowed(tab, url).with_receiver(*ID).flush();
|
||||
|
|
@ -147,7 +141,7 @@ impl Pubsub {
|
|||
Self::pub_(BodyYank::dummy());
|
||||
}
|
||||
if Self::own_static_ability("yank") {
|
||||
Client::push(BodyYank::borrowed(cut, urls).with_severity(300));
|
||||
Client::push(BodyYank::borrowed(cut, urls));
|
||||
}
|
||||
if BOOT.local_events.contains("yank") {
|
||||
BodyYank::borrowed(cut, urls).with_receiver(*ID).flush();
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ impl Server {
|
|||
continue;
|
||||
}
|
||||
|
||||
if receiver == 0 && sender <= u16::MAX as u64 {
|
||||
if receiver == 0 {
|
||||
let Some(body) = parts.next() else { continue };
|
||||
if !STATE.set(kind, sender as u16, body) { continue }
|
||||
if !STATE.set(kind, sender, body) { continue }
|
||||
}
|
||||
|
||||
line.push('\n');
|
||||
|
|
@ -91,10 +91,6 @@ impl Server {
|
|||
let Ok(payload) = Payload::from_str(&s) else { return };
|
||||
let Body::Hi(hi) = payload.body else { return };
|
||||
|
||||
if payload.sender <= u16::MAX as u64 {
|
||||
return; // The kind of static messages cannot be "hi"
|
||||
}
|
||||
|
||||
if id.is_none() {
|
||||
if let Some(ref state) = *STATE.read() {
|
||||
state.values().for_each(|s| _ = tx.send(s.clone()));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use tokio::{fs::{self, File, OpenOptions}, io::{AsyncBufReadExt, AsyncWriteExt,
|
|||
use yazi_boot::BOOT;
|
||||
use yazi_shared::{timestamp_us, RoCell};
|
||||
|
||||
use crate::{body::Body, CLIENTS};
|
||||
use crate::CLIENTS;
|
||||
|
||||
pub static STATE: RoCell<State> = RoCell::new();
|
||||
|
||||
|
|
@ -23,23 +23,22 @@ impl Deref for State {
|
|||
}
|
||||
|
||||
impl State {
|
||||
pub fn set(&self, kind: &str, severity: u16, body: &str) -> bool {
|
||||
pub fn set(&self, kind: &str, sender: u64, body: &str) -> bool {
|
||||
let Some(inner) = &mut *self.inner.write() else { return false };
|
||||
let key = format!("{}_{severity}_{kind}", Body::tab(kind, body));
|
||||
|
||||
if body == "null" {
|
||||
return inner
|
||||
.remove(&key)
|
||||
.remove(kind)
|
||||
.map(|_| self.last.store(timestamp_us(), Ordering::Relaxed))
|
||||
.is_some();
|
||||
}
|
||||
|
||||
let value = format!("{kind},0,{severity},{body}\n");
|
||||
if inner.get(&key).is_some_and(|s| *s == value) {
|
||||
let value = format!("{kind},0,{sender},{body}\n");
|
||||
if inner.get(kind).is_some_and(|s| *s == value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inner.insert(key, value);
|
||||
inner.insert(kind.to_owned(), value);
|
||||
self.last.store(timestamp_us(), Ordering::Relaxed);
|
||||
true
|
||||
}
|
||||
|
|
@ -86,9 +85,7 @@ impl State {
|
|||
let mut parts = line.splitn(4, ',');
|
||||
let Some(kind) = parts.next() else { continue };
|
||||
let Some(_) = parts.next() else { continue };
|
||||
let Some(severity) = parts.next().and_then(|s| s.parse::<u16>().ok()) else { continue };
|
||||
let Some(body) = parts.next() else { continue };
|
||||
inner.insert(format!("{}_{severity}_{kind}", Body::tab(kind, body)), mem::take(&mut line));
|
||||
inner.insert(kind.to_owned(), mem::take(&mut line));
|
||||
}
|
||||
|
||||
let clients = CLIENTS.read();
|
||||
|
|
|
|||
|
|
@ -25,14 +25,6 @@ impl Pubsub {
|
|||
})?,
|
||||
)?;
|
||||
|
||||
ps.raw_set(
|
||||
"pub_static",
|
||||
lua.create_function(|_, (severity, kind, value): (u16, mlua::String, Value)| {
|
||||
yazi_dds::Pubsub::pub_static(severity, Body::from_lua(kind.to_str()?, value)?);
|
||||
Ok(())
|
||||
})?,
|
||||
)?;
|
||||
|
||||
ps.raw_set(
|
||||
"sub",
|
||||
lua.create_function(|lua, (kind, f): (mlua::String, Function)| {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue