// Capacitor 네이티브(안드로이드) 통합. 웹에서는 no-op. import { Capacitor } from '@capacitor/core' import { App as CapApp } from '@capacitor/app' import { useUiStore } from '@/stores/ui' import { appLock } from '@/composables/appLock' export function setupCapacitor(router) { if (!Capacitor.isNativePlatform()) return const ui = useUiStore() let exitArmed = false let exitTimer = null // 안드로이드 하드웨어 뒤로가기 우선순위: // 1) 잠금 화면이면 우회 불가 → 종료 // 2) 열린 전역 오버레이(회원가입/로그인/비번/사이드바) 닫기 // 3) 화면 뒤로 // 4) 최상위에서 한 번 더 누르면 종료(실수 종료 방지) CapApp.addListener('backButton', ({ canGoBack }) => { if (appLock.state.locked) { CapApp.exitApp(); return } if (ui.signupOpen) { ui.closeSignup(); return } if (ui.loginOpen) { ui.closeLogin(); return } if (ui.passwordOpen) { ui.closePassword(); return } if (ui.sidebarOpen) { ui.closeSidebar(); return } if (canGoBack && window.history.length > 1) { router.back(); return } if (exitArmed) { CapApp.exitApp(); return } exitArmed = true window.dispatchEvent(new CustomEvent('app:toast', { detail: '한 번 더 누르면 종료됩니다' })) clearTimeout(exitTimer) exitTimer = setTimeout(() => { exitArmed = false }, 2000) }) // 네이티브 표시용 클래스 (safe-area 등 스타일 분기) document.documentElement.classList.add('is-native') }