fix: resolve JavaScript module import error in test app
- Replace ES module imports with global Capacitor objects - Add null checks for DailyNotification plugin availability - Fix 'Failed to resolve module specifier @capacitor/core' error - Use window.Capacitor and window.DailyNotification instead of imports This resolves the JavaScript error that was preventing the web interface from loading properly in the test app.
This commit is contained in:
@@ -60,18 +60,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { DailyNotification } from '@timesafari/daily-notification-plugin';
|
||||
|
||||
window.Capacitor = Capacitor;
|
||||
window.DailyNotification = DailyNotification;
|
||||
<script>
|
||||
// Use global Capacitor and plugin objects instead of ES modules
|
||||
// These are provided by the Capacitor runtime
|
||||
const Capacitor = window.Capacitor;
|
||||
const DailyNotification = window.DailyNotification;
|
||||
|
||||
window.testPlugin = async function() {
|
||||
const status = document.getElementById('status');
|
||||
status.innerHTML = 'Testing plugin...';
|
||||
|
||||
try {
|
||||
if (!DailyNotification) {
|
||||
status.innerHTML = 'DailyNotification plugin not available';
|
||||
return;
|
||||
}
|
||||
const result = await DailyNotification.echo({ value: 'Hello from test app!' });
|
||||
status.innerHTML = `Plugin test successful: ${result.value}`;
|
||||
} catch (error) {
|
||||
@@ -84,6 +87,10 @@
|
||||
status.innerHTML = 'Configuring plugin...';
|
||||
|
||||
try {
|
||||
if (!DailyNotification) {
|
||||
status.innerHTML = 'DailyNotification plugin not available';
|
||||
return;
|
||||
}
|
||||
await DailyNotification.configure({
|
||||
fetchUrl: 'https://api.example.com/daily-content',
|
||||
scheduleTime: '09:00',
|
||||
@@ -100,6 +107,10 @@
|
||||
status.innerHTML = 'Checking plugin status...';
|
||||
|
||||
try {
|
||||
if (!DailyNotification) {
|
||||
status.innerHTML = 'DailyNotification plugin not available';
|
||||
return;
|
||||
}
|
||||
const result = await DailyNotification.getStatus();
|
||||
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user