@@ -31,6 +31,10 @@ const settingsOpen = ref(false)
3131const storeOpen = ref (false )
3232const savesOpen = ref (false )
3333const helpOpen = ref (false )
34+ // 主界面返回键二次确认:首次按只飘字提示,2s 内再按才真退出,避免遥控器误触退出。
35+ const exitHintVisible = ref (false )
36+ let exitArmedAt = 0
37+ let exitHintTimer: ReturnType <typeof setTimeout > | null = null
3438
3539// 模态(游戏库/设置/存档列表/快捷键)打开时锁住游戏输入,改由模态接管手柄/键盘导航。
3640const inputLocked = computed (
@@ -157,15 +161,31 @@ function onSystemAction(action: string) {
157161 }
158162}
159163
160- // 返回键分级返回:面板打开→关面板;游戏中→停止游戏回主界面;主界面→直接退出 app 。
164+ // 返回键分级返回:面板打开→关面板;游戏中→停止游戏回主界面;主界面→飘字+二次确认才退出 。
161165// 汇聚遥控器/手柄 BACK(经各 useRemoteNav.onBack 与 NesScreen 的 'back')与物理返回键(popstate)。
166+ const EXIT_CONFIRM_MS = 2000
162167function handleBack() {
163168 if (helpOpen .value ) helpOpen .value = false
164169 else if (settingsOpen .value ) settingsOpen .value = false
165170 else if (savesOpen .value ) savesOpen .value = false
166171 else if (storeOpen .value ) storeOpen .value = false
167172 else if (romName .value ) stopRom ()
168- else void exitApp ()
173+ else {
174+ const now = Date .now ()
175+ if (now - exitArmedAt < EXIT_CONFIRM_MS ) {
176+ if (exitHintTimer ) { clearTimeout (exitHintTimer ); exitHintTimer = null }
177+ exitHintVisible .value = false
178+ void exitApp ()
179+ return
180+ }
181+ exitArmedAt = now
182+ exitHintVisible .value = true
183+ if (exitHintTimer ) clearTimeout (exitHintTimer )
184+ exitHintTimer = setTimeout (() => {
185+ exitHintVisible .value = false
186+ exitHintTimer = null
187+ }, EXIT_CONFIRM_MS )
188+ }
169189}
170190
171191// 退出 app:Tauri 用 process 插件 exit(0);浏览器预览降级 window.close()(失败静默)。
@@ -199,6 +219,7 @@ onBeforeUnmount(() => {
199219 if (typeof window !== ' undefined' ) {
200220 window .removeEventListener (' popstate' , onPopState )
201221 }
222+ if (exitHintTimer ) clearTimeout (exitHintTimer )
202223})
203224 </script >
204225
@@ -259,6 +280,10 @@ onBeforeUnmount(() => {
259280 <p v-if =" !romName" class =" hint" >打开本地 .nes 文件开始游戏</p >
260281 </main >
261282
283+ <Transition name="toast">
284+ <div v-if =" exitHintVisible" class =" exit-hint" role =" status" >再按一次返回键退出</div >
285+ </Transition >
286+
262287 <footer class =" footer" >
263288 <span class =" keys" >键盘 {{ keyHint }}</span >
264289 <button class =" link-btn" @click =" helpOpen = true" >查看所有快捷键</button >
@@ -411,4 +436,27 @@ body {
411436.link-btn :hover {
412437 text-decoration : underline ;
413438}
439+ .exit-hint {
440+ position : fixed ;
441+ left : 50% ;
442+ bottom : 80px ;
443+ transform : translateX (-50% );
444+ padding : 10px 20px ;
445+ border-radius : 22px ;
446+ background : rgba (0 , 0 , 0 , 0.82 );
447+ color : #fff ;
448+ font-size : 14px ;
449+ letter-spacing : 0.3px ;
450+ box-shadow : 0 4px 16px rgba (0 , 0 , 0 , 0.35 );
451+ pointer-events : none ;
452+ z-index : 1000 ;
453+ }
454+ .toast-enter-active ,
455+ .toast-leave-active {
456+ transition : opacity 0.18s ease ;
457+ }
458+ .toast-enter-from ,
459+ .toast-leave-to {
460+ opacity : 0 ;
461+ }
414462 </style >
0 commit comments