Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging fixes #21

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading