From 9b815300124f49a79f15e57c4bb6cde443c9a723 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sun, 17 May 2026 16:33:06 +1000 Subject: [PATCH] feat: Lazy-load Capacitor local notifications to optimize runtime loading --- src/app/utils/tauri.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/utils/tauri.ts b/src/app/utils/tauri.ts index c8f3545..16b3199 100644 --- a/src/app/utils/tauri.ts +++ b/src/app/utils/tauri.ts @@ -119,6 +119,15 @@ let notificationTapCallback: ((path: string) => void) | null = null; const ANDROID_NOTIFICATION_SMALL_ICON = 'ic_stat_paarrot'; const ANDROID_NOTIFICATION_ICON_COLOR = '#FF8A00'; +type CapacitorLocalNotificationsModule = typeof import('@capacitor/local-notifications'); + +/** + * Lazy-load Capacitor local notifications at runtime only. + * Vite must not pre-resolve this module because some desktop builds do not include it. + */ +const importCapacitorLocalNotifications = async (): Promise => + import(/* @vite-ignore */ '@capacitor/local-notifications'); + /** * Bring the Tauri window to the front and focus it */ @@ -196,7 +205,7 @@ export const setupNotificationTapListener = async (onTap: (path: string) => void if (isCapacitorNative()) { try { - const { LocalNotifications } = await import('@capacitor/local-notifications'); + const { LocalNotifications } = await importCapacitorLocalNotifications(); await LocalNotifications.addListener('localNotificationActionPerformed', async (event: any) => { await focusWindow(); const path = event?.notification?.extra?.path; @@ -336,7 +345,7 @@ const ensureCapacitorNotificationChannel = async (): Promise => { if (notificationChannelCreated || !isAndroid()) return; try { - const { LocalNotifications } = await import('@capacitor/local-notifications'); + const { LocalNotifications } = await importCapacitorLocalNotifications(); await LocalNotifications.createChannel({ id: 'messages', name: 'Messages', @@ -365,7 +374,7 @@ export const requestSystemNotificationPermission = async (): Promise => if (isCapacitorNative()) { try { - const { LocalNotifications } = await import('@capacitor/local-notifications'); + const { LocalNotifications } = await importCapacitorLocalNotifications(); let perm = await LocalNotifications.checkPermissions(); if (perm.display !== 'granted') { perm = await LocalNotifications.requestPermissions(); @@ -385,7 +394,7 @@ export const requestSystemNotificationPermission = async (): Promise => export const getSystemNotificationPermissionState = async (): Promise => { if (isCapacitorNative()) { try { - const { LocalNotifications } = await import('@capacitor/local-notifications'); + const { LocalNotifications } = await importCapacitorLocalNotifications(); const perm = await LocalNotifications.checkPermissions(); return perm.display === 'granted' ? 'granted' : 'prompt'; } catch (err) { @@ -471,7 +480,7 @@ export const sendNotification = async (options: { if (isCapacitorNative()) { try { - const { LocalNotifications } = await import('@capacitor/local-notifications'); + const { LocalNotifications } = await importCapacitorLocalNotifications(); let perm = await LocalNotifications.checkPermissions(); if (perm.display !== 'granted') { perm = await LocalNotifications.requestPermissions();