Converted manifest file into dynamic endpoint

This commit is contained in:
CasVT
2025-04-24 13:51:43 +02:00
parent 2fbc460893
commit 4f77435801
8 changed files with 53 additions and 60 deletions

View File

@@ -298,15 +298,8 @@ class MigrateUpdateManifest(DBMigrator):
def run(self) -> None:
# V9 -> V10
# Nothing is changed in the database
# It's just that this code needs to run once
# and the DB migration system does exactly that:
# run pieces of code once.
from backend.internals.settings import Settings, update_manifest
update_manifest(
Settings().get_settings().url_prefix
)
# There used to be a migration here that fixed the manifest file.
# That has since been replaced by the dynamic endpoint serving the JSON.
# So the migration doesn't do anything anymore, and a function used
# doesn't exist anymore, so the whole migration is just removed.
return

View File

@@ -139,15 +139,13 @@ class Settings(metaclass=Singleton):
reversed_tuples(formatted_data.items())
)
for key, handler in (
('url_prefix', update_manifest),
('log_level', set_log_level)
if (
'log_level' in data
and formatted_data['log_level'] != getattr(
self.get_settings(), 'log_level'
)
):
if (
key in data
and formatted_data[key] != getattr(self.get_settings(), key)
):
handler(formatted_data[key])
set_log_level(formatted_data['log_level'])
self._fetch_settings()
@@ -232,24 +230,3 @@ class Settings(metaclass=Singleton):
raise InvalidKeyValue(key, value)
return converted_value
def update_manifest(url_base: str) -> None:
"""Update the url's in the manifest file.
Needs to happen when url base changes.
Args:
url_base (str): The url base to use in the file.
"""
filename = folder_path('frontend', 'static', 'json', 'pwa_manifest.json')
with open(filename, 'r') as f:
manifest = load(f)
manifest['start_url'] = url_base + '/'
manifest['scope'] = url_base + '/'
manifest['icons'][0]['src'] = f'{url_base}/static/img/favicon.svg'
with open(filename, 'w') as f:
dump(manifest, f, indent=4)
return

View File

@@ -385,6 +385,11 @@ class UrlPrefixVariable(NonRequiredInputVariable):
name = "url_prefix"
description = "The base URL to run on. Useful for reverse proxies. Empty string to disable."
def validate(self) -> bool:
return self.value is None or (
isinstance(self.value, str)
)
class LogLevelVariable(NonRequiredInputVariable):
name = "log_level"

View File

@@ -1,17 +0,0 @@
{
"name": "MIND",
"short_name": "MIND",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#1b1b1b",
"theme_color": "#6b6b6b",
"orientation": "portrait-primary",
"icons": [
{
"src": "/static/img/favicon.svg",
"type": "image/svg+xml",
"sizes": "64x64 32x32 24x24 16x16"
}
]
}

View File

@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta id="url_prefix" data-value="{{url_prefix}}">
<link rel="manifest" href="{{ url_for('static', filename='json/pwa_manifest.json') }}">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/favicon.svg') }}">
<meta name="apple-mobile-web-app-status-bar" content="#6b6b6b">
<meta name="theme-color" content="#6b6b6b">

View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta id="url_prefix" data-value="{{url_prefix}}">
<link rel="manifest" href="{{ url_for('static', filename='json/pwa_manifest.json') }}">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/favicon.svg') }}">
<meta name="apple-mobile-web-app-status-bar" content="#6b6b6b">
<meta name="theme-color" content="#6b6b6b">

View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta id="url_prefix" data-value="{{url_prefix}}">
<link rel="manifest" href="{{ url_for('static', filename='json/pwa_manifest.json') }}">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/favicon.svg') }}">
<meta name="apple-mobile-web-app-status-bar" content="#6b6b6b">
<meta name="theme-color" content="#6b6b6b">

View File

@@ -20,6 +20,41 @@ def ui_not_found(e):
return render('page_not_found.html')
@ui.route('/manifest.json', methods=methods)
def ui_manifest():
from io import BytesIO
from json import dumps
from flask import send_file
return send_file(
BytesIO(dumps(
{
"name": "MIND",
"short_name": "MIND",
"description": "MIND is a simple self hosted reminder application that can send push notifications to your device. Set the reminder and forget about it!",
"display": "standalone",
"orientation": "portrait-primary",
"start_url": f"{SERVER.url_prefix}/",
"scope": f"{SERVER.url_prefix}/",
"id": f"{SERVER.url_prefix}/",
"background_color": "#1b1b1b",
"theme_color": "#6b6b6b",
"icons": [
{
"src": f"{SERVER.url_prefix}/static/img/favicon.svg",
"type": "image/svg+xml",
"sizes": "any"
}
]
},
indent=4
).encode('utf-8')),
mimetype="application/manifest+json",
download_name="manifest.json"
), 200
@ui.route('/', methods=methods)
def ui_login():
return render('login.html')