Skip to content

Commit

Permalink
tokio mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 19, 2023
1 parent 1357cfa commit 5bc036a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tauri-build = { version = "1.4", features = [] }
[dependencies]
tauri = { version = "1.4", features = ["shell-open"] }
enigo = { version = "0.1.3" }
tokio = "1.34.0"

[target.'cfg(any(windows, target_os = "macos"))'.dependencies]
window-shadows = "0.2.2"
Expand Down
11 changes: 6 additions & 5 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use window_shadows::set_shadow;

use tauri::Manager;
use enigo::*;
use std::sync::{Arc,Mutex};
use tauri::State;
use tokio::sync::Mutex;


struct Controller(Arc<Mutex<Enigo>>);
struct Controller(Mutex<Enigo>);

#[tauri::command]
fn press(controller: State<'_, Controller>, key: &str) {
let mut controller = (&controller.0).lock().unwrap();
async fn press(controller: State<'_, Controller>, key: &str) -> Result<(), String> {
let mut controller = (&controller.0).lock().await;
match key {
"VOL_UP" => {
controller.key_down(Key::VolumeUp);
Expand All @@ -36,6 +36,7 @@ fn press(controller: State<'_, Controller>, key: &str) {
}
_ => {}
}
Ok(())
}


Expand All @@ -51,7 +52,7 @@ fn main() {

Ok(())
})
.manage(Controller(Arc::new(Mutex::new(controller))))
.manage(Controller(Mutex::new(controller)))
.invoke_handler(tauri::generate_handler![press])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down

0 comments on commit 5bc036a

Please sign in to comment.