mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-13 14:20:46 +00:00
Use server startup URL for WebUI streaming URL
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
469bb4f5bf
commit
bfcd7de6da
2 changed files with 25 additions and 44 deletions
|
|
@ -32,40 +32,6 @@ use crate::stremio_app::{
|
||||||
|
|
||||||
use super::stremio_server::StremioServer;
|
use super::stremio_server::StremioServer;
|
||||||
|
|
||||||
fn webui_url_with_streaming_server(webui_url: &str) -> String {
|
|
||||||
if webui_url.trim_end_matches('/') != WEB_ENDPOINT.trim_end_matches('/') {
|
|
||||||
return webui_url.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
find_streaming_server_url()
|
|
||||||
.map(|server_url| web_endpoint_with_streaming_server(&server_url))
|
|
||||||
.unwrap_or_else(|| webui_url.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_streaming_server_url() -> Option<String> {
|
|
||||||
let client = reqwest::blocking::Client::builder()
|
|
||||||
.timeout(time::Duration::from_millis(500))
|
|
||||||
.build()
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
(11470..=11474).find_map(|port| {
|
|
||||||
let server_url = format!("http://127.0.0.1:{port}");
|
|
||||||
let settings_url = format!("{server_url}/settings");
|
|
||||||
let response = client.get(settings_url).send().ok()?;
|
|
||||||
|
|
||||||
if !response.status().is_success() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let body = response.text().ok()?;
|
|
||||||
if body.contains("\"baseUrl\"") && body.contains("\"values\"") {
|
|
||||||
Some(server_url)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, NwgUi)]
|
#[derive(Default, NwgUi)]
|
||||||
pub struct MainWindow {
|
pub struct MainWindow {
|
||||||
pub command: String,
|
pub command: String,
|
||||||
|
|
@ -163,10 +129,16 @@ impl MainWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn on_init(&self) {
|
fn on_init(&self) {
|
||||||
self.webview
|
let webui_url =
|
||||||
.endpoint
|
if self.webui_url.trim_end_matches('/') == WEB_ENDPOINT.trim_end_matches('/') {
|
||||||
.set(webui_url_with_streaming_server(&self.webui_url))
|
self.server
|
||||||
.ok();
|
.server_url()
|
||||||
|
.map(|server_url| web_endpoint_with_streaming_server(&server_url))
|
||||||
|
.unwrap_or_else(|| self.webui_url.clone())
|
||||||
|
} else {
|
||||||
|
self.webui_url.clone()
|
||||||
|
};
|
||||||
|
self.webview.endpoint.set(webui_url).ok();
|
||||||
self.webview.dev_tools.set(self.dev_tools).ok();
|
self.webview.dev_tools.set(self.dev_tools).ok();
|
||||||
if let Some(hwnd) = self.window.handle.hwnd() {
|
if let Some(hwnd) = self.window.handle.hwnd() {
|
||||||
if let Ok(mut saved_style) = self.saved_window_style.try_borrow_mut() {
|
if let Ok(mut saved_style) = self.saved_window_style.try_borrow_mut() {
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,17 @@ 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>>,
|
||||||
|
server_url: Arc<Mutex<Option<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StremioServer {
|
impl StremioServer {
|
||||||
pub fn start(&self) {
|
pub fn server_url(&self) -> Option<String> {
|
||||||
|
self.server_url.lock().ok().and_then(|url| url.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start(&self) -> Option<String> {
|
||||||
if self.development {
|
if self.development {
|
||||||
return;
|
return None;
|
||||||
}
|
}
|
||||||
let (tx, rx) = flume::unbounded();
|
let (tx, rx) = flume::unbounded();
|
||||||
let logs = self.logs.clone();
|
let logs = self.logs.clone();
|
||||||
|
|
@ -173,8 +178,12 @@ impl StremioServer {
|
||||||
sender.notice();
|
sender.notice();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for the server to start
|
// Wait for the server to start and keep the exact endpoint printed by server.js.
|
||||||
rx.recv().unwrap();
|
let server_url = rx.recv().unwrap();
|
||||||
|
if let Ok(mut stored_url) = self.server_url.lock() {
|
||||||
|
*stored_url = Some(server_url.clone());
|
||||||
|
}
|
||||||
|
Some(server_url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +202,7 @@ impl PartialUi for StremioServer {
|
||||||
.parent(data.parent)
|
.parent(data.parent)
|
||||||
.build(&mut data.crash_notice)
|
.build(&mut data.crash_notice)
|
||||||
.ok();
|
.ok();
|
||||||
data.start();
|
let _ = data.start();
|
||||||
println!("Stremio server started");
|
println!("Stremio server started");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -210,7 +219,7 @@ impl PartialUi for StremioServer {
|
||||||
"Stremio server crash log",
|
"Stremio server crash log",
|
||||||
self.logs.lock().unwrap().deref(),
|
self.logs.lock().unwrap().deref(),
|
||||||
);
|
);
|
||||||
self.start();
|
let _ = self.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue