Service worker

This commit is contained in:
Michel 2018-06-25 14:19:45 +02:00
parent 051ffd6163
commit 2a37361586
4 changed files with 9 additions and 8 deletions

View File

@ -9,6 +9,7 @@ composer require pixelspin/silverstripe-progressivewebapp
## Usage
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
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');)

View File

@ -1,3 +1,3 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('resources/pixelspin/silverstripe-progressivewebapp/resources/js/service-worker.js');
}
navigator.serviceWorker.register('/service-worker.js');
}

View File

@ -20,11 +20,11 @@ class ProgressiveWebAppController extends Controller {
* @return mixed
*/
public function index($url) {
$config = SiteConfig::current_site_config();
$manifestContent = [];
$manifestContent['start_url'] = './';
$manifestContent['start_url'] = '/';
if($config->ManifestName){
$manifestContent['name'] = $config->ManifestName;
}
@ -44,7 +44,7 @@ class ProgressiveWebAppController extends Controller {
if($config->ManifestDisplay){
$manifestContent['display'] = $config->ManifestDisplay;
}
$logo = $config->ManifestLogo();
if($logo && $logo->exists()){
$mime = $logo->getMimeType();
@ -91,10 +91,10 @@ class ProgressiveWebAppController extends Controller {
]
];
}
$this->getResponse()->addHeader('Content-Type', 'application/manifest+json; charset="utf-8"');
return json_encode($manifestContent);
}
}