import { App } from '@capacitor/app' import { StatusBar, Style } from '@capacitor/status-bar' import { SplashScreen } from '@capacitor/splash-screen' import { Haptics, ImpactStyle } from '@capacitor/haptics' import { Capacitor } from '@capacitor/core' export default defineNuxtPlugin((nuxtApp) => { // Csak natív platformon fut if (!Capacitor.isNativePlatform()) { return } const router = useRouter() // Android hardware back button kezelése App.addListener('backButton', async ({ canGoBack }) => { // Ha van history, navigáljunk vissza if (router.currentRoute.value.path !== '/' && window.history.length > 1) { router.back() } else { // Ha a főoldalon vagyunk, kérdezzük meg hogy ki akar-e lépni // vagy minimalizáljuk az appot App.minimizeApp() } }) // Status bar beállítása const setupStatusBar = async () => { try { // Sötét ikonok világos háttérrel (vagy fordítva dark mode-ban) await StatusBar.setStyle({ style: Style.Dark }) // Android-on beállíthatjuk a háttérszínt if (Capacitor.getPlatform() === 'android') { await StatusBar.setBackgroundColor({ color: '#262626' }) // neutral-800 } } catch (e) { console.warn('StatusBar setup error:', e) } } // Splash screen elrejtése amikor az app betöltődött const hideSplash = async () => { try { await SplashScreen.hide({ fadeOutDuration: 300 }) } catch (e) { console.warn('SplashScreen hide error:', e) } } // App mounted hook nuxtApp.hooks.hook('app:mounted', async () => { await setupStatusBar() // Kis késleltetés hogy a UI renderelődjön setTimeout(() => { hideSplash() }, 500) }) // Haptics helper függvények exportálása return { provide: { haptics: { // Könnyű rezgés (pl. gomb kattintás) light: () => Haptics.impact({ style: ImpactStyle.Light }), // Közepes rezgés (pl. toggle váltás) medium: () => Haptics.impact({ style: ImpactStyle.Medium }), // Erős rezgés (pl. sikeres művelet) heavy: () => Haptics.impact({ style: ImpactStyle.Heavy }), // Szelekció rezgés selection: () => Haptics.selectionStart(), // Értesítés rezgések success: () => Haptics.notification({ type: 'SUCCESS' as any }), warning: () => Haptics.notification({ type: 'WARNING' as any }), error: () => Haptics.notification({ type: 'ERROR' as any }), } } } })