mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-01-11 22:40:32 +00:00
Icon, ugly splash, error web handling
This commit is contained in:
parent
6f1ba7f8a6
commit
f75acabcf8
9 changed files with 112 additions and 8 deletions
47
Cargo.lock
generated
47
Cargo.lock
generated
|
|
@ -40,6 +40,12 @@ version = "3.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
|
@ -92,6 +98,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embed-resource"
|
||||
version = "1.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45de30eb317b4cd3882ee16623cb3004e5fb99a8f4cd40097cadf61efbc54adc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"vswhom",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum_primitive"
|
||||
version = "0.1.1"
|
||||
|
|
@ -467,6 +484,7 @@ dependencies = [
|
|||
name = "stremio-shell-ng"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embed-resource",
|
||||
"mpv",
|
||||
"native-windows-derive",
|
||||
"native-windows-gui",
|
||||
|
|
@ -578,6 +596,26 @@ version = "0.9.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "vswhom"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"vswhom-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vswhom-sys"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f5402d3d0e79a069714f7b48e3ecc60be7775a2c049cb839457457a239532"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.74"
|
||||
|
|
@ -698,3 +736,12 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16cdb3898397cf7f624c294948669beafaeebc5577d5ec53d0afb76633593597"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -16,3 +16,6 @@ mpv = "0.2.3"
|
|||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
structopt = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
embed-resource = "1.3"
|
||||
4
build.rs
Normal file
4
build.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extern crate embed_resource;
|
||||
fn main() {
|
||||
embed_resource::compile("resources.rc");
|
||||
}
|
||||
BIN
images/stremio.ico
Normal file
BIN
images/stremio.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
images/stremio_splash.ico
Normal file
BIN
images/stremio_splash.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
3
resources.rc
Normal file
3
resources.rc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#define RT_MANIFEST 24
|
||||
MAINICON ICON "images/stremio.ico"
|
||||
SPLASHIMAGE ICON "images/stremio_splash.ico"
|
||||
|
|
@ -25,6 +25,7 @@ fn main() {
|
|||
unsafe {
|
||||
nwg::set_dpi_awareness()
|
||||
};
|
||||
nwg::enable_visual_styles();
|
||||
|
||||
let opt = Opt::from_args();
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,30 @@ struct RPCResponse {
|
|||
#[derive(Default, NwgUi)]
|
||||
pub struct MainWindow {
|
||||
pub webui_url: String,
|
||||
#[nwg_control(title: "Stremio", flags: "MAIN_WINDOW|VISIBLE")]
|
||||
#[nwg_events( OnWindowClose: [MainWindow::on_quit], OnInit: [MainWindow::on_init], OnMinMaxInfo: [MainWindow::on_min_max(SELF, EVT_DATA)] )]
|
||||
#[nwg_resource]
|
||||
pub embed: nwg::EmbedResource,
|
||||
#[nwg_resource(source_embed: Some(&data.embed), source_embed_str: Some("MAINICON"))]
|
||||
pub window_icon: nwg::Icon,
|
||||
#[nwg_control(icon: Some(&data.window_icon), title: "Stremio", flags: "MAIN_WINDOW|VISIBLE")]
|
||||
#[nwg_events( OnWindowClose: [Self::on_quit], OnInit: [Self::on_init], OnPaint: [Self::on_paint], OnMinMaxInfo: [Self::on_min_max(SELF, EVT_DATA)] )]
|
||||
pub window: nwg::Window,
|
||||
#[nwg_partial(parent: window)]
|
||||
pub webview: WebView,
|
||||
#[nwg_partial(parent: window)]
|
||||
pub player: Player,
|
||||
#[nwg_resource(size: Some((300,300)), source_embed: Some(&data.embed), source_embed_str: Some("SPLASHIMAGE"))]
|
||||
pub splash_image: nwg::Icon,
|
||||
#[nwg_control(icon: Some(&data.splash_image))]
|
||||
pub splash: nwg::ImageFrame,
|
||||
#[nwg_control]
|
||||
#[nwg_events(OnNotice: [Self::on_toggle_fullscreen_notice] )]
|
||||
pub toggle_fullscreen_notice: nwg::Notice,
|
||||
#[nwg_control]
|
||||
#[nwg_events(OnNotice: [Self::on_quit_notice] )]
|
||||
pub quit_notice: nwg::Notice,
|
||||
#[nwg_control]
|
||||
#[nwg_events(OnNotice: [Self::on_hide_splash_notice] )]
|
||||
pub hide_splash_notice: nwg::Notice,
|
||||
}
|
||||
|
||||
impl MainWindow {
|
||||
|
|
@ -101,6 +118,9 @@ impl MainWindow {
|
|||
} // recv
|
||||
}); // thread
|
||||
|
||||
let toggle_fullscreen_sender = self.toggle_fullscreen_notice.sender();
|
||||
let quit_sender = self.quit_notice.sender();
|
||||
let hide_splash_sender = self.hide_splash_notice.sender();
|
||||
thread::spawn(move || loop {
|
||||
let rx = web_rx.lock().unwrap();
|
||||
if let Ok(msg) = rx.recv() {
|
||||
|
|
@ -140,7 +160,20 @@ impl MainWindow {
|
|||
} else {
|
||||
match method {
|
||||
"toggle-fullscreen" => {
|
||||
println!("full screen toggle requested");
|
||||
toggle_fullscreen_sender.notice();
|
||||
}
|
||||
"quit" => {
|
||||
quit_sender.notice();
|
||||
}
|
||||
"app-ready" => {
|
||||
hide_splash_sender.notice();
|
||||
}
|
||||
"app-error" => {
|
||||
hide_splash_sender.notice();
|
||||
if args.len() > 1 {
|
||||
// TODO: Make this modal dialog
|
||||
eprintln!("Web App Error: {}", args[1].as_str().unwrap_or("Unknown error"));
|
||||
}
|
||||
}
|
||||
_ => eprintln!("Unsupported command {:?}", args),
|
||||
}
|
||||
|
|
@ -157,6 +190,19 @@ impl MainWindow {
|
|||
let data = data.on_min_max();
|
||||
data.set_min_size(Self::MIN_WIDTH, Self::MIN_HEIGHT);
|
||||
}
|
||||
fn on_paint(&self) {
|
||||
let (w, h) = self.window.size();
|
||||
self.splash.set_size(w, h);
|
||||
}
|
||||
fn on_toggle_fullscreen_notice(&self) {
|
||||
println!("full screen toggle requested");
|
||||
}
|
||||
fn on_quit_notice(&self) {
|
||||
self.on_quit();
|
||||
}
|
||||
fn on_hide_splash_notice(&self) {
|
||||
self.splash.set_visible(false);
|
||||
}
|
||||
fn on_quit(&self) {
|
||||
nwg::stop_thread_dispatch();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,13 +78,13 @@ impl PartialUi for WebView {
|
|||
} else {
|
||||
eprintln!("failed to get interface to controller2");
|
||||
}
|
||||
let webview = controller
|
||||
let webview = controller
|
||||
.get_webview()
|
||||
.expect("Cannot obtain webview from controller");
|
||||
if let Some(endpoint) = endpoint.get() {
|
||||
if let Err(e) = webview
|
||||
if let Some(endpoint) = endpoint.get() {
|
||||
if let Err(_) = webview
|
||||
.navigate(endpoint.as_str()) {
|
||||
eprintln!("Cannot load WEB UI at '{}': {:?}", &endpoint, e);
|
||||
tx_web.clone().send(format!(r#"{{"id":1,"args":["app-error","Cannot load WEB UI at '{}'"]}}"#, &endpoint).to_string()).ok();
|
||||
};
|
||||
}
|
||||
webview
|
||||
|
|
@ -92,7 +92,7 @@ impl PartialUi for WebView {
|
|||
r##"
|
||||
window.qt={webChannelTransport:{send:window.chrome.webview.postMessage}};
|
||||
window.chrome.webview.addEventListener('message',ev=>window.qt.webChannelTransport.onmessage(ev));
|
||||
window.onload=()=>initShellComm();
|
||||
window.onload=()=>{try{initShellComm();}catch(e){window.chrome.webview.postMessage('{"id":1,"args":["app-error","'+e.message+'"]}')}};
|
||||
"##,
|
||||
|_| Ok(()),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue