fix: improve JavaScript function definitions and add cache-busting
- Wrap function definitions in DOMContentLoaded event listener - Add cache-busting meta tags to prevent WebView caching - Add console logging for debugging - Ensure functions are properly attached to window object This should resolve the 'function not defined' JavaScript errors and prevent WebView from using cached HTML files.
This commit is contained in:
113
www/index.html
113
www/index.html
@@ -3,6 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||||
|
<meta http-equiv="Pragma" content="no-cache">
|
||||||
|
<meta http-equiv="Expires" content="0">
|
||||||
<title>DailyNotification Plugin Test</title>
|
<title>DailyNotification Plugin Test</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -61,62 +64,70 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Use global Capacitor and plugin objects instead of ES modules
|
// Wait for DOM to be ready
|
||||||
// These are provided by the Capacitor runtime
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const Capacitor = window.Capacitor;
|
console.log('DOM loaded, initializing test functions...');
|
||||||
const DailyNotification = window.DailyNotification;
|
|
||||||
|
|
||||||
window.testPlugin = async function() {
|
|
||||||
const status = document.getElementById('status');
|
|
||||||
status.innerHTML = 'Testing plugin...';
|
|
||||||
|
|
||||||
try {
|
// Use global Capacitor and plugin objects instead of ES modules
|
||||||
if (!DailyNotification) {
|
// These are provided by the Capacitor runtime
|
||||||
status.innerHTML = 'DailyNotification plugin not available';
|
const Capacitor = window.Capacitor;
|
||||||
return;
|
const DailyNotification = window.DailyNotification;
|
||||||
}
|
|
||||||
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() {
|
// Define global functions
|
||||||
const status = document.getElementById('status');
|
window.testPlugin = async function() {
|
||||||
status.innerHTML = 'Configuring plugin...';
|
const status = document.getElementById('status');
|
||||||
|
status.innerHTML = 'Testing plugin...';
|
||||||
try {
|
|
||||||
if (!DailyNotification) {
|
try {
|
||||||
status.innerHTML = 'DailyNotification plugin not available';
|
if (!DailyNotification) {
|
||||||
return;
|
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) {
|
||||||
|
status.innerHTML = `Plugin test failed: ${error.message}`;
|
||||||
}
|
}
|
||||||
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() {
|
window.configurePlugin = async function() {
|
||||||
const status = document.getElementById('status');
|
const status = document.getElementById('status');
|
||||||
status.innerHTML = 'Checking plugin status...';
|
status.innerHTML = 'Configuring plugin...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!DailyNotification) {
|
if (!DailyNotification) {
|
||||||
status.innerHTML = 'DailyNotification plugin not available';
|
status.innerHTML = 'DailyNotification plugin not available';
|
||||||
return;
|
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}`;
|
||||||
}
|
}
|
||||||
const result = await DailyNotification.getStatus();
|
};
|
||||||
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
|
|
||||||
} catch (error) {
|
window.checkStatus = async function() {
|
||||||
status.innerHTML = `Status check failed: ${error.message}`;
|
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}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Test functions initialized');
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user