This commit is contained in:
Vladimir Borisov 2022-04-28 14:05:30 +03:00
parent f2080cd205
commit d40c757973

View file

@ -1,60 +1,60 @@
#![windows_subsystem = "windows"] #![windows_subsystem = "windows"]
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
use clap::Parser; use clap::Parser;
use native_windows_gui::{self as nwg, NativeUi}; use native_windows_gui::{self as nwg, NativeUi};
mod stremio_app; mod stremio_app;
use crate::stremio_app::{stremio_server::StremioServer, MainWindow}; use crate::stremio_app::{stremio_server::StremioServer, MainWindow};
const DEV_ENDPOINT: &str = "http://127.0.0.1:11470"; const DEV_ENDPOINT: &str = "http://127.0.0.1:11470";
const WEB_ENDPOINT: &str = "https://app.strem.io/shell-v4.4/"; const WEB_ENDPOINT: &str = "https://app.strem.io/shell-v4.4/";
const STA_ENDPOINT: &str = "https://staging.strem.io/"; const STA_ENDPOINT: &str = "https://staging.strem.io/";
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(version)] #[clap(version)]
struct Opt { struct Opt {
#[clap(long, help = "Enable dev tools when pressing F12")] #[clap(long, help = "Enable dev tools when pressing F12")]
dev_tools: bool, dev_tools: bool,
#[clap(long, help = "Disable the server and load the WebUI from localhost")] #[clap(long, help = "Disable the server and load the WebUI from localhost")]
development: bool, development: bool,
#[clap(long, help = "Shortcut for --webui-url=https://staging.strem.io/")] #[clap(long, help = "Shortcut for --webui-url=https://staging.strem.io/")]
staging: bool, staging: bool,
#[clap(long, default_value = WEB_ENDPOINT, help = "Override the WebUI URL")] #[clap(long, default_value = WEB_ENDPOINT, help = "Override the WebUI URL")]
webui_url: String, webui_url: String,
} }
fn main() { fn main() {
// native-windows-gui has some basic high DPI support with the high-dpi // native-windows-gui has some basic high DPI support with the high-dpi
// feature. It supports the "System DPI Awareness" mode, but not the more // feature. It supports the "System DPI Awareness" mode, but not the more
// advanced Per-Monitor (v2) DPI Awareness modes. // advanced Per-Monitor (v2) DPI Awareness modes.
// //
// Use an application manifest to get rid of this deprecated warning. // Use an application manifest to get rid of this deprecated warning.
#[allow(deprecated)] #[allow(deprecated)]
unsafe { unsafe {
nwg::set_dpi_awareness() nwg::set_dpi_awareness()
}; };
nwg::enable_visual_styles(); nwg::enable_visual_styles();
let opt = Opt::parse(); let opt = Opt::parse();
if !opt.development { if !opt.development {
StremioServer::new(); StremioServer::new();
} }
let webui_url = if opt.development && opt.webui_url == WEB_ENDPOINT { let webui_url = if opt.development && opt.webui_url == WEB_ENDPOINT {
DEV_ENDPOINT.to_string() DEV_ENDPOINT.to_string()
} else if opt.staging && opt.webui_url == WEB_ENDPOINT { } else if opt.staging && opt.webui_url == WEB_ENDPOINT {
STA_ENDPOINT.to_string() STA_ENDPOINT.to_string()
} else { } else {
opt.webui_url opt.webui_url
}; };
nwg::init().expect("Failed to init Native Windows GUI"); nwg::init().expect("Failed to init Native Windows GUI");
let _app = MainWindow::build_ui(MainWindow { let _app = MainWindow::build_ui(MainWindow {
webui_url, webui_url,
dev_tools: opt.development || opt.dev_tools, dev_tools: opt.development || opt.dev_tools,
..Default::default() ..Default::default()
}) })
.expect("Failed to build UI"); .expect("Failed to build UI");
nwg::dispatch_thread_events(); nwg::dispatch_thread_events();
} }