mirror of
https://github.com/a2nt/silverstripe-progressivewebapp.git
synced 2024-10-22 11:05:45 +02:00
Service worker
This commit is contained in:
parent
051ffd6163
commit
2a37361586
@ -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');)
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user