Skip to content

Commit

Permalink
Fix Manifest injection when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 1, 2024
1 parent c4a6ed9 commit febffa6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Twig/PwaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
private string $manifestPublicUrl;

public function __construct(
#[Autowire('%spomky_labs_pwa.manifest.enabled%')]
private bool $manifestEnabled,
#[Autowire('%spomky_labs_pwa.sw.enabled%')]
private bool $serviceWorkerEnabled,
#[Autowire('@asset_mapper.importmap.config_reader')]
private ImportMapConfigReader $importMapConfigReader,
private AssetMapperInterface $assetMapper,
Expand All @@ -40,12 +44,23 @@ public function load(
bool $injectSW = true,
array $swAttributes = []
): string {
$url = $this->assetMapper->getPublicPath($this->manifestPublicUrl) ?? $this->manifestPublicUrl;
$output = sprintf('%s<link rel="manifest" href="%s">', PHP_EOL, $url);
$output = '';
if ($this->manifestEnabled === true) {
$output = $this->injectManifestFile($output);
}
if ($this->serviceWorkerEnabled === true) {
$output = $this->injectServiceWorker($output, $injectSW, $swAttributes);
}
$output = $this->injectIcons($output, $injectIcons);
$output = $this->injectThemeColor($output, $injectThemeColor);

return $this->injectServiceWorker($output, $injectSW, $swAttributes);
return $this->injectThemeColor($output, $injectThemeColor);
}

private function injectManifestFile(string $output): string
{
$url = $this->assetMapper->getPublicPath($this->manifestPublicUrl) ?? $this->manifestPublicUrl;

return $output . sprintf('%s<link rel="manifest" href="%s">', PHP_EOL, $url);
}

private function injectThemeColor(string $output, bool $themeColor): string
Expand Down

0 comments on commit febffa6

Please sign in to comment.