Slightly better error handling for the server

This commit is contained in:
Vladimir Borisov 2022-09-30 15:51:59 +03:00
parent ef461f0440
commit b85cf31cd1

View file

@ -1,4 +1,6 @@
use native_windows_gui as nwg;
use std::os::windows::process::CommandExt;
use std::env;
use std::process::Command;
use std::thread;
use std::time::Duration;
@ -17,12 +19,24 @@ impl StremioServer {
job.set_extended_limit_info(&mut info).ok();
job.assign_current_process().ok();
loop {
let mut child = Command::new("stremio-runtime")
let child = Command::new("./stremio-runtime")
.arg("server.js")
.creation_flags(CREATE_NO_WINDOW)
.spawn()
.expect("Cannot run the server");
child.wait().expect("Cannot wait for the server");
.spawn();
match child {
Ok(mut child) => {
// TODO: store somehow last few lines of the child's stdout/stderr instead of just waiting
child.wait().expect("Cannot wait for the server");
}
Err(err) => {
nwg::error_message(
"Stremio server",
format!("Cannot execute stremio-runtime: {}", &err).as_str(),
);
break;
}
};
// TODO: show error message with the child's stdout/stderr
thread::sleep(Duration::from_millis(500));
dbg!("Trying to restart the server...");
}