Skip to content

Commit

Permalink
^ PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
SindlaXYZ committed Dec 31, 2020
1 parent 6660c8e commit f0a0e5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/Command/LazyEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ private function generateSettersGetters()

$function = ucfirst($prop->name);

//if (preg_match("/__toString/", $prop->getDocComment())) {
if (preg_match("/__toString/", $prop->getDocComment())) {
echo "__toString is deprecated. Use @Aurora instead.";
}

if ($auroraAnnotation->toSting) {
$toString = "\n\n" . <<<EOT
public function __toString() {
Expand Down
38 changes: 29 additions & 9 deletions src/Utils/Twig/UtilityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function getFunctions()
// {{ aurora.pwa(app.request, app.debug) }}
new TwigFunction('pwa', [$this, 'pwa']),

new TwigFunction('pwa.version', [$this, 'pwaVersion']),

// {{ aurora.pwa.delete(app.request, app.debug) }}
new TwigFunction('pwa.delete', [$this, 'pwaDelete']),

Expand Down Expand Up @@ -155,27 +157,45 @@ public function pwa(Request $Request, bool $debug)
'pwa' => (bool)($Request->isSecure() || preg_match('/(.*\.localhost$|^localhost$)/i', $Request->getHost())),
'theme_color' => $this->container->getParameter('aurora.pwa.theme_color'),
'build' => $this->getBuild(),
'pwaVersion' => $this->pwaVersion(),
'debug' => $debug
]);
}

public function pwaVersion()
{
$version = $this->getBuild();
$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;
}

public function pwaDelete(Request $Request, bool $debug)
{
return $this->twig->display('@Aurora/pwa.delete.html.twig', [
'host' => $Request->getHost(),
'pwa' => (bool)($Request->isSecure() || preg_match('/(.*\.localhost$|^localhost$)/i', $Request->getHost())),
'build' => $this->getBuild(),
'debug' => $debug
'host' => $Request->getHost(),
'pwa' => (bool)($Request->isSecure() || preg_match('/(.*\.localhost$|^localhost$)/i', $Request->getHost())),
'build' => $this->getBuild(),
'pwaVersion' => $this->pwaVersion(),
'debug' => $debug
]);
}

public function pwaUnregister(Request $Request, bool $debug)
{
return $this->twig->display('@Aurora/pwa.unregister.html.twig', [
'host' => $Request->getHost(),
'pwa' => (bool)($Request->isSecure() || preg_match('/(.*\.localhost$|^localhost$)/i', $Request->getHost())),
'build' => $this->getBuild(),
'debug' => $debug
'host' => $Request->getHost(),
'pwa' => (bool)($Request->isSecure() || preg_match('/(.*\.localhost$|^localhost$)/i', $Request->getHost())),
'build' => $this->getBuild(),
'pwaVersion' => $this->pwaVersion(),
'debug' => $debug
]);
}

Expand Down Expand Up @@ -447,7 +467,7 @@ public function compressCSSJS(Request $Request, string $assetType, bool $combine
if (!preg_match('/http:|https:|ftp:/', $assetWebPath)) {

$assetContent = file_get_contents($assetAbsPath);
if('js' == $assetType) {
if ('js' == $assetType) {
/**
* HightChart bug: `/(NaN| {2}|^$)/` will be replaced with `/(NaN|{2}|^$)/`
*/
Expand Down
2 changes: 1 addition & 1 deletion src/templates/pwa-main.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if ('serviceWorker' in navigator) {
var serviceWorkerPath = document.currentScript.getAttribute('service-worker');
var serviceWorkerVersion = '{{ build }}'; {# document.currentScript.getAttribute('service-worker-version')#};
var serviceWorkerVersion = '{{ pwaVersion }}'; {# document.currentScript.getAttribute('service-worker-version')#};
var serviceWorkerDebug = document.currentScript.getAttribute('service-worker-debug');
let deferredPrompt;

Expand Down
4 changes: 2 additions & 2 deletions src/templates/pwa-sw.js.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var PRECACHE = 'precache-{{ build }}';
var RUNTIME = 'runtime-{{ build }}';
var PRECACHE = 'precache-{{ pwaVersion }}';
var RUNTIME = 'runtime-{{ pwaVersion }}';

{% set _debug = app.debug %}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/pwa.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{# The Service Worker is a background script that a browser can run even while a user isn't on your page. It's the thing that provides offline support, and wakes up when a notification is triggered. #}
{# PWS works only on secured (HTTPS) connection #}
{% if pwa %}
<script src="{{ asset('/pwa-main.js') }}" service-worker="{{ asset('/pwa-sw.js') }}" service-worker-version="{{ build }}" service-worker-debug="{{ debug ? 1 : 0 }}" nonce="{{ aurora.nonce() }}"></script>
<script src="{{ asset('/pwa-main.js') }}" service-worker="{{ asset('/pwa-sw.js') }}" service-worker-version="{{ pwaVersion }}" service-worker-debug="{{ debug ? 1 : 0 }}" nonce="{{ aurora.nonce() }}"></script>
{% endif %}

0 comments on commit f0a0e5d

Please sign in to comment.