From 816c7a65824947b00e3d597dcde1fbac4a089aa1 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Mon, 10 Nov 2025 04:23:45 +0000 Subject: [PATCH] Fix daily notification plugin integration and bundling - Change from dynamic to static imports for @timesafari/daily-notification-plugin - Remove plugin from external dependencies in vite.config.capacitor.mts to ensure proper bundling - Add debug logging to DailyNotificationSection for troubleshooting - Update package-lock.json with latest dependencies --- package-lock.json | 2 +- .../DailyNotificationSection.vue | 11 +++++- .../platforms/CapacitorPlatformService.ts | 36 +++++-------------- vite.config.capacitor.mts | 6 ++-- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 93b98785..981ff658 100644 --- a/package-lock.json +++ b/package-lock.json @@ -152,7 +152,7 @@ }, "../daily-notification-plugin": { "name": "@timesafari/daily-notification-plugin", - "version": "1.0.1", + "version": "1.0.3", "license": "MIT", "workspaces": [ "packages/*" diff --git a/src/components/notifications/DailyNotificationSection.vue b/src/components/notifications/DailyNotificationSection.vue index 9858014d..39f84962 100644 --- a/src/components/notifications/DailyNotificationSection.vue +++ b/src/components/notifications/DailyNotificationSection.vue @@ -357,6 +357,10 @@ export default class DailyNotificationSection extends Vue { this.loading = true; const platformService = PlatformServiceFactory.getInstance(); + logger.debug( + "[DailyNotificationSection] Checking notification support...", + ); + // Check if notifications are supported on this platform // This also verifies plugin availability (returns null if plugin unavailable) const status = await platformService.getDailyNotificationStatus(); @@ -364,11 +368,16 @@ export default class DailyNotificationSection extends Vue { // Notifications not supported or plugin unavailable - don't initialize this.notificationsSupported = false; logger.warn( - "[DailyNotificationSection] Notifications not supported or plugin unavailable", + "[DailyNotificationSection] Notifications not supported or plugin unavailable - section will be hidden", ); return; } + logger.debug( + "[DailyNotificationSection] Notifications supported, status:", + status, + ); + this.notificationsSupported = true; this.notificationStatus = status; diff --git a/src/services/platforms/CapacitorPlatformService.ts b/src/services/platforms/CapacitorPlatformService.ts index 4b49d123..97a8a315 100644 --- a/src/services/platforms/CapacitorPlatformService.ts +++ b/src/services/platforms/CapacitorPlatformService.ts @@ -13,6 +13,7 @@ import { CapacitorSQLite, DBSQLiteValues, } from "@capacitor-community/sqlite"; +import { DailyNotification } from "@timesafari/daily-notification-plugin"; import { runMigrations } from "@/db-sql/migration"; import { QueryExecResult } from "@/interfaces/database"; @@ -1421,9 +1422,8 @@ export class CapacitorPlatformService */ async getDailyNotificationStatus(): Promise { try { - // Dynamic import to avoid build issues if plugin unavailable - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" + logger.debug( + "[CapacitorPlatformService] Getting daily notification status...", ); const pluginStatus = await DailyNotification.getNotificationStatus(); @@ -1463,10 +1463,16 @@ export class CapacitorPlatformService }, }; } catch (error) { + const errorMessage = + error instanceof Error ? error.message : String(error); logger.error( "[CapacitorPlatformService] Failed to get notification status:", + errorMessage, error, ); + logger.warn( + "[CapacitorPlatformService] Daily notification section will be hidden - plugin may not be installed or available", + ); return null; } } @@ -1477,10 +1483,6 @@ export class CapacitorPlatformService */ async checkNotificationPermissions(): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - const permissions = await DailyNotification.checkPermissions(); // Log the raw permission state for debugging @@ -1530,10 +1532,6 @@ export class CapacitorPlatformService */ async requestNotificationPermissions(): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - logger.info( `[CapacitorPlatformService] Requesting notification permissions...`, ); @@ -1571,10 +1569,6 @@ export class CapacitorPlatformService */ async scheduleDailyNotification(options: ScheduleOptions): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - await DailyNotification.scheduleDailyNotification({ time: options.time, title: options.title, @@ -1601,10 +1595,6 @@ export class CapacitorPlatformService */ async cancelDailyNotification(): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - await DailyNotification.cancelAllNotifications(); logger.info("[CapacitorPlatformService] Cancelled daily notification"); @@ -1670,10 +1660,6 @@ export class CapacitorPlatformService config: NativeFetcherConfig, ): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - // Step 1: Get activeDid from database (single source of truth) // This ensures we're using the correct user identity for authentication const activeIdentity = await this.getActiveIdentity(); @@ -1740,10 +1726,6 @@ export class CapacitorPlatformService */ async updateStarredPlans(plans: { planIds: string[] }): Promise { try { - const { DailyNotification } = await import( - "@timesafari/daily-notification-plugin" - ); - await DailyNotification.updateStarredPlans({ planIds: plans.planIds, }); diff --git a/vite.config.capacitor.mts b/vite.config.capacitor.mts index e3bfd9f1..27a722a4 100644 --- a/vite.config.capacitor.mts +++ b/vite.config.capacitor.mts @@ -10,10 +10,8 @@ export default defineConfig(async () => { ...baseConfig.build, rollupOptions: { ...baseConfig.build?.rollupOptions, - // Externalize Capacitor plugins that are bundled natively - external: [ - "@timesafari/daily-notification-plugin" - ], + // Note: @timesafari/daily-notification-plugin is NOT externalized + // because it needs to be bundled for dynamic imports to work in Capacitor WebView output: { ...baseConfig.build?.rollupOptions?.output, }