From 0c991f716362acf3251a720eb9ed7f91d911ef9b Mon Sep 17 00:00:00 2001 From: Backpack Date: Tue, 22 Jul 2025 23:42:18 +0800 Subject: [PATCH] fix rock mode --- src/hand_landmark/gesture_handler.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/hand_landmark/gesture_handler.ts b/src/hand_landmark/gesture_handler.ts index afe4f2c..51471f9 100644 --- a/src/hand_landmark/gesture_handler.ts +++ b/src/hand_landmark/gesture_handler.ts @@ -500,6 +500,8 @@ export class GestureHandler { * 获取指定手指的指尖 landmark * fingerIndex: 0=拇指, 1=食指, 2=中指, ... */ + private lastModeSwitchTime: number = 0; + private readonly MODE_SWITCH_INTERVAL = 3000; // 3秒 private getFingerTip(hand: HandInfo, fingerIndex: number) { if (!hand) return null; @@ -519,9 +521,14 @@ export class GestureHandler { this.previousGestureCount = 1; } - const app_store = use_app_store(); - if (gesture === HandGesture.ROCK_SWITCH_MODE) { + + const app_store = use_app_store(); + if (gesture === HandGesture.ROCK_SWITCH_MODE) { + const now = Date.now(); + if (now - this.lastModeSwitchTime >= this.MODE_SWITCH_INTERVAL) { + this.lastModeSwitchTime = now; + if (app_store.mode === 'normal') { app_store.mode = 'music'; app_store.sub_window_info("🎵 切换到音乐模式"); @@ -529,9 +536,9 @@ export class GestureHandler { app_store.mode = 'normal'; app_store.sub_window_info("💼 切换到普通模式"); } - return; // 切换后不继续处理其他手势 } - + return; // 不管有没有切换,都返回,不再处理其他手势 + }