CONTENTS
---------------------
   
 * INTRODUCTION
 * REQUIREMENTS
 * INSTALLATION
 * CONFIGURATION
 * QUEUE AND CRON
 * TROUBLESHOOTING
 * TO DO
 * USE 'push_notification' AS A SERVICE

INTRODUCTION
------------

- This module will turn your website into a progressive web app
- Users can choose to subscribe or not for push notifications. This is achieved by one of three options:
-- Modal means default Drupal confirmation dialog box.
-- Embedded means it gets added to the bottom of the page.
-- Bootstrap 5 Modal if you load Bootstrap css and js into your website ie via a theme.
- Notifications will be sent to subscribed users on publish of specific content
   types. Site admin can choose such content types using this module
- Site admin can send generic notifications to all subscribed users
- Site admin can set background color and theme color of progressive web app
- Site admin can set public / private keys that will be used to sign Push API
   requests
- Site admin can view subscribed users (User id and subscription endpoint)


REQUIREMENTS
------------

- php version 7.0 or higher
- minishlink/web-push library version 7.0
- Site domain should be SSL enabled. Push notifications only works on SSL
   enabled domains

INSTALLATION
------------

Please watch this video for how to set things up: https://youtu.be/arpnqe9cNX8

1. Install 'Advanced Progressive web app' module
   - Install using composer: 'composer require drupal/advanced_pwa'
      (recommended)
      or
   - Download and install 'Advanced Progressive web app' module
   - The above mentioned 'web-push' library dependency will be automatically
      installed if you are installing the module using composer
2. If you did not install the module using composer, install the 'web-push'
    library manually:
   - Run 'composer require minishlink/web-push:^7.0' from your sites root
      folder
   Please note that the current module works only with web-push library
      version 7.0

CONFIGURATION
-------------

Once you install the module, a link 'Advanced pwa Settings' will appear on
   '/admin/config' page under 'System'.

1. Go to '/admin/config/system/advanced_pwa' to configure manifest related
     settings
   a. Enable 'Enable push notifications' to enable push notification feature.
       Disabling the push notifications will ensure that no user will be able
        to receive push notifications
   b. 'Short name' will be name of the app that will appear on users home
        screen
   c. Enter Name of the app
   d. 'General App Icon' will be the icon that will appear on users home
        screen, along with app name
   e. 'Background Color' will be shown when the user opens the website from
        their homescreen
   f. 'Theme Color' is used to create a consistent experience in the browser
   g. Under prompt settings you can configure the text used when requesting permission for push notifications. 
   You also have options for the display type and how often to ask for permission.
   h. Under advanced settings you can choose what page to direct users to when they open the app. Also orientation.
2. Go to '/admin/config/advanced_pwa/config' to set up public / private keys
     and upload app notification icon
   Note: Click on 'Generate keys' before uploading notification icon.
3. 'Push Notification Subscription'
     ('/admin/config/advanced_pwa/config-subscription') config page will allow
        you to select content types. Push notification will be sent to
          subscribed users whenever content of the selected content type
           is published
4. 'Push Notification Subscription List'
     (/admin/config/advanced_pwa/subscription-list) page will show list of
       subscribed users
5. You can send generic notification message from
    'Broadcast Push Notification' (/admin/config/advanced_pwa/config-broadcast)
      page
6. To add a link to trigger the push notification prompt use this anywhere: 

   <span class="push-prompt-link">Some plain text <span class="trigger-push-prompt">The link text</span></span>. 

   The link and text will only display if the user has permission, hasn't already subscribed and hasn't clicked block in the browser.
   You'll also need to add a little CSS to the link text to make it look like one.

QUEUE AND CRON
--------------

Considering the fact that there could be hundreds of users subscribed to the
 site and multiple content editors either publishing content or sending
  generic notifications, our module will not send notifications as soon as
   content is published or generic message is sent. It will Queue the
    notifications and will be sent on next cron run.

You can either use Drupal core cron or any contributed cron modules like
 'Ultimate Cron'.

If you choose to use 'Ultimate Cron' module, you will have to enable
 'Override cron queue processing' checkbox under path
  '/admin/config/system/cron/settings'. This will expose queue workers as cron
   jobs and will show under '/admin/config/system/cron/jobs'.

Note: At the time of writing these instructions, this feature of 'Ultimate Cron'
 module was experimental. Enable it only if you need it.

TROUBLESHOOTING
---------------

1. The current module works only with web-push library version 4.0
2. Web-push library 7.0 needs php version 7.0 or higher

TO DO
-----

Currently offline viewing has been commented out. The functionality is there. 
You need to uncomment // cache.put(event.request, response.clone()); in js/service_worker.js. 
I commented it out because it doesn't work at all well when users sign in or out. The cache becomes stale.
My idea is to add settings to turn it on and off. Along with similar settings to configuring a block.

USE 'push_notification' AS A SERVICE
------------------------------------

You can use 'push_notification' functionality as a service from any of your
  custom modules, if needed.
Name of the service is 'advanced_pwa.push_notifications'.

Usage example:
----------------------------------------------------
$sendNotificationService = \Drupal::service('advanced_pwa.push_notifications');

return $sendNotificationService::sendNotificationStart($subscriptionData,
  $notification_data);
----------------------------------------------------

'sendNotificationStart' is the method to which '$subscriptionData' and
  '$notification_data' arguments needs to be passed.

Check file 'AdvancedpwaQueueProcessor.php' for more details.
