From 37853163c854a70f1254ee4073d25aafb8c61c6f Mon Sep 17 00:00:00 2001 From: Shayne Hartford Date: Sat, 8 Jul 2023 16:15:28 -0400 Subject: [PATCH] 1.5.3 - Reload Config --- Cargo.lock | 122 ++++++++++++++++++++++++++---------------------- Cargo.toml | 2 +- README.md | 24 +++++++--- src/main.rs | 46 +++++++++++------- tauri.conf.json | 2 +- 5 files changed, 115 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1eb6acb..005aa34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,9 +317,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr", "serde", @@ -383,7 +383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "599aa35200ffff8f04c1925aa1acc92fa2e08874379ef42e210a80e527e60838" dependencies = [ "serde", - "toml 0.7.5", + "toml 0.7.6", ] [[package]] @@ -487,9 +487,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.10" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384e169cc618c613d5e3ca6404dda77a8685a63e08660dcc64abaf7da7cb0c7a" +checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" dependencies = [ "clap_builder", "clap_derive", @@ -498,9 +498,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.10" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef137bbe35aab78bdb468ccfba75a5f4d8321ae011d34063770780545176af2d" +checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" dependencies = [ "anstream", "anstyle", @@ -627,9 +627,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -860,7 +860,7 @@ checksum = "f7f1e82a60222fc67bfd50d752a9c89da5cce4c39ed39decc84a443b07bbd69a" dependencies = [ "cc", "rustc_version", - "toml 0.7.5", + "toml 0.7.6", "vswhom", "winreg 0.11.0", ] @@ -1445,9 +1445,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -1676,7 +1676,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] @@ -1689,12 +1689,12 @@ checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.1", - "rustix 0.38.2", + "hermit-abi 0.3.2", + "rustix 0.38.3", "windows-sys 0.48.0", ] @@ -1934,7 +1934,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -2123,7 +2123,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", ] @@ -2491,9 +2491,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" +checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" dependencies = [ "proc-macro2", "syn 2.0.23", @@ -2684,13 +2684,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick 1.0.2", "memchr", - "regex-syntax 0.7.2", + "regex-automata 0.3.2", + "regex-syntax 0.7.3", ] [[package]] @@ -2702,6 +2703,17 @@ dependencies = [ "regex-syntax 0.6.29", ] +[[package]] +name = "regex-automata" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +dependencies = [ + "aho-corasick 1.0.2", + "memchr", + "regex-syntax 0.7.3", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -2710,9 +2722,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" [[package]] name = "reqwest" @@ -2800,9 +2812,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.22" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8818fa822adcc98b18fedbb3632a6a33213c070556b5aa7c4c8cc21cff565c4c" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ "bitflags 1.3.2", "errno", @@ -2814,9 +2826,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.2" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabcb0461ebd01d6b79945797c27f8529082226cb630a9865a71870ff63532a4" +checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4" dependencies = [ "bitflags 2.3.3", "errno", @@ -2927,18 +2939,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.166" +version = "1.0.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" +checksum = "7daf513456463b42aa1d94cff7e0c24d682b429f020b9afa4f5ba5c40a22b237" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.166" +version = "1.0.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" +checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9" dependencies = [ "proc-macro2", "quote", @@ -2947,9 +2959,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" dependencies = [ "itoa 1.0.8", "ryu", @@ -2958,9 +2970,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0a21fba416426ac927b1691996e82079f8b6156e920c85345f135b2e9ba2de" +checksum = "1d89a8107374290037607734c0b73a85db7ed80cae314b3c5791f192a496e731" dependencies = [ "proc-macro2", "quote", @@ -3097,9 +3109,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -3254,7 +3266,7 @@ dependencies = [ "cfg-expr 0.15.3", "heck 0.4.1", "pkg-config", - "toml 0.7.5", + "toml 0.7.6", "version-compare 0.1.1", ] @@ -3523,7 +3535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5993dc129e544393574288923d1ec447c857f3f644187f4fbf7d9a875fbfc4fb" dependencies = [ "embed-resource", - "toml 0.7.5", + "toml 0.7.6", ] [[package]] @@ -3536,7 +3548,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.22", + "rustix 0.37.23", "windows-sys 0.48.0", ] @@ -3577,18 +3589,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", @@ -3711,9 +3723,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebafdf5ad1220cb59e7d17cf4d2c72015297b75b19a10472f99b89225089240" +checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" dependencies = [ "serde", "serde_spanned", @@ -3732,9 +3744,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.11" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" dependencies = [ "indexmap 2.0.0", "serde", @@ -4470,9 +4482,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" dependencies = [ "memchr", ] @@ -4498,11 +4510,11 @@ dependencies = [ [[package]] name = "wooting-profile-switcher" -version = "1.5.2" +version = "1.5.3" dependencies = [ "active-win-pos-rs", "anyhow", - "clap 4.3.10", + "clap 4.3.11", "ctrlc", "dirs", "regex", diff --git a/Cargo.toml b/Cargo.toml index 4b0fe5f..45cba8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wooting-profile-switcher" description = "Automatically switch Wooting keyboard profiles based on focused window" -version = "1.5.2" +version = "1.5.3" authors = ["Shayne Hartford "] edition = "2021" readme = "README.md" diff --git a/README.md b/README.md index 61355b5..1d9f096 100644 --- a/README.md +++ b/README.md @@ -17,23 +17,39 @@ Automatically switch Wooting keyboard profiles based on focused window ## System Tray Icon -The system tray icon allows you to pause/resume, quit, and set the active profile +The system tray icon allows you to pause/resume, reload, quit, and set the active profile ## Configuration -The config file is generated on first run with the following format +The config file is generated on first-run in the following location and format + +| Platform | Location | +|----------|------------------------------------------| +| Portable | Same location as the binary | +| Windows | `C:\Users\...\AppData\Roaming` | +| macOS | `/Users/.../Library/Application Support` | +| Linux | `/home/.../.config` | ```json { + // The fallback profile to use when no match is found (optional) "fallback_profile_index": null, + // Sleep duration for the loop checking the active window "loop_sleep_ms": 250, + // Sleep duration between sending Wooting USB commands "send_sleep_ms": 250, + // List of rule objects "rules": [ { + // The official app name (optional) "app_name": null, + // The running process name (optional) "process_name": "Isaac", + // The running process path (optional) "process_path": null, + // The profile to switch to when a match is found for this rule (0-3) "profile_index": 1, + // The running window title (optional) "title": null }, { @@ -47,10 +63,6 @@ The config file is generated on first run with the following format } ``` -The `fallback_profile_index` variable allows you to set a fallback profile index to use when no match is found. -The `sleep_ms` variables allow you to customize the duration between checking the active process, and duration between sending Wooting USB commands. -The `rules` variable is a list of rules that supports [Wildcard] and [Regex] for `app_name`, `process_name`, `process_path` and `title` variables. - ### Examples: #### Matching a window title with a date variable diff --git a/src/main.rs b/src/main.rs index ad33d98..bd4b7eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,13 +63,13 @@ async fn main() -> Result<()> { })); let args = Arc::new(RwLock::new(Args::parse())); - let config = Arc::new(Config::load()?); + let config = Arc::new(RwLock::new(Config::load()?)); // Poll the active window in a background task let args_task = args.clone(); let config_task = config.clone(); tokio::spawn(async move { - poll_active_window(args_task, &config_task).unwrap(); + poll_active_window(args_task, config_task).unwrap(); }); // Create the system tray menu and add the MENU_ITEMS @@ -88,9 +88,10 @@ async fn main() -> Result<()> { SystemTray::new().with_menu( system_tray_menu .add_native_item(SystemTrayMenuItem::Separator) - .add_item(CustomMenuItem::new(String::from("pause"), "Pause")) + .add_item(CustomMenuItem::new(String::from("pause"), "Pause Scanning")) + .add_item(CustomMenuItem::new(String::from("reload"), "Reload Config")) .add_native_item(SystemTrayMenuItem::Separator) - .add_item(CustomMenuItem::new(String::from("quit"), "Quit")), + .add_item(CustomMenuItem::new(String::from("quit"), "Quit Program")), ), ) .on_system_tray_event(move |app, event| { @@ -100,26 +101,34 @@ async fn main() -> Result<()> { "quit" => { std::process::exit(0); } + "reload" => { + let mut config_write_lock = config_clone.write().unwrap(); + *config_write_lock = Config::load().expect("Failed to reload config"); + } "pause" => { let paused = args_clone.read().unwrap().paused; - let title = if paused { "Pause" } else { "Resume" }; + let title = if paused { + "Pause Scanning" + } else { + "Resume Scanning" + }; args_clone.write().unwrap().paused = !paused; item_handle.set_title(title).unwrap(); } "digital" => { - set_active_profile_index(0, config_clone.send_sleep_ms); + set_active_profile_index(0, config_clone.read().unwrap().send_sleep_ms); args_clone.write().unwrap().profile_index = Some(0); } "analog_1" => { - set_active_profile_index(1, config_clone.send_sleep_ms); + set_active_profile_index(1, config_clone.read().unwrap().send_sleep_ms); args_clone.write().unwrap().profile_index = Some(1); } "analog_2" => { - set_active_profile_index(2, config_clone.send_sleep_ms); + set_active_profile_index(2, config_clone.read().unwrap().send_sleep_ms); args_clone.write().unwrap().profile_index = Some(2); } "analog_3" => { - set_active_profile_index(3, config_clone.send_sleep_ms); + set_active_profile_index(3, config_clone.read().unwrap().send_sleep_ms); args_clone.write().unwrap().profile_index = Some(3); } _ => {} @@ -138,7 +147,7 @@ async fn main() -> Result<()> { let args_clone = args.clone(); let config_clone = config.clone(); tokio::spawn(async move { - poll_args_profile(args_clone, &config_clone, &app_clone); + poll_args_profile(args_clone, config_clone, &app_clone); }); }); @@ -146,9 +155,9 @@ async fn main() -> Result<()> { } /// Poll the args for profile index and update the system tray menu -fn poll_args_profile(args: Arc>, config: &Config, app: &AppHandle) { +fn poll_args_profile(args: Arc>, config: Arc>, app: &AppHandle) { loop { - std::thread::sleep(Duration::from_millis(config.loop_sleep_ms)); + std::thread::sleep(Duration::from_millis(config.read().unwrap().loop_sleep_ms)); if let Some(profile_index) = args.read().unwrap().profile_index { MENU_ITEMS.iter().enumerate().for_each(|(i, (id, _title))| { @@ -162,7 +171,7 @@ fn poll_args_profile(args: Arc>, config: &Config, app: &AppHandle) } /// Poll the active window for matching rules and apply the profile -fn poll_active_window(args: Arc>, config: &Config) -> Result<()> { +fn poll_active_window(args: Arc>, config: Arc>) -> Result<()> { let device_info = unsafe { if !wooting_rgb_kbd_connected() { println!("Keyboard not connected."); @@ -174,7 +183,7 @@ fn poll_active_window(args: Arc>, config: &Config) -> Result<()> { }; if let Some(profile_index) = args.read().unwrap().profile_index { - set_active_profile_index(profile_index, config.send_sleep_ms); + set_active_profile_index(profile_index, config.read().unwrap().send_sleep_ms); return Ok(()); } @@ -183,7 +192,7 @@ fn poll_active_window(args: Arc>, config: &Config) -> Result<()> { args.write().unwrap().profile_index = Some(last_profile_index); loop { - std::thread::sleep(Duration::from_millis(config.loop_sleep_ms)); + std::thread::sleep(Duration::from_millis(config.read().unwrap().loop_sleep_ms)); if args.read().unwrap().paused { continue; @@ -216,10 +225,11 @@ fn poll_active_window(args: Arc>, config: &Config) -> Result<()> { }; println!("Active Process State: {active_process_state:#?}"); - let profile_index = match find_match(active_process_state, &config.rules) { + let profile_index = match find_match(active_process_state, &config.read().unwrap().rules) { Some(profile_index) => profile_index, None => { - if let Some(fallback_profile_index) = config.fallback_profile_index { + if let Some(fallback_profile_index) = config.read().unwrap().fallback_profile_index + { fallback_profile_index } else { continue; @@ -234,7 +244,7 @@ fn poll_active_window(args: Arc>, config: &Config) -> Result<()> { } println!("Process Profile Index: {}", profile_index); - set_active_profile_index(profile_index, config.send_sleep_ms); + set_active_profile_index(profile_index, config.read().unwrap().send_sleep_ms); args.write().unwrap().profile_index = Some(profile_index); } } diff --git a/tauri.conf.json b/tauri.conf.json index 724c3bc..7a47c5d 100644 --- a/tauri.conf.json +++ b/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "WootingProfileSwitcher", - "version": "1.5.2" + "version": "1.5.3" }, "tauri": { "allowlist": {