[#413] /manifest.json should install PWAs for specific plugins.

If called on a `/plugin/<plugin>` route.
This commit is contained in:
Fabio Manganiello 2024-07-17 02:29:51 +02:00
parent b039d98c66
commit 490ed4c361
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -1,4 +1,7 @@
from flask import Blueprint, jsonify, send_from_directory from typing import Optional
from urllib.parse import urlparse
from flask import Blueprint, jsonify, request, send_from_directory
from platypush.config import Config from platypush.config import Config
from platypush.backend.http.app import template_folder from platypush.backend.http.app import template_folder
@ -11,13 +14,37 @@ __routes__ = [
] ]
def _get_plugin(url: Optional[str] = None) -> Optional[str]:
if not url:
return None
path = urlparse(url).path.lstrip('/').split('/')
if len(path) > 1 and path[0] == 'plugin':
return path[1]
return None
@pwa.route('/manifest.json', methods=['GET']) @pwa.route('/manifest.json', methods=['GET'])
def manifest_json(): def manifest_json():
"""Generated manifest file for the PWA""" """Generated manifest file for the PWA"""
device_id = Config.get_device_id()
referer = request.headers.get('Referer')
plugin = _get_plugin(referer)
start_url = '/'
name = f'Platypush @ {device_id}'
short_name = device_id
if plugin:
start_url = f'/plugin/{plugin}'
name = f'{plugin} @ {device_id}'
short_name = plugin
return jsonify( return jsonify(
{ {
"name": f'Platypush @ {Config.get("device_id")}', "name": name,
"short_name": Config.get('device_id'), "short_name": short_name,
"icons": [ "icons": [
{ {
"src": "/img/icons/favicon-16x16.png", "src": "/img/icons/favicon-16x16.png",
@ -94,7 +121,7 @@ def manifest_json():
], ],
"gcm_sender_id": "", "gcm_sender_id": "",
"gcm_user_visible_only": True, "gcm_user_visible_only": True,
"start_url": "/", "start_url": start_url,
"permissions": ["gcm"], "permissions": ["gcm"],
"orientation": "portrait", "orientation": "portrait",
"display": "standalone", "display": "standalone",