1
0
Fork 0
forked from wry/wry

add unix socket ipc

This commit is contained in:
kossLAN 2026-06-08 19:56:17 -04:00
parent dc62d2240f
commit f92c092acc
No known key found for this signature in database
9 changed files with 1550 additions and 2 deletions

View file

@ -4,7 +4,9 @@ use {
GlobalArgs,
json::{JsonClient, jsonl},
},
ipc::{self, Client as IpcClient},
tools::tool_client::{Handle, ToolClient, with_tool_client},
utils::errorfmt::ErrorFmt,
wire::{JayClientQueryId, jay_client_query, jay_compositor},
},
ahash::AHashMap,
@ -83,10 +85,13 @@ struct Clients {
impl Clients {
async fn run(&self, global: &GlobalArgs, args: ClientsArgs) {
let tc = &self.tc;
let comp = tc.jay_compositor().await;
let cmd = args
.cmd
.unwrap_or(ClientsCmd::Show(ShowArgs { cmd: ShowCmd::All }));
if self.run_ipc(global, &cmd) {
return;
}
let comp = tc.jay_compositor().await;
match cmd {
ClientsCmd::Show(a) => {
let id = tc.id();
@ -153,6 +158,50 @@ impl Clients {
}
tc.round_trip().await;
}
fn run_ipc(&self, global: &GlobalArgs, cmd: &ClientsCmd) -> bool {
match cmd {
ClientsCmd::Show(a) => {
let id = match &a.cmd {
ShowCmd::All => None,
ShowCmd::Id(a) => Some(a.id),
ShowCmd::SelectWindow => return false,
};
let clients: Vec<IpcClient> = match ipc::request(&ipc::Request::ClientsGet { id }) {
Ok(clients) => clients,
Err(e) if e.can_fallback() => return false,
Err(e) => fatal!("Could not query clients over IPC: {}", ErrorFmt(e)),
};
let mut clients = clients.into_iter().map(Client::from).collect::<Vec<_>>();
clients.sort_by_key(|c| c.id);
if global.json {
for client in &clients {
jsonl(&make_json_client(client));
}
} else {
let mut prefix = " ".to_string();
let mut printer = ClientPrinter {
prefix: &mut prefix,
};
for client in &clients {
println!("- client:");
printer.print_client(client);
}
}
true
}
ClientsCmd::Kill(a) => match &a.cmd {
KillCmd::Id(id) => {
match ipc::request_unit(&ipc::Request::ClientsKill { id: id.id }) {
Ok(()) => true,
Err(e) if e.can_fallback() => false,
Err(e) => fatal!("Could not kill client over IPC: {}", ErrorFmt(e)),
}
}
KillCmd::SelectWindow => false,
},
}
}
}
#[derive(Default)]
@ -169,6 +218,23 @@ pub struct Client {
pub exe: Option<String>,
}
impl From<IpcClient> for Client {
fn from(client: IpcClient) -> Self {
Self {
id: client.client_id,
sandboxed: client.sandboxed,
sandbox_engine: client.sandbox_engine,
sandbox_app_id: client.sandbox_app_id,
sandbox_instance_id: client.sandbox_instance_id,
uid: client.uid,
pid: client.pid,
is_xwayland: client.is_xwayland,
comm: client.comm,
exe: client.exe,
}
}
}
pub async fn handle_client_query(
tl: &Rc<ToolClient>,
id: JayClientQueryId,