From e4d671deed1759d82bebe9bd571a61a197d1625f Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Sun, 19 Nov 2023 04:22:07 +0200 Subject: [PATCH] feat: long press esc --- desktop/src-tauri/src/main.rs | 8 +++----- desktop/src/App.tsx | 3 ++- web/src/App.tsx | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 06214af..e817004 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -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); @@ -31,6 +26,9 @@ fn press(controller: State<'_, Controller>, key: &str) { }, "F5" => { controller.key_down(Key::F5); + }, + "ESC" => { + controller.key_down(Key::Escape); } _ => {} } diff --git a/desktop/src/App.tsx b/desktop/src/App.tsx index c80e290..af1674f 100644 --- a/desktop/src/App.tsx +++ b/desktop/src/App.tsx @@ -13,7 +13,8 @@ enum Action { VOL_DN, PG_UP, PG_DN, - F5 + F5, + ESC } interface Message { diff --git a/web/src/App.tsx b/web/src/App.tsx index 7a12e42..8ccbad8 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -11,7 +11,8 @@ enum Action { VOL_DN, PG_UP, PG_DN, - F5 + F5, + ESC } interface Message { action: Action; @@ -30,11 +31,13 @@ function App() { const [conn, setConn] = useState(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)); } @@ -47,10 +50,14 @@ 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 }, []); @@ -58,6 +65,10 @@ function App() { sendMessage({ action: Action.F5 }) }); + const prevButtonBind = useLongPress(() => { + sendMessage({ action: Action.ESC }) + }); + if (loading) { return (
@@ -135,6 +146,7 @@ function App() {