Добавление PWA

This commit is contained in:
Petro1990 2025-11-24 23:13:24 +03:00
parent 682a5ecb13
commit bfb684dded
5 changed files with 57 additions and 2 deletions

View File

@ -36,8 +36,16 @@ mkdir -p "$INIT_DIR"
mkdir -p "/opt/etc/mihomo/profiles"
mkdir -p "/opt/etc/mihomo/backup"
# 3. Скачивание файлов
echo "[3/4] Скачивание файлов с сервера..."
# Создаем директорию для PWA
mkdir -p "/opt/etc/mihomo/public/icons"
# 3. Скачивание и копирование файлов
echo "[3/4] Скачивание и копирование файлов..."
# Копируем локальные PWA файлы
echo "Копирование PWA файлов..."
cp -f public/manifest.json /opt/etc/mihomo/public/manifest.json
cp -f public/icons/*.png /opt/etc/mihomo/public/icons/
# Скачиваем основной скрипт
echo "Загрузка $PY_SCRIPT..."

View File

@ -164,6 +164,8 @@ HTML_TEMPLATE = """<!DOCTYPE html>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<title>Mihomo Editor v18.4</title>
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/icons/icon-192x192.png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.7/ace.js"></script>
<style>
:root {
@ -777,6 +779,30 @@ class H(http.server.SimpleHTTPRequestHandler):
pass # Silent fail to avoid crashing
def do_GET(s):
if s.path == '/manifest.json':
try:
with open('public/manifest.json', 'rb') as f:
s.send_response(200)
s.send_header('Content-type', 'application/json')
s.end_headers()
s.wfile.write(f.read())
except FileNotFoundError:
s.send_error(404, "File not found")
return
if s.path.startswith('/icons/'):
try:
# Sanitize path to prevent directory traversal
safe_path = os.path.join('public', s.path[1:]).replace('\\\\', '/')
with open(safe_path, 'rb') as f:
s.send_response(200)
s.send_header('Content-type', 'image/png')
s.end_headers()
s.wfile.write(f.read())
except FileNotFoundError:
s.send_error(404, "File not found")
return
if s.path.startswith('/mihomo_panel/'):
s.proxy_pass('GET')
return

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

21
public/manifest.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "Mihomo Studio",
"short_name": "Mihomo",
"start_url": "/",
"display": "standalone",
"background_color": "#1a1a1a",
"theme_color": "#1a1a1a",
"description": "Mihomo Config Editor",
"icons": [
{
"src": "/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}