mirror of
https://github.com/a2nt/silverstripe-progressivewebapp.git
synced 2024-10-22 11:05:45 +02:00
Service worker js
This commit is contained in:
parent
2a37361586
commit
bde15f3cf2
20
README.md
20
README.md
@ -8,13 +8,13 @@ composer require pixelspin/silverstripe-progressivewebapp
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Install the module, run dev/build and fill in the settings in the siteconfig
|
- Install the module, run dev/build and fill in the settings in the siteconfig
|
||||||
Create a symlink at the root of you website to vendor/pixelspin/silverstripe-progressivewebapp/service-worker.js
|
- Include the required js to register the service worker
|
||||||
Place the link to the manifest file (<link rel="manifest" href="{$BaseHref}manifest.json">) in the head of your pages and add the color meta data as well (<meta name="theme-color" content="$SiteConfig.ManifestColor">)
|
```
|
||||||
Include the js (Requirements::javascript('pixelspin/silverstripe-progressivewebapp:resources/js/progressivewebapp.js');)
|
Requirements::javascript('pixelspin/silverstripe-progressivewebapp:resources/js/progressivewebapp.js');
|
||||||
|
```
|
||||||
## Todo
|
- Add the following tags to the head of your website
|
||||||
- Add "add to homescreen" prompt
|
```
|
||||||
- Add offline support
|
<meta name="theme-color" content="$SiteConfig.ManifestColor">
|
||||||
- Create an you are offline page
|
<link rel="manifest" href="{$BaseHref}manifest.json">
|
||||||
- Improve documentation
|
```
|
@ -4,7 +4,8 @@ Name: progressivewebapp
|
|||||||
|
|
||||||
SilverStripe\Control\Director:
|
SilverStripe\Control\Director:
|
||||||
rules:
|
rules:
|
||||||
'manifest.json': 'Pixelspin\ProgressiveWebApp\Controllers\ProgressiveWebAppController'
|
'manifest.json': 'Pixelspin\ProgressiveWebApp\Controllers\ManifestController'
|
||||||
|
'service-worker.js': 'Pixelspin\ProgressiveWebApp\Controllers\ServiceWorkerController'
|
||||||
|
|
||||||
SilverStripe\SiteConfig\SiteConfig:
|
SilverStripe\SiteConfig\SiteConfig:
|
||||||
extensions:
|
extensions:
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/service-worker.js');
|
var baseHref = (document.getElementsByTagName('base')[0] || {}).href;
|
||||||
|
if(baseHref){
|
||||||
|
navigator.serviceWorker.register(baseHref + 'service-worker.js');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
self.addEventListener('fetch', (event) => {});
|
|
@ -5,7 +5,7 @@ namespace Pixelspin\ProgressiveWebApp\Controllers;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
|
|
||||||
class ProgressiveWebAppController extends Controller {
|
class ManifestController extends Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
26
src/Controllers/ServiceWorkerController.php
Normal file
26
src/Controllers/ServiceWorkerController.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pixelspin\ProgressiveWebApp\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
|
||||||
|
class ServiceWorkerController extends Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $allowed_actions = [
|
||||||
|
'index'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default controller action for the service-worker.js file
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function index($url) {
|
||||||
|
$this->getResponse()->addHeader('Content-Type', 'application/javascript; charset="utf-8"');
|
||||||
|
return $this->renderWith('ServiceWorker');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
templates/ServiceWorker.ss
Normal file
1
templates/ServiceWorker.ss
Normal file
@ -0,0 +1 @@
|
|||||||
|
self.addEventListener('fetch', (event) => {});
|
Loading…
Reference in New Issue
Block a user