Unify provider and main webapp manifest (manifest.json)

This commit is contained in:
Kacper Donat 2020-09-18 22:47:22 +02:00
parent 63c5f7572b
commit ed8c62f4bd
5 changed files with 38 additions and 58 deletions

View File

@ -1,30 +0,0 @@
{
"name": "Co Jedzie?",
"short_name": "Co Jedzie?",
"orientation": "portrait",
"lang": "pl_PL",
"start_url": ".",
"display": "standalone",
"background_color": "#005ea8",
"theme_color": "#005ea8",
"description": "Odpowiedź na odwieczne pytanie ludzkości - czy tramwaje jeżdżą?",
"icons": [{
"src": "images/icon-256.png",
"sizes": "256x256"
},{
"src": "images/icon-512.png",
"sizes": "512x512"
},{
"src": "images/icon-64.png",
"sizes": "64x64"
},{
"src": "images/icon-128.png",
"sizes": "128x128"
},{
"src": "images/icon-192.png",
"sizes": "192x192"
},{
"src": "images/icon-96.png",
"sizes": "96x96"
}]
}

View File

@ -2,7 +2,6 @@
namespace App\Controller;
use App\Provider\Provider;
use App\Service\ProviderResolver;
use Symfony\Component\HttpFoundation\Request;
@ -18,25 +17,32 @@ class MainController extends Controller
return $this->render('choose.html.twig', ['providers' => $resolver->all()]);
}
/**
* @Route("/{provider}/manifest.json", name="provider_manifest")
* @Route("/manifest.json", name="main_manifest")
*/
public function manifest(?Provider $provider = null)
{
$response = $this->render('manifest.json.twig', ['provider' => $provider]);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/{provider}", name="app")
*/
public function app(Provider $provider, Request $request)
{
$state = json_decode($request->query->get('state', '{}'), true) ?: [];
$state = array_merge([
'version' => 1,
'stops' => [],
], $state);
$state = array_merge(
[
'version' => 1,
'stops' => [],
],
$state
);
return $this->render('app.html.twig', compact('state', 'provider'));
}
/**
* @Route("/{provider}/manifest.json", name="webapp_manifest")
*/
public function manifest(Provider $provider)
{
return $this->render('manifest.json.twig', ['provider' => $provider]);
}
}
}

View File

@ -6,8 +6,8 @@ namespace App\Service;
use App\Exception\NonExistentServiceException;
use App\Provider\Dummy\DummyProvider;
use App\Provider\Provider;
use Kadet\Functional\Transforms as t;
use Kadet\Functional\Predicates as p;
use Kadet\Functional\Transforms as t;
use Tightenco\Collect\Support\Collection;
class ProviderResolver
@ -23,16 +23,19 @@ class ProviderResolver
}
}
/**\
* @param string $name
*
* @return \App\Provider\Provider
* @throws \App\Exception\NonExistentServiceException
*/
public function resolve(string $name): Provider
public function resolve(?string $name): ?Provider
{
if (empty($name)) {
return null;
}
if (!$this->providers->has($name)) {
$message = sprintf("Provider '%s' doesn't exist, you can choose from: %s", $name, $this->providers->keys()->implode(', '));
$message = sprintf(
"Provider '%s' doesn't exist, you can choose from: %s",
$name,
$this->providers->keys()->implode(', ')
);
throw new NonExistentServiceException($message);
}
@ -44,4 +47,4 @@ class ProviderResolver
{
return clone $this->providers;
}
}
}

View File

@ -1,6 +1,6 @@
{% extends 'base.html.twig' %}
{% block title "#{parent()} - #{provider.name}" %}
{% block manifest path('webapp_manifest', { provider: provider.identifier }) %}
{% block manifest path('provider_manifest', { provider: provider.identifier }) %}
{% block body %}
<main id="app" class="container not-ready">

View File

@ -1,13 +1,14 @@
{
"name": "Co Jedzie? - {{ provider.shortName }}",
"short_name": "Co Jedzie? - {{ provider.shortName }}",
"name": "Co Jedzie?{% if provider %} - {{ provider.shortName }}{% endif %}",
"short_name": "Co Jedzie?{% if provider %} - {{ provider.shortName }}{% endif %}",
"orientation": "portrait",
"lang": "pl_PL",
"start_url": "{{ path('app', { provider: provider.identifier }) }}",
"start_url": "{{ provider ? path('app', { provider: provider.identifier }) : path('choose') }}",
"display": "standalone",
"background_color": "white",
"theme_color": "white",
"description": "Odpowiedź na odwieczne pytanie ludzkości - czy tramwaje jeżdżą?",
"categories": ["navigation", "transport", "travel", "utilities"],
"icons": [{
"src": "{{ asset('images/icon-256.png') }}",
"sizes": "256x256"