sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.17k stars 50 forks source link

Deliver as a PWA on the web #371

Open bsidhom opened 7 months ago

bsidhom commented 7 months ago

It would be great to make Numbat installable as a Progressive Web App (PWA). The key benefit of this is the ability to use it offline on any device with a modern web browser.

Here's the minimum set of changes needed to get core PWA functionality:

Some great follow-up features which could be done down the road but would really enhance the experience:

In any case, I think it would be a good exercise to start with the current web implementation and see how far we can go with the offline experience.

bsidhom commented 7 months ago

NOTE: At the moment, I'm only considering the core Numbat calculator app as being "in scope" for the PWA, but I assume we could easily cache the docs for offline use as well.

bsidhom commented 7 months ago

It looks like there are already icons. I'll need to check whether those already cover the obvious platforms, in which case we can check that off. 🙂

sharkdp commented 7 months ago

on any device with a modern web browser

If only this were true :smiling_face_with_tear:. Firefox does not have support for PWAs. And Apple is breaking PWA support for customers in Europe with iOS 17.4: https://techcrunch.com/2024/02/15/apple-confirms-its-breaking-iphone-web-apps-in-the-eu-on-purpose/?guccounter=1

bsidhom commented 7 months ago

Where did you hear about lack of Firefox support? It used to work. (Not sure about mobile to be clear; since what you typically care about with PWAs is offline functionality and separate window support, I expect that to be integrated into the default system browser, i.e., Safari on iOS and Chrome on Android.) As far as I can tell, Firefox removed windowed mode for PWAs (also known as single-site browser), but did not remove the PWA APIs that allow the app to operate (e.g., it should still work offline). And I think that's only on desktop in any case, where I'd be more likely to use a regular browser bookmark (even if offline).

For iOS, I'm less certain. One can only hope that this is a pre-release bug (not unheard of). If it's only happening in the EU, then hopefully Apple is eventually forced to allow third-party browser engines on iOS. I've been waiting for this since I first heard rumors. :) In any case, all three browsers on the major OSes should support service workers, etc. So the functionality is still there. The main problem I'm seeing now is that if the iOS 17.4 regression was intentional, then offline PWAs will only operate for up to 7 days, since they now use the shared browser GC policy rather than a separate app-specific one.

bsidhom commented 7 months ago

More specifically, we can project compatibility onto the dimensions we care about:

And that's basically it.

If we wanted to get fancier and maintain some sort of shared memory app state, we could even use newer technologies such as broadcast channels and/or web locks. Honestly, I'd be surprised if any of these already-shipped features were removed or deprecated suddenly. I think my biggest concern now is around iOS (just in the EU?) deleting your offline stuff more aggressively in the future. But that's no worse than the pre-PWA situation. :)

sharkdp commented 7 months ago

Where did you hear about lack of Firefox support?

image

https://en.wikipedia.org/wiki/Progressive_web_app#Browser_support

Your version in #372 actually works fine in Firefox on Android though!

Firefox removed windowed mode for PWAs (also known as single-site browser), but did not remove the PWA APIs that allow the app to operate (e.g., it should still work offline).

Right. The service worker APIs still work fine.

For iOS, I'm less certain. One can only hope that this is a pre-release bug (not unheard of). If it's only happening in the EU, then hopefully Apple is eventually forced to allow third-party browser engines on iOS. I've been waiting for this since I first heard rumors. :)

I don't think it was a bug. It was intentional. But in the meantime, they backtracked, apparently: https://appleinsider.com/articles/24/03/01/apple-reverses-course-on-death-of-progressive-web-apps-in-eu

So yeah, let's try this :+1:. Sorry for being so reluctant.