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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module">
|
<script>
|
||||||
import { Capacitor } from '@capacitor/core';
|
// Use global Capacitor and plugin objects instead of ES modules
|
||||||
import { DailyNotification } from '@timesafari/daily-notification-plugin';
|
// These are provided by the Capacitor runtime
|
||||||
|
const Capacitor = window.Capacitor;
|
||||||
window.Capacitor = Capacitor;
|
const DailyNotification = window.DailyNotification;
|
||||||
window.DailyNotification = DailyNotification;
|
|
||||||
|
|
||||||
window.testPlugin = async function() {
|
window.testPlugin = async function() {
|
||||||
const status = document.getElementById('status');
|
const status = document.getElementById('status');
|
||||||
status.innerHTML = 'Testing plugin...';
|
status.innerHTML = 'Testing plugin...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result = await DailyNotification.echo({ value: 'Hello from test app!' });
|
const result = await DailyNotification.echo({ value: 'Hello from test app!' });
|
||||||
status.innerHTML = `Plugin test successful: ${result.value}`;
|
status.innerHTML = `Plugin test successful: ${result.value}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -84,6 +87,10 @@
|
|||||||
status.innerHTML = 'Configuring plugin...';
|
status.innerHTML = 'Configuring plugin...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
await DailyNotification.configure({
|
await DailyNotification.configure({
|
||||||
fetchUrl: 'https://api.example.com/daily-content',
|
fetchUrl: 'https://api.example.com/daily-content',
|
||||||
scheduleTime: '09:00',
|
scheduleTime: '09:00',
|
||||||
@@ -100,6 +107,10 @@
|
|||||||
status.innerHTML = 'Checking plugin status...';
|
status.innerHTML = 'Checking plugin status...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result = await DailyNotification.getStatus();
|
const result = await DailyNotification.getStatus();
|
||||||
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
|
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user