mirror of
https://github.com/Casvt/MIND.git
synced 2026-02-19 11:54:46 -05:00
Added support for PWA
This commit is contained in:
@@ -21,7 +21,7 @@ from backend.custom_exceptions import (AccessUnauthorized, InvalidDatabaseFile,
|
||||
from backend.helpers import RestartVars, folder_path
|
||||
|
||||
DB_FILENAME = 'db', 'MIND.db'
|
||||
__DATABASE_VERSION__ = 9
|
||||
__DATABASE_VERSION__ = 10
|
||||
__DATEBASE_NAME_ORIGINAL__ = "MIND_original.db"
|
||||
|
||||
class DB_Singleton(type):
|
||||
@@ -283,6 +283,22 @@ def migrate_db(current_db_version: int) -> None:
|
||||
|
||||
current_db_version = 9
|
||||
|
||||
if current_db_version == 9:
|
||||
# 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.settings import update_manifest
|
||||
|
||||
url_prefix: str = cursor.execute(
|
||||
"SELECT value FROM config WHERE key = 'url_prefix' LIMIT 1;"
|
||||
).fetchone()[0]
|
||||
update_manifest(url_prefix)
|
||||
|
||||
current_db_version = 10
|
||||
|
||||
return
|
||||
|
||||
def setup_db() -> None:
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
Getting and setting settings
|
||||
"""
|
||||
|
||||
from json import dumps, loads
|
||||
from typing import Any
|
||||
|
||||
from backend.custom_exceptions import InvalidKeyValue, KeyNotFound
|
||||
from backend.db import __DATABASE_VERSION__, get_db
|
||||
from backend.helpers import folder_path
|
||||
|
||||
default_settings = {
|
||||
'allow_new_accounts': True,
|
||||
@@ -143,6 +145,25 @@ def set_setting(key: str, value: Any) -> None:
|
||||
"UPDATE config SET value = ? WHERE key = ?;",
|
||||
(value, key)
|
||||
)
|
||||
|
||||
if key == 'url_prefix':
|
||||
update_manifest(value)
|
||||
|
||||
return
|
||||
|
||||
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.
|
||||
"""
|
||||
with open(folder_path('frontend', 'static', 'json', 'manifest.json'), 'r+') as f:
|
||||
manifest = loads(f.read())
|
||||
manifest['start_url'] = url_base + '/'
|
||||
manifest['icons'][0]['src'] = f'{url_base}/static/img/favicon.svg'
|
||||
f.seek(0)
|
||||
f.write(dumps(manifest, indent=4))
|
||||
return
|
||||
|
||||
def backup_hosting_settings() -> None:
|
||||
|
||||
18
frontend/static/json/manifest.json
Normal file
18
frontend/static/json/manifest.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "MIND",
|
||||
"short_name": "MIND",
|
||||
"start_url": "/",
|
||||
"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"
|
||||
}
|
||||
]
|
||||
} }
|
||||
]
|
||||
}
|
||||
@@ -5,6 +5,11 @@
|
||||
<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/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">
|
||||
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.svg') }}" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/general.css') }}">
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
<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/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">
|
||||
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.svg') }}" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/general.css') }}">
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
<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/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">
|
||||
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.svg') }}" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/general.css') }}">
|
||||
|
||||
Reference in New Issue
Block a user