Skip to content

Commit

Permalink
fix macos
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 19, 2023
1 parent 2017b17 commit deb7562
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 70 deletions.
13 changes: 0 additions & 13 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion desktop/package-lock.json

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

1 change: 1 addition & 0 deletions desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@tauri-apps/api": "^1.4.0",
"@uidotdev/usehooks": "^2.4.1",
"peerjs": "^1.5.1",
"qr-code-styling": "^1.6.0-rc.1",
"react": "^18.2.0",
Expand Down
1 change: 0 additions & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ tauri-build = { version = "1.4", features = [] }
[dependencies]
tauri = { version = "1.4", features = ["shell-open"] }
enigo = { version = "0.1.3" }
tokio = { version = "1.34.0", features = ["macros"] }


[target.'cfg(any(windows, target_os = "macos"))'.dependencies]
Expand Down
90 changes: 35 additions & 55 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,45 @@ use window_shadows::set_shadow;

use tauri::Manager;
use enigo::*;
use tauri::State;
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::mpsc;
use tokio;

struct Controller(UnboundedSender<String>);

#[tauri::command]
async fn press(controller: State<'_, Controller>, key: String) -> Result<(), String> {
controller.0.send(key.to_string()).unwrap_or_default();
Ok(())
}

#[tokio::main]
async fn main() {
async fn press(key: String) -> Result<(), String> {
let mut controller = Enigo::new();
let (ch_tx, mut ch_rx) = mpsc::unbounded_channel::<String>();

tokio::spawn(async move {
// application specific stuff...
// send commands to ch_tx
// ch_tx.send(EnigoCommand::KeyClick(Key::Layout('E')));

while let Some(key) = ch_rx.recv().await {
match key.as_str() {
"VOL_UP" => {
controller.key_down(Key::VolumeUp);
},
"VOL_DN" => {
controller.key_down(Key::VolumeDown);
},
"PG_UP" => {
controller.key_down(Key::PageUp);
},
"PG_DN" => {
controller.key_down(Key::PageDown);
},
"F5" => {
controller.key_down(Key::F5);
},
"ESC" => {
controller.key_down(Key::Escape);
}
_ => {}
}
match key.as_str() {
"VOL_UP" => {
controller.key_down(Key::VolumeUp);
},
"VOL_DN" => {
controller.key_down(Key::VolumeDown);
},
"PG_UP" => {
controller.key_down(Key::PageUp);
},
"PG_DN" => {
controller.key_down(Key::PageDown);
},
"F5" => {
controller.key_down(Key::F5);
},
"ESC" => {
controller.key_down(Key::Escape);
}
});
_ => {}
}
Ok(())
}

fn main() {
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();

#[cfg(any(windows, target_os = "macos"))]
set_shadow(&window, true).unwrap();

Ok(())
})
.manage(Controller(ch_tx))
.invoke_handler(tauri::generate_handler![press])
.run(tauri::generate_context!())
.expect("error while running tauri application");
.setup(|app| {
let window = app.get_window("main").unwrap();

#[cfg(any(windows, target_os = "macos"))]
set_shadow(&window, true).unwrap();

Ok(())
})
.invoke_handler(tauri::generate_handler![press])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

0 comments on commit deb7562

Please sign in to comment.