From ea9837935e3d6cbb93154d9b662232e62fd02481 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Tue, 6 Aug 2024 12:17:56 +0800 Subject: [PATCH] feat: add Shortcut key and auto check pause for pause game --- apps/client/components/main/LearningTimer.vue | 10 ++- apps/client/components/main/Tool.vue | 44 ++++++------- apps/client/composables/main/useGamePause.ts | 66 +++++++++++++++++++ apps/client/composables/user/shortcutKey.ts | 2 + apps/client/pages/User/Setting.vue | 4 ++ 5 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 apps/client/composables/main/useGamePause.ts diff --git a/apps/client/components/main/LearningTimer.vue b/apps/client/components/main/LearningTimer.vue index c3d399e2..68448df1 100644 --- a/apps/client/components/main/LearningTimer.vue +++ b/apps/client/components/main/LearningTimer.vue @@ -17,12 +17,15 @@ import { computed, onMounted, onUnmounted, ref, watch } from "vue"; import { useLearningTimeTracker } from "~/composables/main/learningTimeTracker"; +import { useGamePause } from "~/composables/main/useGamePause"; import { useGameStore } from "~/store/game"; const { $anime } = useNuxtApp(); const gameStore = useGameStore(); -const { totalSeconds, startTracking, stopTracking } = useLearningTimeTracker(); +const { pauseGame, enableAutoPauseCheck, disableAutoPauseCheck } = useGamePause(); + +const { totalSeconds, stopTracking } = useLearningTimeTracker(); const clockIcon = ref(null); const formattedTime = computed(() => { @@ -71,8 +74,7 @@ function handleVisibilityChange() { if (document.hidden) { stopTracking(); - } else { - startTracking(); + pauseGame(); } } @@ -87,10 +89,12 @@ function handleBeforeunload() { onMounted(() => { document.addEventListener("visibilitychange", handleVisibilityChange); window.addEventListener("beforeunload", handleBeforeunload); + enableAutoPauseCheck(); }); onUnmounted(() => { document.removeEventListener("visibilitychange", handleVisibilityChange); window.removeEventListener("beforeunload", handleBeforeunload); + disableAutoPauseCheck(); }); diff --git a/apps/client/components/main/Tool.vue b/apps/client/components/main/Tool.vue index a2e484f1..09c0567b 100644 --- a/apps/client/components/main/Tool.vue +++ b/apps/client/components/main/Tool.vue @@ -29,8 +29,8 @@
@@ -65,36 +65,40 @@ confirm-btn-text="确认" @confirm="handleTipConfirm" /> + {{ showGamePauseModal }}