mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-16 18:11:14 +02:00
fix(wm): socket cleanup on exit
This commit ensures that Shutdown signals will be sent to subscriber sockets and that "komorebi.sock" will be cleaned up on exit. Alongside these changes, komorebi_client::send_message no longer retries so that integrators can receive feedback via io::Result errors when komorebi is not running.
This commit is contained in:
@@ -57,16 +57,10 @@ const KOMOREBI: &str = "komorebi.sock";
|
|||||||
|
|
||||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||||
let socket = DATA_DIR.join(KOMOREBI);
|
let socket = DATA_DIR.join(KOMOREBI);
|
||||||
let mut connected = false;
|
let mut stream = UnixStream::connect(socket)?;
|
||||||
while !connected {
|
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||||
if let Ok(mut stream) = UnixStream::connect(&socket) {
|
|
||||||
connected = true;
|
|
||||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||||
let socket = DATA_DIR.join(KOMOREBI);
|
let socket = DATA_DIR.join(KOMOREBI);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -163,7 +163,7 @@ lazy_static! {
|
|||||||
]));
|
]));
|
||||||
static ref SUBSCRIPTION_PIPES: Arc<Mutex<HashMap<String, File>>> =
|
static ref SUBSCRIPTION_PIPES: Arc<Mutex<HashMap<String, File>>> =
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
static ref SUBSCRIPTION_SOCKETS: Arc<Mutex<HashMap<String, PathBuf>>> =
|
pub static ref SUBSCRIPTION_SOCKETS: Arc<Mutex<HashMap<String, PathBuf>>> =
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
static ref TCP_CONNECTIONS: Arc<Mutex<HashMap<String, TcpStream>>> =
|
static ref TCP_CONNECTIONS: Arc<Mutex<HashMap<String, TcpStream>>> =
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
clippy::doc_markdown
|
clippy::doc_markdown
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
use std::net::Shutdown;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -23,6 +24,7 @@ use sysinfo::Process;
|
|||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
use uds_windows::UnixStream;
|
||||||
|
|
||||||
use komorebi::border_manager;
|
use komorebi::border_manager;
|
||||||
use komorebi::focus_manager;
|
use komorebi::focus_manager;
|
||||||
@@ -287,5 +289,15 @@ fn main() -> Result<()> {
|
|||||||
WindowsApi::disable_focus_follows_mouse()?;
|
WindowsApi::disable_focus_follows_mouse()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sockets = komorebi::SUBSCRIPTION_SOCKETS.lock();
|
||||||
|
for path in (*sockets).values() {
|
||||||
|
if let Ok(stream) = UnixStream::connect(path) {
|
||||||
|
stream.shutdown(Shutdown::Both)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let socket = DATA_DIR.join("komorebi.sock");
|
||||||
|
let _ = std::fs::remove_file(socket);
|
||||||
|
|
||||||
std::process::exit(130);
|
std::process::exit(130);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::fs::OpenOptions;
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use std::net::Shutdown;
|
||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
@@ -779,6 +780,16 @@ impl WindowManager {
|
|||||||
WindowsApi::disable_focus_follows_mouse()?;
|
WindowsApi::disable_focus_follows_mouse()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sockets = SUBSCRIPTION_SOCKETS.lock();
|
||||||
|
for path in (*sockets).values() {
|
||||||
|
if let Ok(stream) = UnixStream::connect(path) {
|
||||||
|
stream.shutdown(Shutdown::Both)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let socket = DATA_DIR.join("komorebi.sock");
|
||||||
|
let _ = std::fs::remove_file(socket);
|
||||||
|
|
||||||
std::process::exit(0)
|
std::process::exit(0)
|
||||||
}
|
}
|
||||||
SocketMessage::MonitorIndexPreference(index_preference, left, top, right, bottom) => {
|
SocketMessage::MonitorIndexPreference(index_preference, left, top, right, bottom) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user