diff --git a/test-apps/ios-test-app/App/App/public/capacitor_plugins.js b/test-apps/ios-test-app/App/App/public/capacitor_plugins.js index ad9b9da..c347aa3 100644 --- a/test-apps/ios-test-app/App/App/public/capacitor_plugins.js +++ b/test-apps/ios-test-app/App/App/public/capacitor_plugins.js @@ -1,75 +1,99 @@ // Capacitor Plugins Registration // This file registers the DailyNotification plugin for iOS +// Methods bridge to native Swift implementation via Capacitor's native bridge -window.Capacitor = window.Capacitor || {}; -window.Capacitor.Plugins = window.Capacitor.Plugins || {}; - -// Register DailyNotification plugin with method stubs -// Methods will be bridged to native Swift implementation -window.Capacitor.Plugins.DailyNotification = window.Capacitor.Plugins.DailyNotification || { - // Permission methods - checkPermissionStatus: function() { - return window.Capacitor.nativePromise('DailyNotification', 'checkPermissionStatus', {}); - }, - requestNotificationPermissions: function() { - return window.Capacitor.nativePromise('DailyNotification', 'requestNotificationPermissions', {}); - }, - checkPermissions: function() { - return window.Capacitor.nativePromise('DailyNotification', 'checkPermissions', {}); - }, - requestPermissions: function() { - return window.Capacitor.nativePromise('DailyNotification', 'requestPermissions', {}); - }, - // Notification methods - scheduleDailyNotification: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {}); - }, - getNotificationStatus: function() { - return window.Capacitor.nativePromise('DailyNotification', 'getNotificationStatus', {}); - }, - cancelAllNotifications: function() { - return window.Capacitor.nativePromise('DailyNotification', 'cancelAllNotifications', {}); - }, - // Status methods - checkStatus: function() { - return window.Capacitor.nativePromise('DailyNotification', 'checkStatus', {}); - }, - // Channel methods - isChannelEnabled: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'isChannelEnabled', options || {}); - }, - openChannelSettings: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'openChannelSettings', options || {}); - }, - // Configuration methods - configure: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'configure', options || {}); - }, - configureNativeFetcher: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'configureNativeFetcher', options || {}); - }, - // Battery/Power methods - getBatteryStatus: function() { - return window.Capacitor.nativePromise('DailyNotification', 'getBatteryStatus', {}); - }, - getPowerState: function() { - return window.Capacitor.nativePromise('DailyNotification', 'getPowerState', {}); - }, - requestBatteryOptimizationExemption: function() { - return window.Capacitor.nativePromise('DailyNotification', 'requestBatteryOptimizationExemption', {}); - }, - // Exact alarm methods - getExactAlarmStatus: function() { - return window.Capacitor.nativePromise('DailyNotification', 'getExactAlarmStatus', {}); - }, - openExactAlarmSettings: function() { - return window.Capacitor.nativePromise('DailyNotification', 'openExactAlarmSettings', {}); - }, - // Test methods - testAlarm: function(options) { - return window.Capacitor.nativePromise('DailyNotification', 'testAlarm', options || {}); +(function() { + 'use strict'; + + // Wait for Capacitor to be available + function registerPlugin() { + if (!window.Capacitor) { + setTimeout(registerPlugin, 100); + return; + } + + const cap = window.Capacitor; + if (!cap.Plugins) { + cap.Plugins = {}; + } + + // Create plugin object with methods that call native bridge + const DailyNotification = { + // Permission methods + checkPermissionStatus: function() { + return cap.nativePromise('DailyNotification', 'checkPermissionStatus', {}); + }, + requestNotificationPermissions: function() { + return cap.nativePromise('DailyNotification', 'requestNotificationPermissions', {}); + }, + checkPermissions: function() { + return cap.nativePromise('DailyNotification', 'checkPermissions', {}); + }, + requestPermissions: function() { + return cap.nativePromise('DailyNotification', 'requestPermissions', {}); + }, + // Notification methods + scheduleDailyNotification: function(options) { + return cap.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {}); + }, + getNotificationStatus: function() { + return cap.nativePromise('DailyNotification', 'getNotificationStatus', {}); + }, + cancelAllNotifications: function() { + return cap.nativePromise('DailyNotification', 'cancelAllNotifications', {}); + }, + // Status methods + checkStatus: function() { + return cap.nativePromise('DailyNotification', 'checkStatus', {}); + }, + // Channel methods + isChannelEnabled: function(options) { + return cap.nativePromise('DailyNotification', 'isChannelEnabled', options || {}); + }, + openChannelSettings: function(options) { + return cap.nativePromise('DailyNotification', 'openChannelSettings', options || {}); + }, + // Configuration methods + configure: function(options) { + return cap.nativePromise('DailyNotification', 'configure', options || {}); + }, + configureNativeFetcher: function(options) { + return cap.nativePromise('DailyNotification', 'configureNativeFetcher', options || {}); + }, + // Battery/Power methods + getBatteryStatus: function() { + return cap.nativePromise('DailyNotification', 'getBatteryStatus', {}); + }, + getPowerState: function() { + return cap.nativePromise('DailyNotification', 'getPowerState', {}); + }, + requestBatteryOptimizationExemption: function() { + return cap.nativePromise('DailyNotification', 'requestBatteryOptimizationExemption', {}); + }, + // Exact alarm methods + getExactAlarmStatus: function() { + return cap.nativePromise('DailyNotification', 'getExactAlarmStatus', {}); + }, + openExactAlarmSettings: function() { + return cap.nativePromise('DailyNotification', 'openExactAlarmSettings', {}); + }, + // Test methods + testAlarm: function(options) { + return cap.nativePromise('DailyNotification', 'testAlarm', options || {}); + } + }; + + // Register plugin + cap.Plugins.DailyNotification = DailyNotification; + + console.log('✅ DailyNotification plugin registered with', Object.keys(DailyNotification).length, 'methods'); } -}; - -console.log('Capacitor plugins file loaded - DailyNotification plugin registered'); + + // Register when DOM is ready or immediately if Capacitor is already available + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', registerPlugin); + } else { + registerPlugin(); + } +})();