2017-10-27 23:29:07 -04:00
|
|
|
from django.http import JsonResponse
|
2017-10-28 00:05:54 -04:00
|
|
|
from django.urls import reverse
|
2018-04-19 22:35:51 -04:00
|
|
|
from ..favicons import icons
|
2017-10-27 23:29:07 -04:00
|
|
|
from lemoncurry import utils
|
2017-10-28 00:05:54 -04:00
|
|
|
from lemoncurry.theme import color
|
2017-10-27 23:29:07 -04:00
|
|
|
from urllib.parse import urljoin
|
2017-10-28 00:05:54 -04:00
|
|
|
from textwrap import shorten
|
2017-10-27 23:29:07 -04:00
|
|
|
|
|
|
|
|
2018-04-19 22:35:51 -04:00
|
|
|
def manifest_icons(base):
|
|
|
|
return [{'src': i.url, 'type': i.mime, 'sizes': i.sizes} for i in sorted(icons, key=lambda i: i.size)]
|
|
|
|
|
|
|
|
|
2017-10-27 23:29:07 -04:00
|
|
|
def manifest(request):
|
2017-10-28 00:05:54 -04:00
|
|
|
base = utils.origin(request)
|
|
|
|
start_url = reverse('home:index') + '?utm_source=homescreen'
|
|
|
|
|
2017-10-27 23:29:07 -04:00
|
|
|
app = {
|
2017-10-28 21:12:39 -04:00
|
|
|
'name': request.site.name,
|
|
|
|
'short_name': shorten(request.site.name, width=20, placeholder=''),
|
2018-04-19 22:35:51 -04:00
|
|
|
'icons': manifest_icons(base),
|
2017-10-28 00:05:54 -04:00
|
|
|
|
|
|
|
'display': 'browser',
|
|
|
|
'start_url': urljoin(base, start_url),
|
|
|
|
|
|
|
|
'background_color': color(0),
|
|
|
|
'theme_color': color(2),
|
2017-10-27 23:29:07 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 22:35:51 -04:00
|
|
|
# icons = FaviconImg.objects.filter(
|
|
|
|
# faviconFK__isFavicon=True,
|
|
|
|
# rel__in=rels,
|
|
|
|
# ).order_by('size')
|
|
|
|
# app['icons'] = [{
|
|
|
|
# 'type': 'image/png',
|
|
|
|
# 'sizes': '{0}x{0}'.format(icon.size),
|
|
|
|
# 'src': urljoin(base, icon.faviconImage.url),
|
|
|
|
# } for icon in icons]
|
2017-10-27 23:29:07 -04:00
|
|
|
|
|
|
|
return JsonResponse(app, content_type='application/manifest+json')
|