diff --git a/src/lib.rs b/src/lib.rs index 981f180..a14aa72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use tao::{ event_loop::{ControlFlow, EventLoopBuilder}, window::WindowBuilder, }; +use tracing::{debug, warn}; use wry::WebViewBuilder; #[derive(Debug, Deserialize)] @@ -58,9 +59,10 @@ pub fn spawn_browser(url: String, command_receiver: Option>) - event_loop.run(move |event, _, control_flow| { *control_flow = ControlFlow::Wait; + debug!(?event, "got event"); match event { - Event::NewEvents(StartCause::Init) => println!("Opened a browser window!"), + Event::NewEvents(StartCause::Init) => debug!("init"), Event::WindowEvent { event: WindowEvent::CloseRequested, .. @@ -68,13 +70,19 @@ pub fn spawn_browser(url: String, command_receiver: Option>) - | Event::UserEvent(Command::Stop) => *control_flow = ControlFlow::Exit, Event::UserEvent(Command::Reload) => { if let Ok(url) = webview.url() { - // TODO: Remove the use of unwrap - webview.load_url(url.as_str()).unwrap(); + if let Err(e) = webview.load_url(url.as_str()) { + warn!(err=%e, "unable to load webview") + }; } } - // TODO: Remove the use of unwrap - Event::UserEvent(Command::LoadUrl { url }) => webview.load_url(url.as_str()).unwrap(), - _ => (), + Event::UserEvent(Command::LoadUrl { url }) => { + if let Err(e) = webview.load_url(url.as_str()) { + warn!(err=%e, "unable to load webview") + }; + } + _ => { + warn!(?event, "got other event") + } } }) } diff --git a/src/main.rs b/src/main.rs index dae92ff..e8b210c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,8 +34,8 @@ fn main() -> color_eyre::eyre::Result<()> { let machine_id = system::get_machine_id().context("getting machine id")?; debug!("Loading the config"); - let config = Config::load(cli.default_config_path.map(|p| PathBuf::from(p))) - .context("loading config")?; + let config = + Config::load(cli.default_config_path.map(PathBuf::from)).context("loading config")?; info!(url=%cli.url, "Opening URL"); diff --git a/src/system.rs b/src/system.rs index ce727ea..9ed3634 100644 --- a/src/system.rs +++ b/src/system.rs @@ -1,6 +1,6 @@ use tracing::{instrument, warn}; -const MACHINE_ID_PATH: &'static str = "/etc/machine-id"; +const MACHINE_ID_PATH: &str = "/etc/machine-id"; /// Returns the system machine id /// (https://www.freedesktop.org/software/systemd/man/latest/machine-id.html)