Improvments to launcher.
Moved UI building to a function. Found a way to clear GtkListBox without a loop. Ran rustfmt.
This commit is contained in:
parent
f4d8d778fe
commit
91087608b2
3 changed files with 134 additions and 133 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use pop_launcher::{Request, Response};
|
||||
use std::process;
|
||||
use std::io::{self, BufRead, Write};
|
||||
use std::process;
|
||||
|
||||
pub struct LauncherIpc {
|
||||
child: process::Child,
|
||||
|
|
@ -16,13 +16,15 @@ impl LauncherIpc {
|
|||
.stdout(process::Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let stdin = child.stdin.take().ok_or(
|
||||
io::Error::new(io::ErrorKind::Other, "failed to find child stdin")
|
||||
)?;
|
||||
let stdin = child.stdin.take().ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"failed to find child stdin",
|
||||
))?;
|
||||
|
||||
let stdout = io::BufReader::new(child.stdout.take().ok_or(
|
||||
io::Error::new(io::ErrorKind::Other, "failed to find child stdout")
|
||||
)?);
|
||||
let stdout = io::BufReader::new(child.stdout.take().ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"failed to find child stdout",
|
||||
))?);
|
||||
|
||||
Ok(Self {
|
||||
child,
|
||||
|
|
@ -33,9 +35,8 @@ impl LauncherIpc {
|
|||
}
|
||||
|
||||
fn send_request(&mut self, request: Request) -> io::Result<()> {
|
||||
let mut request_json = serde_json::to_string(&request).map_err(|err| {
|
||||
io::Error::new(io::ErrorKind::InvalidInput, err)
|
||||
})?;
|
||||
let mut request_json = serde_json::to_string(&request)
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
|
||||
request_json.push('\n');
|
||||
self.stdin.write_all(request_json.as_bytes())
|
||||
}
|
||||
|
|
@ -43,9 +44,8 @@ impl LauncherIpc {
|
|||
fn recv_response(&mut self) -> io::Result<Response> {
|
||||
let mut response_json = String::new();
|
||||
self.stdout.read_line(&mut response_json)?;
|
||||
serde_json::from_str(&response_json).map_err(|err| {
|
||||
io::Error::new(io::ErrorKind::InvalidData, err)
|
||||
})
|
||||
serde_json::from_str(&response_json)
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))
|
||||
}
|
||||
|
||||
pub fn request(&mut self, request: Request) -> io::Result<Response> {
|
||||
|
|
@ -55,7 +55,7 @@ impl LauncherIpc {
|
|||
|
||||
//TODO: better exit implementation
|
||||
pub fn exit(&mut self) -> io::Result<Option<process::ExitStatus>> {
|
||||
if ! self.exited {
|
||||
if !self.exited {
|
||||
self.send_request(Request::Exit)?;
|
||||
let status = self.child.wait()?;
|
||||
self.exited = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue