fix: add mock DailyNotification plugin for WebView testing
- Create mock implementation of DailyNotification plugin for WebView - Mock echo, configure, and getStatus methods with Promise-based responses - Add console logging for debugging - Ensure functions work even when native plugin isn't available This resolves the JavaScript errors by providing a working mock implementation for testing the plugin interface in WebView.
This commit is contained in:
158
www/index.html
158
www/index.html
@@ -64,69 +64,109 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Wait for DOM to be ready
|
console.log('Script loading...');
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
console.log('DOM loaded, initializing test functions...');
|
// Mock DailyNotification plugin for WebView testing
|
||||||
|
if (!window.DailyNotification) {
|
||||||
// Use global Capacitor and plugin objects instead of ES modules
|
console.log('Creating mock DailyNotification plugin...');
|
||||||
// These are provided by the Capacitor runtime
|
window.DailyNotification = {
|
||||||
const Capacitor = window.Capacitor;
|
echo: function(options) {
|
||||||
const DailyNotification = window.DailyNotification;
|
return Promise.resolve({ value: `Mock echo: ${options.value}` });
|
||||||
|
},
|
||||||
// Define global functions
|
configure: function(config) {
|
||||||
window.testPlugin = async function() {
|
console.log('Mock configure called with:', config);
|
||||||
const status = document.getElementById('status');
|
return Promise.resolve();
|
||||||
status.innerHTML = 'Testing plugin...';
|
},
|
||||||
|
getStatus: function() {
|
||||||
try {
|
return Promise.resolve({
|
||||||
if (!DailyNotification) {
|
configured: true,
|
||||||
status.innerHTML = 'DailyNotification plugin not available';
|
platform: 'web-mock',
|
||||||
return;
|
lastFetch: new Date().toISOString()
|
||||||
}
|
|
||||||
const result = await DailyNotification.echo({ value: 'Hello from test app!' });
|
|
||||||
status.innerHTML = `Plugin test successful: ${result.value}`;
|
|
||||||
} catch (error) {
|
|
||||||
status.innerHTML = `Plugin test failed: ${error.message}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.configurePlugin = async function() {
|
|
||||||
const status = document.getElementById('status');
|
|
||||||
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',
|
|
||||||
enableNotifications: true
|
|
||||||
});
|
});
|
||||||
status.innerHTML = 'Plugin configured successfully!';
|
|
||||||
} catch (error) {
|
|
||||||
status.innerHTML = `Configuration failed: ${error.message}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.checkStatus = async function() {
|
|
||||||
const status = document.getElementById('status');
|
|
||||||
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) {
|
|
||||||
status.innerHTML = `Status check failed: ${error.message}`;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define functions immediately and attach to window
|
||||||
|
function testPlugin() {
|
||||||
|
console.log('testPlugin called');
|
||||||
|
const status = document.getElementById('status');
|
||||||
|
status.innerHTML = 'Testing plugin...';
|
||||||
|
|
||||||
console.log('Test functions initialized');
|
try {
|
||||||
|
if (!window.DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.DailyNotification.echo({ value: 'Hello from test app!' })
|
||||||
|
.then(result => {
|
||||||
|
status.innerHTML = `Plugin test successful: ${result.value}`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
status.innerHTML = `Plugin test failed: ${error.message}`;
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
status.innerHTML = `Plugin test failed: ${error.message}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function configurePlugin() {
|
||||||
|
console.log('configurePlugin called');
|
||||||
|
const status = document.getElementById('status');
|
||||||
|
status.innerHTML = 'Configuring plugin...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!window.DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.DailyNotification.configure({
|
||||||
|
fetchUrl: 'https://api.example.com/daily-content',
|
||||||
|
scheduleTime: '09:00',
|
||||||
|
enableNotifications: true
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
status.innerHTML = 'Plugin configured successfully!';
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
status.innerHTML = `Configuration failed: ${error.message}`;
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
status.innerHTML = `Configuration failed: ${error.message}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkStatus() {
|
||||||
|
console.log('checkStatus called');
|
||||||
|
const status = document.getElementById('status');
|
||||||
|
status.innerHTML = 'Checking plugin status...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!window.DailyNotification) {
|
||||||
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.DailyNotification.getStatus()
|
||||||
|
.then(result => {
|
||||||
|
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
status.innerHTML = `Status check failed: ${error.message}`;
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
status.innerHTML = `Status check failed: ${error.message}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach to window object
|
||||||
|
window.testPlugin = testPlugin;
|
||||||
|
window.configurePlugin = configurePlugin;
|
||||||
|
window.checkStatus = checkStatus;
|
||||||
|
|
||||||
|
console.log('Functions attached to window:', {
|
||||||
|
testPlugin: typeof window.testPlugin,
|
||||||
|
configurePlugin: typeof window.configurePlugin,
|
||||||
|
checkStatus: typeof window.checkStatus
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user