lekoala/silverstripe-pwa

Create your progressive web app (PWA) with SilverStripe

Fund package maintenance!
lekoala

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-master 2024-09-16 12:59 UTC

This package is auto-updated.

Last update: 2024-12-16 13:31:50 UTC


README

Build Status scrutinizer Code coverage

Features

  • Support push notifications
  • Generate a valid manifest
  • Provides a default configurable service worker that can cache assets

Generate icons

Use the cli npm run generate-assets(-root) (if you have a app/images/logo.svg file) or upload a zip file with the required icons

Note: pay attention to maskable icons. You can test their size in the developer console. You can test them in maskable.app

Subscribe to push notifications

client.js provides some base code for this. You need to put somewhere a checkbox that can be used to toggle push notifications on/off.

<label
    ><input type="checkbox" class="js-push-toggle" /> Enable
    notifications</label
>

This is dealt with by client.js. You can replace client code by your custom code or disable it entirely

LeKoala\SsPwa\ServiceWorkerController:
    enable_client_js: false
    custom_client_path: "/my/custom/path"

Service worker

This module provides a default service worker. You can use your own if needed

LeKoala\SsPwa\ServiceWorkerController:
    custom_sw_path: "/my/custom/path"

Use vapid keys

You can generate the vapid keys with this online tool or with the cli npm run gen-push-keys

You need to save them either in your .env file or as YML config.

PUSH_PUBLIC_KEY='BK1Zt63e94HgYNm-s9aquI85AUdDRz3uKMxue7woQVZv0_3txywXPgyYd2WPJetayKYq3E_AObBGD9rHWOL_...'
PUSH_PRIVATE_KEY='1nKKQnzGRMNit-TuvklqoTY_ENO8eAybp1MsZWx0...'

Sending push notifications

You can use the following piece of code

PushSubscription::sendPushNotifications($where, $data);

Credits

Thanks to https://github.com/a2nt/silverstripe-progressivewebapp for some inspiration :-)

Compatibility

Tested with ^4.11

Maintainer

LeKoala - thomas@lekoala.be