Skip to content

Commit

Permalink
^ PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
SindlaXYZ committed Jan 5, 2021
1 parent f0a0e5d commit 6249921
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ parameters:
aurora.minify.output.ignore.extensions: ['.pdf', '.jpg', '.png', '.gif', '.doc']
aurora.minify.output.ignore.content.type: ['text/plain']
# https://developers.google.com/web/fundamentals/web-app-manifest
aurora.pwa.automatically_prompt: false
aurora.pwa.app_name: ''
aurora.pwa.app_short_name: ''
aurora.pwa.app_description: ''
aurora.pwa.start_url: '/?pwa'
aurora.pwa.display: 'fullscreen' # fullscreen | standalone | minimal-ui
aurora.pwa.icons: '%kernel.project_dir%/public/static/img/favicon'
aurora.pwa.theme_color: '#2C3E50' # Sets the color of the tool bar, and may be reflected in the app's preview in task switchers
aurora.pwa.background_color: '#2C3E50' # Should be the same color as the load page, to provide a smooth transition from the splash screen to your app
aurora.pwa.offline: '/aurora/pwa-offline'
#aurora.pwa.version_append: "!php/eval `date('Y-m-d H')`"
aurora.pwa.version_append: "!php/eval `App\Utils::pwaVersioAppend()`"
aurora.pwa.automatically_prompt: false
aurora.pwa.app_name: ''
aurora.pwa.app_short_name: ''
aurora.pwa.app_description: ''
aurora.pwa.start_url: '/?pwa'
aurora.pwa.display: 'fullscreen' # fullscreen | standalone | minimal-ui
aurora.pwa.icons: '%kernel.project_dir%/public/static/img/favicon'
aurora.pwa.theme_color: '#2C3E50' # Sets the color of the tool bar, and may be reflected in the app's preview in task switchers
aurora.pwa.background_color: '#2C3E50' # Should be the same color as the load page, to provide a smooth transition from the splash screen to your app
aurora.pwa.offline: '/aurora/pwa-offline'
aurora.pwa.precache:
- '/'
aurora.pwa.prevent_cache:
Expand Down
19 changes: 18 additions & 1 deletion src/Utils/PWA/PWA.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function manifestJSON(Request $Request)
public function browserConfig(Request $Request)
{
$cache = new FilesystemAdapter();
return $cache->get(sha1(__NAMESPACE__ . __CLASS__ . __METHOD__. __LINE__ . sha1($Request->getRequestUri())), function (ItemInterface $item) {
return $cache->get(sha1(__NAMESPACE__ . __CLASS__ . __METHOD__ . __LINE__ . sha1($Request->getRequestUri())), function (ItemInterface $item) {
$item->expiresAfter(('dev' !== $this->container->getParameter('kernel.environment')) ? (60 * 60 * 24) : 0);

$encoder = new XmlEncoder();
Expand Down Expand Up @@ -144,6 +144,7 @@ public function mainJS(Request $Request)
{
$rendered = $this->twig->render('@Aurora/pwa-main.js.twig', [
'build' => $this->_build($Request),
'pwaVersion' => $this->version(),
'automatically_prompt' => ($this->container->hasParameter('aurora.pwa.automatically_prompt') ? boolval($this->container->getParameter('aurora.pwa.automatically_prompt')) : true)
]);

Expand Down Expand Up @@ -183,6 +184,22 @@ public function serviceWorkerJS(Request $Request)
return $response;
}

public function version()
{
$serviceGit = $this->container->get('aurora.git');
$version = $serviceGit->getHash();
$versionAppend = $this->container->getParameter('aurora.pwa.version_append');

if (0 === strpos($versionAppend, '!php/eval')) {
preg_match('/`(.*)`/', $versionAppend, $match);
if (isset($match[1]) && !empty($match[1])) {
$version .= '-' . substr(sha1(eval("return " . trim($match[1], ';') . ";")), 0, 15);
}
}

return $version;
}

/**
* Favicon image
*
Expand Down
13 changes: 3 additions & 10 deletions src/Utils/Twig/UtilityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,10 @@ public function pwa(Request $Request, bool $debug)

public function pwaVersion()
{
$version = $this->getBuild();
$versionAppend = $this->container->getParameter('aurora.pwa.version_append');
/** @var PWA $PWA */
$PWA = $this->container->get('aurora.pwa');

if (0 === strpos($versionAppend, '!php/eval')) {
preg_match('/`(.*)`/', $versionAppend, $match);
if (isset($match[1]) && !empty($match[1])) {
$version .= '-' . substr(sha1(eval("return " . trim($match[1], ';') . ";")), 0, 15);
}
}

return $version;
return $PWA->version();
}

public function pwaDelete(Request $Request, bool $debug)
Expand Down

0 comments on commit 6249921

Please sign in to comment.