From bd57184640e3f93733d12fc19d0c1fc60a28ad2f Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Mon, 20 Nov 2023 19:31:20 +0200 Subject: [PATCH] add logging --- Cargo.lock | 41 +++++++++++++++++++++++++++++++++++ README.md | 13 +++++++++++ desktop/src-tauri/Cargo.toml | 1 + desktop/src-tauri/src/main.rs | 3 ++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 05e583a..404976e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,6 +664,19 @@ dependencies = [ "xkeysym", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1247,6 +1260,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "iana-time-zone" version = "0.1.58" @@ -1366,6 +1385,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "itoa" version = "0.4.8" @@ -1633,6 +1663,8 @@ name = "mobslide" version = "0.0.1" dependencies = [ "enigo", + "env_logger", + "log", "tauri", "tauri-build", "window-shadows", @@ -2930,6 +2962,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +dependencies = [ + "winapi-util", +] + [[package]] name = "thin-slice" version = "0.1.1" diff --git a/README.md b/README.md index eac82ae..c726f79 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,16 @@ npm run dev -- --host 0.0.0.0 ### Building To build for the current platform, execute `cargo tauri build`. On Windows, this will build both NSIS and MSI installers. Both function identically and are located under `src-tauri/target/release/bundle/`. + + +### Debugging +When developing you can see logging messages by setting ENV variable +``` +export RUST_LOG=trace +cargo tauri dev +``` + +For forther exploring, you can even try setting +``` +RUST_BACKTRACE=1 +``` \ No newline at end of file diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 2a3a222..e1b544e 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -16,6 +16,7 @@ tauri-build = { version = "1.4", features = [] } tauri = { version = "1.4", features = ["shell-open", "devtools"] } enigo = { version = "0.2.0-rc2" } env_logger = "0.10" +log = "0.4.20" [target.'cfg(any(windows, target_os = "macos"))'.dependencies] diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 86fe689..600fa0b 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -5,12 +5,13 @@ use window_shadows::set_shadow; use enigo::{Direction, Enigo, Key, Keyboard, Settings}; +use log::debug; use tauri::Manager; #[tauri::command] async fn press(key: String) -> Result<(), String> { let mut enigo = Enigo::new(&Settings::default()).unwrap(); - + debug!("Pressing {}", key); match key.as_str() { "VOL_UP" => { enigo.key(Key::VolumeUp, Direction::Click).unwrap();