derkyjadex / M8WebDisplay

Display for headless M8 tracker
https://derkyjadex.github.io/M8WebDisplay/
MIT License
196 stars 39 forks source link

Disconnect call is skipped on Chrome pwa when quit. #14

Open jakerr opened 2 years ago

jakerr commented 2 years ago

This was tested with PWA installed on Chrome. The disconnect is not called when the app is quit. On hardware M8 this is going to be less noticeable, but on headless Teensy, this means that autosave won't be executed.

Closing the window via the 'x' button in the window corner does seem to execute the autosave. I don't know if there's another hook that could be used or a workaround that can be done in code.

derkyjadex commented 2 years ago

I wasn't aware that the disable command triggered an autosave; I thought that it was mainly to tell the Teensy/M8 to stop generating and sending display commands over USB serial.

After doing a bit of looking around, I think it might make sense to use the visibilitychange event to send the enable/disable commands whenever the tab or window is shown or hidden. This is supposed to be a more reliable way of detecting a page being closed than the beforeunload event, although it will be fired in more cases than just closing the page.

I'll have to have more of a think about this and take a look into how the autosave works on the M8.