mirror of
https://github.com/a2nt/silverstripe-progressivewebapp.git
synced 2024-10-22 11:05:45 +02:00
First commit
This commit is contained in:
commit
f78a4fd0b7
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# For more information about the properties used in this file,
|
||||||
|
# please see the EditorConfig documentation:
|
||||||
|
# http://editorconfig.org
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[{*.yml,package.json,*.scss,*.js}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
# The indent size used in the package.json file cannot be changed:
|
||||||
|
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/node_modules/
|
||||||
|
/**/*.js.map
|
||||||
|
/**/*.css.map
|
28
LICENSE
Normal file
28
LICENSE
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Copyright (c) 2017, The Webmen
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the {organization} nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# SilverStripe Progressive Web App
|
||||||
|
|
||||||
|
Tools to add progressive web app functionality to your silverstripe website
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```
|
||||||
|
composer require pixelspin/silverstripe-progressivewebapp
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Install the module, run dev/build and fill in the settings in the siteconfig
|
||||||
|
Place the link to the manifest file (<link rel="manifest" href="{$BaseHref}manifest.json">) in the head of your pages
|
11
_config/config.yml
Normal file
11
_config/config.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
Name: progressivewebapp
|
||||||
|
---
|
||||||
|
|
||||||
|
SilverStripe\Control\Director:
|
||||||
|
rules:
|
||||||
|
'manifest.json': 'Pixelspin\ProgressiveWebApp\Controllers\ProgressiveWebAppController'
|
||||||
|
|
||||||
|
SilverStripe\SiteConfig\SiteConfig:
|
||||||
|
extensions:
|
||||||
|
- Pixelspin\ProgressiveWebApp\Extensions\ProgressiveWebAppSiteConfigExtension
|
37
composer.json
Normal file
37
composer.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "pixelspin/silverstripe-progressivewebapp",
|
||||||
|
"description": "Tools to add progressive web app functionality to your silverstripe website",
|
||||||
|
"type": "silverstripe-vendormodule",
|
||||||
|
"keywords": [
|
||||||
|
"silverstripe",
|
||||||
|
"progressive",
|
||||||
|
"app"
|
||||||
|
],
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"authors": [{
|
||||||
|
"name": "Michel van der Steege",
|
||||||
|
"email": "michelsteege@hotmail.com"
|
||||||
|
}],
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true,
|
||||||
|
"require": {
|
||||||
|
"silverstripe/cms": "^4.0@dev",
|
||||||
|
"silverstripe/vendor-plugin": "^1.0",
|
||||||
|
"silverware/colorpicker": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^5.7",
|
||||||
|
"squizlabs/php_codesniffer": "^3.0"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"installer-name": "silverstripe-progressivewebapp",
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Pixelspin\\ProgressiveWebApp\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
90
src/Controllers/ProgressiveWebAppController.php
Normal file
90
src/Controllers/ProgressiveWebAppController.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pixelspin\ProgressiveWebApp\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
|
|
||||||
|
class ProgressiveWebAppController extends Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $allowed_actions = [
|
||||||
|
'index'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default controller action for the manifest.json file
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function index($url) {
|
||||||
|
|
||||||
|
$config = SiteConfig::current_site_config();
|
||||||
|
$manifestContent = [];
|
||||||
|
$manifestContent['start_url'] = '/';
|
||||||
|
|
||||||
|
if($config->ManifestName){
|
||||||
|
$manifestContent['name'] = $config->ManifestName;
|
||||||
|
}
|
||||||
|
if($config->ManifestShortName){
|
||||||
|
$manifestContent['short_name'] = $config->ManifestShortName;
|
||||||
|
}
|
||||||
|
if($config->ManifestDescription){
|
||||||
|
$manifestContent['description'] = $config->ManifestDescription;
|
||||||
|
}
|
||||||
|
if($config->ManifestColor){
|
||||||
|
$manifestContent['background_color'] = $config->ManifestColor;
|
||||||
|
$manifestContent['theme_color'] = $config->ManifestColor;
|
||||||
|
}
|
||||||
|
if($config->ManifestOrientation){
|
||||||
|
$manifestContent['orientation'] = $config->ManifestOrientation;
|
||||||
|
}
|
||||||
|
if($config->ManifestDisplay){
|
||||||
|
$manifestContent['display'] = $config->ManifestDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
$logo = $config->ManifestLogo();
|
||||||
|
if($logo && $logo->exists()){
|
||||||
|
$mime = $logo->getMimeType();
|
||||||
|
$manifestContent['icons'] = [
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(48,48)->Link(),
|
||||||
|
'sizes' => '48x48',
|
||||||
|
'type' => $mime
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(72,72)->Link(),
|
||||||
|
'sizes' => '72x72',
|
||||||
|
'type' => $mime
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(96,96)->Link(),
|
||||||
|
'sizes' => '96x96',
|
||||||
|
'type' => $mime
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(144,144)->Link(),
|
||||||
|
'sizes' => '144x144',
|
||||||
|
'type' => $mime
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(168,168)->Link(),
|
||||||
|
'sizes' => '168x168',
|
||||||
|
'type' => $mime
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'src' => $logo->Fill(192,192)->Link(),
|
||||||
|
'sizes' => '192x192',
|
||||||
|
'type' => $mime
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getResponse()->addHeader('Content-Type', 'application/manifest+json; charset="utf-8"');
|
||||||
|
return json_encode($manifestContent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
src/Extensions/ProgressiveWebAppSiteConfigExtension.php
Normal file
68
src/Extensions/ProgressiveWebAppSiteConfigExtension.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pixelspin\ProgressiveWebApp\Extensions;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
use SilverWare\Colorpicker\ORM\FieldType\DBColor;
|
||||||
|
use SilverStripe\Assets\Image;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\AssetAdmin\Forms\UploadField;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverWare\Colorpicker\Forms\ColorField;
|
||||||
|
|
||||||
|
class ProgressiveWebAppSiteConfigExtension extends DataExtension {
|
||||||
|
|
||||||
|
private static $db = [
|
||||||
|
'ManifestName' => 'Varchar',
|
||||||
|
'ManifestShortName' => 'Varchar',
|
||||||
|
'ManifestDescription' => 'Varchar(255)',
|
||||||
|
'ManifestColor' => DBColor::class,
|
||||||
|
'ManifestOrientation' => 'Varchar',
|
||||||
|
'ManifestDisplay' => 'Varchar'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $displays = [
|
||||||
|
'fullscreen',
|
||||||
|
'standalone',
|
||||||
|
'minimal-ui',
|
||||||
|
'browser'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $orientations = [
|
||||||
|
'any',
|
||||||
|
'natural',
|
||||||
|
'landscape',
|
||||||
|
'landscape-primary',
|
||||||
|
'landscape-secondary',
|
||||||
|
'portrait',
|
||||||
|
'portrait-primary',
|
||||||
|
'portrait-secondary'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $has_one = [
|
||||||
|
'ManifestLogo' => Image::class
|
||||||
|
];
|
||||||
|
|
||||||
|
public function onAfterWrite() {
|
||||||
|
parent::onAfterWrite();
|
||||||
|
$manifestLogo = $this->owner->ManifestLogo();
|
||||||
|
if ($manifestLogo && $manifestLogo->exists()) {
|
||||||
|
$manifestLogo->doPublish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCMSFields(FieldList $fields) {
|
||||||
|
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestName', 'Name')->setDescription('Application name'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestShortName', 'Short name')->setDescription('Short human-readable name for the application'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestDescription', 'Description')->setDescription('Short description about the app'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', ColorField::create('ManifestColor', 'Color')->setDescription('Color used for the splash screen and/or icon'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', DropdownField::create('ManifestOrientation', 'Orientation', array_combine(self::$orientations, self::$orientations))->setDescription('App orientation'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', DropdownField::create('ManifestDisplay', 'Display', array_combine(self::$displays, self::$displays))->setDescription('Display mode of the app'));
|
||||||
|
$fields->addFieldToTab('Root.ProgressiveWebApp', UploadField::create('ManifestLogo', 'Logo')->setDescription('This image must be square and at least 512x512px'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user