Skip to content

Commit

Permalink
feat: long press esc
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 19, 2023
1 parent a4cda6b commit e4d671d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 3 additions & 5 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ use enigo::*;
use std::sync::Mutex;
use tauri::State;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

struct Controller(Mutex<Enigo>);

Expand All @@ -31,6 +26,9 @@ fn press(controller: State<'_, Controller>, key: &str) {
},
"F5" => {
controller.key_down(Key::F5);
},
"ESC" => {
controller.key_down(Key::Escape);
}
_ => {}
}
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum Action {
VOL_DN,
PG_UP,
PG_DN,
F5
F5,
ESC
}

interface Message {
Expand Down
16 changes: 14 additions & 2 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum Action {
VOL_DN,
PG_UP,
PG_DN,
F5
F5,
ESC
}
interface Message {
action: Action;
Expand All @@ -30,11 +31,13 @@ function App() {
const [conn, setConn] = useState<DataConnection | null>(null);

function sendMessage(data: Message) {
console.log('sending => ', data)
navigator.vibrate(60)
if (!noSleep.isEnabled) {
console.log('No sleep enabled')
noSleep.enable()
}

conn?.send(JSON.stringify(data));
}

Expand All @@ -47,17 +50,25 @@ function App() {
console.log("connecting to ", address);
peer.on("open", () => {
const connection = peer.connect(address!);
setLoading(false);
connection.on('open', () => {
setLoading(false);
})
setConn(connection);
});



// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const nextButtonBind = useLongPress(() => {
sendMessage({ action: Action.F5 })
});

const prevButtonBind = useLongPress(() => {
sendMessage({ action: Action.ESC })
});

if (loading) {
return (
<div className="flex flex-col gap-5 w-[100vw] h-[100vh] items-center justify-center">
Expand Down Expand Up @@ -135,6 +146,7 @@ function App() {
</svg>
</button>
<button
{...prevButtonBind()}
onClick={() => sendMessage({ action: Action.PG_UP })} // prev
className="btn btn-circle w-[80px] h-[80px]"
>
Expand Down

0 comments on commit e4d671d

Please sign in to comment.