Skip to content

Commit

Permalink
src/lib: don't use unwrap, logging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
flokli committed Jul 16, 2024
1 parent 4d22089 commit ed5833c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tao::{
event_loop::{ControlFlow, EventLoopBuilder},
window::WindowBuilder,
};
use tracing::{debug, warn};
use wry::WebViewBuilder;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -58,23 +59,30 @@ pub fn spawn_browser(url: String, command_receiver: Option<Receiver<Command>>) -

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,
..
}
| 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")
}
}
})
}

0 comments on commit ed5833c

Please sign in to comment.