Command line flag to enable dev tools

This commit is contained in:
Vladimir Borisov 2021-11-17 13:23:24 +02:00
parent 76ff6cac5b
commit a12c7d265a
3 changed files with 8 additions and 1 deletions

View file

@ -14,6 +14,8 @@ const STA_ENDPOINT: &str = "https://staging.strem.io/";
#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(long)]
dev_tools: bool,
#[structopt(long)]
development: bool,
#[structopt(long)]
@ -51,6 +53,7 @@ fn main() {
nwg::init().expect("Failed to init Native Windows GUI");
let _app = MainWindow::build_ui(MainWindow {
webui_url,
dev_tools: opt.development || opt.dev_tools,
..Default::default()
})
.expect("Failed to build UI");

View file

@ -16,6 +16,7 @@ use crate::stremio_app::window_helper::WindowStyle;
#[derive(Default, NwgUi)]
pub struct MainWindow {
pub webui_url: String,
pub dev_tools: bool,
pub saved_window_style: RefCell<WindowStyle>,
#[nwg_resource]
pub embed: nwg::EmbedResource,
@ -76,6 +77,7 @@ impl MainWindow {
}
fn on_init(&self) {
self.webview.endpoint.set(self.webui_url.clone()).ok();
self.webview.dev_tools.set(self.dev_tools).ok();
if let Some(hwnd) = self.window.handle.hwnd() {
let mut saved_style = self.saved_window_style.borrow_mut();
saved_style.center_window(hwnd, Self::MIN_WIDTH, Self::MIN_HEIGHT);

View file

@ -18,6 +18,7 @@ use winapi::um::winuser::{GetClientRect, WM_SETFOCUS};
#[derive(Default)]
pub struct WebView {
pub endpoint: Rc<OnceCell<String>>,
pub dev_tools: Rc<OnceCell<bool>>,
controller: Rc<OnceCell<Controller>>,
pub channel: ipc::Channel,
notice: nwg::Notice,
@ -60,6 +61,7 @@ impl PartialUi for WebView {
.ok();
let controller_clone = data.controller.clone();
let endpoint = data.endpoint.clone();
let dev_tools = data.dev_tools.clone();
let result = webview2::EnvironmentBuilder::new()
.with_additional_browser_arguments("--disable-gpu --autoplay-policy=no-user-gesture-required")
.build(move |env| {
@ -83,7 +85,7 @@ impl PartialUi for WebView {
.expect("Cannot obtain webview from controller");
let settings = webview.get_settings().unwrap();
settings.put_is_status_bar_enabled(false).ok();
settings.put_are_dev_tools_enabled(true).ok();
settings.put_are_dev_tools_enabled(*dev_tools.get().unwrap()).ok();
settings.put_are_default_context_menus_enabled(false).ok();
settings.put_is_zoom_control_enabled(false).ok();
settings.put_is_built_in_error_page_enabled(false).ok();