mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-12 01:00:32 +00:00
Pass streaming server URL to WebUI
This commit is contained in:
parent
bbbe882faf
commit
469bb4f5bf
2 changed files with 51 additions and 2 deletions
|
|
@ -16,7 +16,10 @@ use url::Url;
|
|||
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
|
||||
|
||||
use crate::stremio_app::{
|
||||
constants::{APP_NAME, UPDATE_ENDPOINT, UPDATE_INTERVAL, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH},
|
||||
constants::{
|
||||
web_endpoint_with_streaming_server, APP_NAME, UPDATE_ENDPOINT, UPDATE_INTERVAL,
|
||||
WEB_ENDPOINT, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH,
|
||||
},
|
||||
ipc::{RPCRequest, RPCResponse},
|
||||
splash::SplashImage,
|
||||
stremio_player::Player,
|
||||
|
|
@ -29,6 +32,40 @@ use crate::stremio_app::{
|
|||
|
||||
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)]
|
||||
pub struct MainWindow {
|
||||
pub command: String,
|
||||
|
|
@ -126,7 +163,10 @@ impl MainWindow {
|
|||
}
|
||||
}
|
||||
fn on_init(&self) {
|
||||
self.webview.endpoint.set(self.webui_url.clone()).ok();
|
||||
self.webview
|
||||
.endpoint
|
||||
.set(webui_url_with_streaming_server(&self.webui_url))
|
||||
.ok();
|
||||
self.webview.dev_tools.set(self.dev_tools).ok();
|
||||
if let Some(hwnd) = self.window.handle.hwnd() {
|
||||
if let Ok(mut saved_style) = self.saved_window_style.try_borrow_mut() {
|
||||
|
|
|
|||
|
|
@ -15,3 +15,12 @@ pub const STREMIO_SERVER_DEV_MODE: &str = "STREMIO_SERVER_DEV_MODE";
|
|||
pub const SRV_BUFFER_SIZE: usize = 1024;
|
||||
pub const SERVER_IPC_KEY: &str = "SERVER_IPC_KEY";
|
||||
pub const SRV_LOG_SIZE: usize = 20;
|
||||
|
||||
pub fn web_endpoint_with_streaming_server(server_url: &str) -> String {
|
||||
let server_url = server_url.trim_end_matches('/');
|
||||
let streaming_server_url =
|
||||
url::form_urlencoded::byte_serialize(server_url.as_bytes()).collect::<String>();
|
||||
let web_endpoint = WEB_ENDPOINT.trim_end_matches('/');
|
||||
|
||||
format!("{web_endpoint}/#/?streamingServerUrl={streaming_server_url}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue