From e8dce2535ade29dba93e4da4f5c071fd70a62d8d Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Wed, 21 Jul 2021 22:49:53 +0300 Subject: [PATCH] Open external --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + src/stremio_app/stremio_app.rs | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 12a264e..a020b96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,6 +331,22 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "open" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcea7a30d6b81a2423cc59c43554880feff7b57d12916f231a79f8d6d9470201" +dependencies = [ + "pathdiff", + "winapi", +] + +[[package]] +name = "pathdiff" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34" + [[package]] name = "plotters" version = "0.3.1" @@ -489,6 +505,7 @@ dependencies = [ "native-windows-derive", "native-windows-gui", "once_cell", + "open", "serde", "serde_json", "structopt", diff --git a/Cargo.toml b/Cargo.toml index 77fd603..deb1826 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ mpv = "0.2.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" structopt = "0.3" +open = "1" [build-dependencies] embed-resource = "1.3" \ No newline at end of file diff --git a/src/stremio_app/stremio_app.rs b/src/stremio_app/stremio_app.rs index 21c367e..0c12136 100644 --- a/src/stremio_app/stremio_app.rs +++ b/src/stremio_app/stremio_app.rs @@ -182,6 +182,24 @@ impl MainWindow { ); } } + "open-external" => { + if args.len() > 1 { + if let Some(arg) = args[1].as_str() { + // FIXME: THIS IS NOT SAFE BY ANY MEANS + // open::that("calc").ok(); does exactly that + let arg_lc = arg.to_lowercase(); + if arg_lc.starts_with("http://") + || arg_lc.starts_with("https://") + || arg_lc.starts_with("rtp://") + || arg_lc.starts_with("rtps://") + || arg_lc.starts_with("ftp://") + || arg_lc.starts_with("ipfs://") + { + open::that(arg).ok(); + } + } + } + } _ => eprintln!("Unsupported command {:?}", args), } }