Skip to content
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

Support "add to home screen" on mobile browsers. #3155

Merged
merged 2 commits into from
Feb 22, 2020

Conversation

zenhack
Copy link
Collaborator

@zenhack zenhack commented Sep 8, 2019

With this patch, sandstorm now supports "add to home screen" on modern
mobile browsers:

https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen

Notes:

  • The new file /public/sandstorm-gradient-logo.png is the same image
    as the corresponding .svg; At least Chrome requires images larger
    than the small icon32.png we have, and doesn't support .svg.
  • The service worker doesn't really do anything right now; it's just
    there because some browsers demand it to allow add to home screen.
    At some point we should use this to cache static assets.

IMPORTANT: I haven't actually had a chance to test this with a real
phone browser yet; I just moved and my sandstorm box isn't set up yet.
Chrome dev tools seems to be happy with it though.

@zenhack
Copy link
Collaborator Author

zenhack commented Jan 11, 2020

Finally got around to actually testing this and I can confirm that it actually works.

@@ -14,6 +14,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs -> spaces

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zenhack Your Tabs -> spaces commit didn't touch this file, so I assume this isn't resolved here.

@@ -0,0 +1,18 @@

self.addEventListener('install', function(event) {
const urlsToCache = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs -> spaces in this whole file.

}))
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we aren't actually caching anything, should we remove the caches.match check here? It seems like it'll just make things slower.

Does it work if you don't register a fetch listener at all? (I think it should then fall back to the default behavior of sending the request to the server...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, I have another commit locally that actually does cache static assets, apparently I forgot to push... sorry about the slopyness on this one.

@ocdtrekkie ocdtrekkie added the enhancement Feature requests label Jan 15, 2020
@zenhack
Copy link
Collaborator Author

zenhack commented Feb 3, 2020 via email

@ocdtrekkie ocdtrekkie added the ready-for-review We think this is ready for review label Feb 10, 2020
"icons/icons-adec2a339de139470e74b4c487321525.woff",
]
event.waitUntil(caches.open('sandstorm-cache').then(function(cache) {
return cache.addAll(urlsToCache);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep the list in-sync somehow?

What happens when the Sandstorm server is updated and the files change? Will the installation keep using the old versions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: sw updates, I remember getting an impression from the docs that it would auto-update the service worker. But yeah, looking back this is a little half-baked. I'm just going rip out the caching stuff entirely, and we can just to the bare minimum to get add to home screen working. Presumably browser caches will do an okay job on their own.

With this patch, sandstorm now supports "add to home screen" on modern
mobile browsers:

    https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen

Notes:

* The new file `/public/sandstorm-gradient-logo.png` is the same image
  as the corresponding `.svg`; At least Chrome requires images larger
  than the small `icon32.png` we have, and doesn't support `.svg`.
* The service worker doesn't do anything right now; it's just
  there because some browsers demand it to allow add to home screen.
  At some point we could use this to cache static assets.
@zenhack
Copy link
Collaborator Author

zenhack commented Feb 15, 2020

Ok, killed the half-baked caching logic, squashed and rebased onto master.

@ocdtrekkie
Copy link
Collaborator

It may be worthwhile to revisit the caching question later as we talk further about shared/static assets going forward, including possibly static assets from apps.

@zenhack
Copy link
Collaborator Author

zenhack commented Feb 16, 2020

Yeah, let's open a separate ticket to track that once this is merged.

@kentonv
Copy link
Member

kentonv commented Feb 22, 2020

Oops, I guess this conflicted with @zarvox's refactor.

@ocdtrekkie ocdtrekkie removed the ready-for-review We think this is ready for review label Feb 22, 2020
@zenhack
Copy link
Collaborator Author

zenhack commented Feb 22, 2020

Merged master back in, but see my comment here:

#3231 (comment)

@ocdtrekkie ocdtrekkie added the ready-for-review We think this is ready for review label Feb 22, 2020
@ocdtrekkie
Copy link
Collaborator

This seems unlikely it's related to this PR, but the test on this PR blew apart spectacularly: https://github.com/sandstorm-io/sandstorm/actions/runs/43545271

Unfortunately, while we know that tests fail and are ignoring that they do, the only way to see spectacular fails is to manually check the log.

@zenhack
Copy link
Collaborator Author

zenhack commented Feb 22, 2020

Can confirm this still works after fixing the merge conflicts.

@kentonv kentonv merged commit 65f4f77 into sandstorm-io:master Feb 22, 2020
@ocdtrekkie ocdtrekkie removed the ready-for-review We think this is ready for review label Feb 23, 2020
@zenhack zenhack deleted the pwa branch December 28, 2020 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants