Skip to content

Commit

Permalink
Logging fixes (#21)
Browse files Browse the repository at this point in the history
* src/lib: don't use unwrap, logging fixes

* src: clippy
  • Loading branch information
flokli authored Jul 16, 2024
1 parent e3ca52f commit 320a8a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 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")
}
}
})
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/system.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 320a8a3

Please sign in to comment.