mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-13 10:11:42 +00:00
fix: search accumulated log buffer for server readiness line
Some checks are pending
Continuous integration / test (push) Waiting to run
Some checks are pending
Continuous integration / test (push) Waiting to run
This commit is contained in:
parent
d0575ead00
commit
0a3d448d3b
1 changed files with 21 additions and 10 deletions
|
|
@ -104,7 +104,7 @@ impl StremioServer {
|
||||||
let out_lines = lines.clone();
|
let out_lines = lines.clone();
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
let out_thread = thread::spawn(move || {
|
let out_thread = thread::spawn(move || {
|
||||||
let http_endpoint = String::new();
|
let mut endpoint_sent = false;
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = [0; SRV_BUFFER_SIZE];
|
let mut buffer = [0; SRV_BUFFER_SIZE];
|
||||||
let on = match stdout.read(&mut buffer[..]) {
|
let on = match stdout.read(&mut buffer[..]) {
|
||||||
|
|
@ -120,19 +120,21 @@ impl StremioServer {
|
||||||
{
|
{
|
||||||
let lines = &mut *out_lines.lock().unwrap();
|
let lines = &mut *out_lines.lock().unwrap();
|
||||||
*lines += string_data.deref();
|
*lines += string_data.deref();
|
||||||
if http_endpoint.is_empty() {
|
if !endpoint_sent {
|
||||||
if let Some(http_endpoint) = string_data
|
if let Some(line) = lines
|
||||||
.lines()
|
.lines()
|
||||||
.find(|line| line.starts_with("EngineFS server started at"))
|
.find(|line| line.starts_with("EngineFS server started at"))
|
||||||
{
|
{
|
||||||
let http_endpoint =
|
if let Some(endpoint) = line.split_whitespace().last() {
|
||||||
http_endpoint.split_whitespace().last().unwrap();
|
println!("HTTP endpoint: {endpoint}");
|
||||||
println!("HTTP endpoint: {http_endpoint}");
|
tx.send(endpoint.to_string()).ok();
|
||||||
let endpoint = http_endpoint.to_string();
|
endpoint_sent = true;
|
||||||
tx.send(endpoint.clone()).ok();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*lines = lines
|
// Preserve trailing newline so the next chunk can't glue onto an unterminated line.
|
||||||
|
let had_trailing_newline = lines.ends_with('\n');
|
||||||
|
let mut trimmed = lines
|
||||||
.lines()
|
.lines()
|
||||||
.rev()
|
.rev()
|
||||||
.take(SRV_LOG_SIZE)
|
.take(SRV_LOG_SIZE)
|
||||||
|
|
@ -141,6 +143,10 @@ impl StremioServer {
|
||||||
.rev()
|
.rev()
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
if had_trailing_newline {
|
||||||
|
trimmed.push('\n');
|
||||||
|
}
|
||||||
|
*lines = trimmed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -164,7 +170,8 @@ impl StremioServer {
|
||||||
{
|
{
|
||||||
let lines = &mut *err_lines.lock().unwrap();
|
let lines = &mut *err_lines.lock().unwrap();
|
||||||
*lines += string_data.deref();
|
*lines += string_data.deref();
|
||||||
*lines = lines
|
let had_trailing_newline = lines.ends_with('\n');
|
||||||
|
let mut trimmed = lines
|
||||||
.lines()
|
.lines()
|
||||||
.rev()
|
.rev()
|
||||||
.take(SRV_LOG_SIZE)
|
.take(SRV_LOG_SIZE)
|
||||||
|
|
@ -173,6 +180,10 @@ impl StremioServer {
|
||||||
.rev()
|
.rev()
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
if had_trailing_newline {
|
||||||
|
trimmed.push('\n');
|
||||||
|
}
|
||||||
|
*lines = trimmed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue