-
-
Notifications
You must be signed in to change notification settings - Fork 207
Description
webxdc sendUpdate does not work in onclose/visibility changed even handler on closing the app.
window.on("visibilitychange", (ev) => {
window.webxdc.sendUpdate(update, descr);
})In this case desktop does not manage to send the update. I suspect it is because sendUpdate uses the async electron ipc invoke-function.
I tried using a the synchronous ipc functions (without changing that sendUpdate returns a promise, it uses jsonrpc under the hood in the back-end and JS has no ::block_on(future/promise) function, so the promise is necessary), but I was not successful in my first try (but I was also very tired and had a hard time concentrating, so maybe I could still make it work, but I don't see very high chances.)
At the moment I would recommend the following workaround, but I haven't tested if closing the window works with standard browser apis in our case:
window.on("visibilitychange", (ev) => {
ev.preventDefault(); // prevent the closing of the window
await window.webxdc.sendUpdate(update, descr);
// somehow close window via JS //maybe with window.close() ?
})Maybe it could also make sense to add a close callback api to the webxdc spec, where you can set a custom close handler that is run on closing and returns a promise, when it is resolved or after a timeout the app is then closed by the host app (in our case DC).