refactor(kde): use the shared subscriber push

notify_subscribers keeps its KDE-specific part (the override events: Monitor, AddSubscriberSocket, AddSubscriberSocketWithOptions, Theme, ReloadStaticConfiguration, WindowManager Show) and the registry statics, and hands the push to komorebi_transport::notify_sockets. 40 lines of connect/write/stale-removal code removed from lib.rs. Behaviour-preserving; logs use the target komorebi::transport (D29).

Verified in komorebi-for-kde: cargo check -p komorebi --all-targets: no errors or warnings; cargo test -p komorebi --lib: 293 passed, 0 failed; the notify_subscribers doctest (it pushes to a real socket and removes a stale one): passed.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent 2f682ae6bf
commit 63c23ed1e7
1 file changed
+8 -33
+8 -33
View File
@@ -60,7 +60,6 @@ use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use std::collections::HashSet;
use std::io::Write;
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use std::sync::Arc;
@@ -361,41 +360,17 @@ pub fn notify_subscribers(
);
let notification = &serde_json::to_string(&notification)?;
let mut stale_sockets = vec![];
let mut sockets = SUBSCRIPTION_SOCKETS.lock();
let options = SUBSCRIPTION_SOCKET_OPTIONS.lock();
for (socket, path) in &mut *sockets {
let apply_state_filter = (*options)
.get(socket)
.copied()
.unwrap_or_default()
.filter_state_changes;
if !apply_state_filter || state_has_been_modified || is_override_event {
match UnixStream::connect(path) {
Ok(mut stream) => {
tracing::debug!("pushed notification to subscriber: {socket}");
stream.write_all(notification.as_bytes())?;
}
Err(_) => {
stale_sockets.push(socket.clone());
}
}
}
}
for socket in stale_sockets {
tracing::warn!("removing stale subscription: {socket}");
sockets.remove(&socket);
let socket_path = DATA_DIR.join(socket);
if let Err(error) = std::fs::remove_file(&socket_path) {
tracing::error!(
"could not remove stale subscriber socket file at {}: {error}",
socket_path.display()
)
}
}
komorebi_transport::notify_sockets(
notification,
&mut sockets,
&options,
state_has_been_modified || is_override_event,
&DATA_DIR,
|path| UnixStream::connect(path),
)?;
Ok(())
}