capacitor-background-runner
capacitor-background-runner copied to clipboard
dispatchEvent details are not passed to background args
As the title describes dispatchEvent details are not passed to background args so i cannot use any component data in my background proces for fetching stuff for example
Let's say i have a function triggered by a button:
async activateBackgroundTask() {
try {
await BackgroundRunner.dispatchEvent({
label: 'com.app.app.check',
event: 'backgroundEventExecute',
details: { hello: "Hello world"},
})
} catch (error) {
console.error('Background task error:', error);
}
}
And a runner.js like this:
addEventListener('backgroundEventExecute', async (resolve, reject, args) => {
try {
// Notify that the background event was triggered
console.log('backgroundEventExecute: ', args, args.hello);
resolve();
} catch (error) {
console.error('Error in backgroundEvent:', error);
reject(error);
}
});
My args is always empty so the data i want to pass will never reach the background process. My console.log is reached and printed in the console. I've also tried to use CapacitorKV.get but i cannot use CapacitorKV.set in my angular/ionic component as it is not available there..
Specs:
"@capacitor/background-runner": "^1.1.0",
Angular: 17.x.x
Capacitor: 6.x.x
Can someone please tell me how to solve this issue OR fix this so we can use this background-runner?
Thanks in advance!