Use a dynamic (title / URL) manifest

This commit is contained in:
Bernd Bestel 2023-08-01 17:12:35 +02:00
parent 8b444a03e5
commit b74fbddd94
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 24 additions and 16 deletions

View File

@ -38,6 +38,28 @@ class SystemController extends BaseController
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl($this->GetEntryPageRelative()));
}
public function Manifest(Request $request, Response $response, array $args)
{
$data = explode('#', base64_decode($request->getQueryParams()['data']));
$manifest = [
'name' => $data[0] . ' | Grocy',
'short_name' => $data[0] . ' | Grocy',
'icons' => [[
'src' => './img/icon-1024.png',
'sizes'=> '1024x1024',
'type' => 'image/png'
]],
'start_url' => $data[1],
'background_color' => '#333131',
'theme_color' => '#333131',
'display' => 'standalone'
];
$response->getBody()->write(json_encode($manifest));
return $response->withHeader('Content-Type', 'application/json');
}
private function GetEntryPageRelative()
{
if (defined('GROCY_ENTRY_PAGE'))

View File

@ -1,15 +0,0 @@
{
"name": "Grocy",
"short_name": "Grocy",
"icons": [
{
"src": "./img/icon-1024.png",
"sizes": "1024x1024",
"type": "image/png"
}
],
"start_url": "../",
"background_color": "#333131",
"theme_color": "#333131",
"display": "standalone"
}

View File

@ -9,6 +9,7 @@ $app->group('', function (RouteCollectorProxy $group) {
// System routes
$group->get('/', '\Grocy\Controllers\SystemController:Root')->setName('root');
$group->get('/about', '\Grocy\Controllers\SystemController:About');
$group->get('/manifest', '\Grocy\Controllers\SystemController:Manifest');
$group->get('/barcodescannertesting', '\Grocy\Controllers\SystemController:BarcodeScannerTesting');
// Login routes

View File

@ -16,7 +16,7 @@
sizes="32x32"
href="{{ $U('/img/icon-32.png?v=', true) }}{{ $version }}">
<link rel="manifest"
href="{{ $U('/manifest.json?v=', true) }}{{ $version }}">
href="{{ $U('/manifest') . '?data=' . base64_encode($__env->yieldContent('title') . '#' . $U($_SERVER['REQUEST_URI'])) }}">
<title>@yield('title') | Grocy</title>