mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-12 01:00:32 +00:00
Fix v4/v5 server coexistence detection
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
bbbe882faf
commit
91024730f4
1 changed files with 30 additions and 0 deletions
30
src/main.rs
30
src/main.rs
|
|
@ -93,6 +93,17 @@ fn main() {
|
|||
}
|
||||
// END IPC
|
||||
|
||||
// v4 has a different mutex name; the IPC check above won't catch it.
|
||||
if detect_stremio_on_default_port() {
|
||||
nwg::init().ok();
|
||||
nwg::error_message(
|
||||
"Stremio is already running",
|
||||
"Another Stremio instance (v4) appears to be running on port 11470.\n\
|
||||
Please close it before launching this version.",
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::env::set_var(
|
||||
STREMIO_SERVER_DEV_MODE,
|
||||
if opt.development { "true" } else { "false" },
|
||||
|
|
@ -122,3 +133,22 @@ fn main() {
|
|||
.expect("Failed to build UI");
|
||||
nwg::dispatch_thread_events();
|
||||
}
|
||||
|
||||
/// Returns true if a Stremio streaming server is bound on 11470.
|
||||
fn detect_stremio_on_default_port() -> bool {
|
||||
let client = match reqwest::blocking::Client::builder()
|
||||
.timeout(std::time::Duration::from_millis(500))
|
||||
.build()
|
||||
{
|
||||
Ok(client) => client,
|
||||
Err(_) => return false,
|
||||
};
|
||||
match client.get("http://127.0.0.1:11470/settings").send() {
|
||||
Ok(resp) if resp.status().is_success() => match resp.text() {
|
||||
// Both keys present rules out foreign processes (VPN, proxy) on 11470.
|
||||
Ok(body) => body.contains("\"baseUrl\"") && body.contains("\"options\""),
|
||||
Err(_) => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue