-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webxdc sendUpdate does not work in onclose/visibility changed event handler on closing the app #3321
Comments
Also see
Also the correct code for the workaround you suggested would be function sendUpdateAndPreventCloseUntilSent(e) {
webxdc.sendUpdate({ payload: 'bar' }, '').then(() => {
window.removeEventListener('beforeunload', sendUpdateAndPreventCloseUntilSent);
// Close the parent since we're in an `<iframe>`.
window.parent.close();
})
e.preventDefault();
e.returnValue = '';
return '';
}
window.addEventListener('beforeunload', sendUpdateAndPreventCloseUntilSent); , as in https://codeberg.org/webxdc/editor/commit/9d56ab4167ad9d72f79baecde50401dc036bc0dd |
Something notable. I'm trying webxdc/webxdc-test@4add6f7, and it appears that So the workaround would be to add a |
Maybe would need a way to prevent sending duplicate updates? |
why not simply call iirc, i did a small test some time ago, and that worked out. that way, |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I'm sorry, I still don't get your idea. Are you suggesting a workaround? How is it better than mine? Can you show some code? |
i have overseen or misinterpreted your comment "So the workaround would be to add a beforeunload listener besides the visibilitychange listener?" that time, sorry. i think, we are talking about the same thing. however, to be clear, i'd not add |
Something to note: this is only the case inside of the window.addEventListener('visibilitychange', () => {
webxdc.sendUpdate({
payload: 'dummyPayload',
info: 'sent!' + Math.random()
}, '');
}); it will send a message, whereas if you choose the app's context, it wont. So, another workaround: +const targetWindow = window.parent;
-window.addEventListener('visibilitychange', () => {
+targetWindow.addEventListener('visibilitychange', () => {
+ // if (targetWindow.document.visibilityState ===...
webxdc.sendUpdate({
payload: 'dummyPayload',
info: 'sent!' + Math.random()
}, '');
}); Update: I implemented the hack here https://codeberg.org/WofWca/webxdc-yjs-provider/commit/d129908920f9f21bb2bc6495b6cfffc17393a382 |
webxdc sendUpdate does not work in onclose/visibility changed even handler on closing the app.
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:
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).
The text was updated successfully, but these errors were encountered: