From f9b929ae7d7b6eee98be49afffb7b89ba65f6d3e Mon Sep 17 00:00:00 2001 From: Lee Salminen Date: Mon, 4 Jul 2022 16:39:05 -0600 Subject: [PATCH] add PWA support for the tpos extension --- .../extensions/tpos/templates/tpos/tpos.html | 1 + lnbits/extensions/tpos/views.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 02d6a98d..e4ea1499 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -1,3 +1,4 @@ + {% extends "public.html" %} {% block toolbar_title %} {{ tpos.name }} diff --git a/lnbits/extensions/tpos/views.py b/lnbits/extensions/tpos/views.py index 2d78ecce..dbee8434 100644 --- a/lnbits/extensions/tpos/views.py +++ b/lnbits/extensions/tpos/views.py @@ -8,6 +8,10 @@ from starlette.responses import HTMLResponse from lnbits.core.models import User from lnbits.decorators import check_user_exists +from lnbits.settings import ( + LNBITS_CUSTOM_LOGO, + LNBITS_SITE_TITLE, +) from . import tpos_ext, tpos_renderer from .crud import get_tpos @@ -33,3 +37,37 @@ async def tpos(request: Request, tpos_id): return tpos_renderer().TemplateResponse( "tpos/tpos.html", {"request": request, "tpos": tpos} ) + +@tpos_ext.get("/manifest/{tpos_id}.webmanifest") +async def manifest(tpos_id: str): + tpos = await get_tpos(tpos_id) + if not tpos: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist." + ) + + return { + "short_name": LNBITS_SITE_TITLE, + "name": tpos.name + ' - ' + LNBITS_SITE_TITLE, + "icons": [ + { + "src": LNBITS_CUSTOM_LOGO if LNBITS_CUSTOM_LOGO else "https://cdn.jsdelivr.net/gh/lnbits/lnbits@0.3.0/docs/logos/lnbits.png", + "type": "image/png", + "sizes": "900x900", + } + ], + "start_url": "/tpos/" + tpos_id, + "background_color": "#1F2234", + "description": "Bitcoin Lightning tPOS", + "display": "standalone", + "scope": "/tpos/" + tpos_id, + "theme_color": "#1F2234", + "shortcuts": [ + { + "name": tpos.name + ' - ' + LNBITS_SITE_TITLE, + "short_name": tpos.name, + "description": tpos.name + ' - ' + LNBITS_SITE_TITLE, + "url": "/tpos/" + tpos_id, + } + ], + } \ No newline at end of file