Cross-platform IPC via interprocess + Windows support fixes
- Replace Unix-socket-only server/client with interprocess local sockets: unchanged unix domain socket on Linux (SOCKET_API compatible), named pipes on Windows - Run command lines with arguments via sh -c / cmd /C in the PTY - Wire RunProgram args into the spawned command - Make libc a unix-only dependency - Skip Kitty background image on Windows (protocol unsupported) - Drop dead pixel-size query code in kitty_gfx - Reject left/right panel positions at config parse instead of silently ignoring them Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::ipc::{self, ClientMessage, ClientRole, ServerMessage};
|
||||
use interprocess::local_socket::traits::{ListenerExt as _, Stream as _};
|
||||
use interprocess::local_socket::{ListenerOptions, Stream};
|
||||
use std::io::{BufReader, BufWriter};
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
@@ -25,11 +26,21 @@ pub enum IpcEvent {
|
||||
}
|
||||
|
||||
pub fn start(socket_path: &str, event_tx: mpsc::Sender<IpcEvent>) {
|
||||
// På unix: städa bort en ev. kvarlämnad socket-fil från en tidigare körning.
|
||||
#[cfg(unix)]
|
||||
let _ = std::fs::remove_file(socket_path);
|
||||
let listener = match UnixListener::bind(socket_path) {
|
||||
|
||||
let name = match ipc::socket_name(socket_path) {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
eprintln!("Ogiltigt socket-namn {}: {}", socket_path, e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let listener = match ListenerOptions::new().name(name).create_sync() {
|
||||
Ok(l) => l,
|
||||
Err(e) => {
|
||||
eprintln!("Kunde inte binda Unix socket {}: {}", socket_path, e);
|
||||
eprintln!("Kunde inte binda lokal socket {}: {}", socket_path, e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -45,7 +56,8 @@ pub fn start(socket_path: &str, event_tx: mpsc::Sender<IpcEvent>) {
|
||||
handle_client(client_id, stream, event_tx, sp);
|
||||
});
|
||||
}
|
||||
Err(_) => break,
|
||||
// Transienta accept-fel (kan hända för named pipes) — fortsätt lyssna.
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -53,20 +65,17 @@ pub fn start(socket_path: &str, event_tx: mpsc::Sender<IpcEvent>) {
|
||||
|
||||
fn handle_client(
|
||||
client_id: usize,
|
||||
stream: UnixStream,
|
||||
stream: Stream,
|
||||
event_tx: mpsc::Sender<IpcEvent>,
|
||||
socket_path: String,
|
||||
) {
|
||||
let stream_write = match stream.try_clone() {
|
||||
Ok(s) => s,
|
||||
Err(_) => return,
|
||||
};
|
||||
let mut reader = BufReader::new(stream);
|
||||
let (recv_half, send_half) = stream.split();
|
||||
let mut reader = BufReader::new(recv_half);
|
||||
let (tx, rx) = mpsc::sync_channel::<ServerMessage>(64);
|
||||
|
||||
// Writer thread
|
||||
thread::spawn(move || {
|
||||
let mut writer = BufWriter::new(stream_write);
|
||||
let mut writer = BufWriter::new(send_half);
|
||||
for msg in rx {
|
||||
if ipc::write_message(&mut writer, &msg).is_err() {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user