mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-13 18:30:47 +00:00
fix: guard StremioServer::start() with a running flag
Some checks failed
Continuous integration / test (push) Has been cancelled
Some checks failed
Continuous integration / test (push) Has been cancelled
This commit is contained in:
parent
0a3d448d3b
commit
27ef17042c
1 changed files with 12 additions and 1 deletions
|
|
@ -8,7 +8,10 @@ use std::{
|
||||||
os::windows::process::CommandExt,
|
os::windows::process::CommandExt,
|
||||||
path,
|
path,
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
sync::{Arc, Mutex, Once},
|
sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc, Mutex, Once,
|
||||||
|
},
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
use winapi::um::{
|
use winapi::um::{
|
||||||
|
|
@ -71,6 +74,7 @@ pub struct StremioServer {
|
||||||
parent: nwg::ControlHandle,
|
parent: nwg::ControlHandle,
|
||||||
crash_notice: nwg::Notice,
|
crash_notice: nwg::Notice,
|
||||||
logs: Arc<Mutex<String>>,
|
logs: Arc<Mutex<String>>,
|
||||||
|
running: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StremioServer {
|
impl StremioServer {
|
||||||
|
|
@ -78,9 +82,14 @@ impl StremioServer {
|
||||||
if self.development {
|
if self.development {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if self.running.swap(true, Ordering::SeqCst) {
|
||||||
|
eprintln!("StremioServer::start() called while a server is already running; skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let (tx, rx) = flume::unbounded();
|
let (tx, rx) = flume::unbounded();
|
||||||
let logs = self.logs.clone();
|
let logs = self.logs.clone();
|
||||||
let sender = self.crash_notice.sender();
|
let sender = self.crash_notice.sender();
|
||||||
|
let running = self.running.clone();
|
||||||
|
|
||||||
ensure_parent_job_object();
|
ensure_parent_job_object();
|
||||||
|
|
||||||
|
|
@ -205,6 +214,8 @@ impl StremioServer {
|
||||||
let mut logs = logs.lock().unwrap();
|
let mut logs = logs.lock().unwrap();
|
||||||
*logs = lines.lock().unwrap().deref().to_string();
|
*logs = lines.lock().unwrap().deref().to_string();
|
||||||
}
|
}
|
||||||
|
// Clear before sender.notice() so the next start() can pass the swap guard.
|
||||||
|
running.store(false, Ordering::SeqCst);
|
||||||
println!("Server terminated.");
|
println!("Server terminated.");
|
||||||
sender.notice();
|
sender.notice();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue