fixed action handlers
This commit is contained in:
17
sw.js
17
sw.js
@@ -91,7 +91,8 @@ self.addEventListener('push', event => {
|
||||
data: {
|
||||
action: 'Unknown',
|
||||
button: 'Unknown',
|
||||
batteryLevel: undefined
|
||||
batteryLevel: undefined,
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,6 +109,12 @@ self.addEventListener('push', event => {
|
||||
data: parsedData.data || pushData.data // Expecting { action: 'SingleClick', button: 'game-button', batteryLevel: 75 }
|
||||
};
|
||||
|
||||
// Ensure all required fields are present in data
|
||||
pushData.data = pushData.data || {};
|
||||
if (!pushData.data.timestamp) {
|
||||
pushData.data.timestamp = new Date().toISOString();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('[ServiceWorker] Error parsing push data:', e);
|
||||
// Use default notification if parsing fails
|
||||
@@ -120,12 +127,14 @@ self.addEventListener('push', event => {
|
||||
// --- Send message to client(s) ---
|
||||
const messagePayload = {
|
||||
type: 'flic-action', // Custom message type
|
||||
action: pushData.data.action, // e.g., 'SingleClick', 'DoubleClick', 'Hold'
|
||||
button: pushData.data.button, // e.g., the button name
|
||||
timestamp: pushData.data.timestamp, // e.g., the timestamp of the action
|
||||
action: pushData.data.action || 'Unknown', // e.g., 'SingleClick', 'DoubleClick', 'Hold'
|
||||
button: pushData.data.button || 'Unknown', // e.g., the button name
|
||||
timestamp: pushData.data.timestamp || new Date().toISOString(), // e.g., the timestamp of the action
|
||||
batteryLevel: pushData.data.batteryLevel // e.g., the battery level percentage
|
||||
};
|
||||
|
||||
console.log('[ServiceWorker] Preparing message payload:', messagePayload);
|
||||
|
||||
// Send message to all open PWA windows controlled by this SW
|
||||
event.waitUntil(
|
||||
self.clients.matchAll({
|
||||
|
||||
Reference in New Issue
Block a user