Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -438,7 +438,24 @@ def show_details_html(choice, previous_output, initial_state):
|
|
| 438 |
|
| 439 |
|
| 440 |
def get_pwa_html():
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
<!DOCTYPE html>
|
| 443 |
<meta charset="UTF-8">
|
| 444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
@@ -446,39 +463,48 @@ def get_pwa_html():
|
|
| 446 |
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
| 447 |
<meta name="theme-color" content="#4299e1">
|
| 448 |
|
| 449 |
-
<
|
| 450 |
-
|
|
|
|
| 451 |
|
| 452 |
<script>
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
</script>
|
| 465 |
|
| 466 |
<style>
|
| 467 |
-
body {
|
| 468 |
overscroll-behavior-y: none;
|
| 469 |
-webkit-overflow-scrolling: touch;
|
| 470 |
-
|
| 471 |
-
width: 100%;
|
| 472 |
-
height: 100%;
|
| 473 |
-
overflow: auto;
|
| 474 |
-
}
|
| 475 |
|
| 476 |
-
@
|
| 477 |
-
body {
|
| 478 |
-
padding-top: env(safe-area-inset-top);
|
| 479 |
-
padding-bottom: env(safe-area-inset-bottom);
|
| 480 |
-
}
|
| 481 |
-
}
|
| 482 |
</style>
|
| 483 |
"""
|
| 484 |
|
|
|
|
| 438 |
|
| 439 |
|
| 440 |
def get_pwa_html():
|
| 441 |
+
# 將 manifest 內容直接嵌入到 HTML 中
|
| 442 |
+
manifest_content = {
|
| 443 |
+
"name": "PawMatch AI",
|
| 444 |
+
"short_name": "PawMatch",
|
| 445 |
+
"start_url": ".",
|
| 446 |
+
"display": "standalone",
|
| 447 |
+
"background_color": "#ffffff",
|
| 448 |
+
"theme_color": "#4299e1",
|
| 449 |
+
"icons": [
|
| 450 |
+
{
|
| 451 |
+
"src": "icon-192.png",
|
| 452 |
+
"sizes": "192x192",
|
| 453 |
+
"type": "image/png"
|
| 454 |
+
}
|
| 455 |
+
]
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
return f"""
|
| 459 |
<!DOCTYPE html>
|
| 460 |
<meta charset="UTF-8">
|
| 461 |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
|
| 463 |
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
| 464 |
<meta name="theme-color" content="#4299e1">
|
| 465 |
|
| 466 |
+
<script type="application/json" id="pwa-manifest">
|
| 467 |
+
{json.dumps(manifest_content)}
|
| 468 |
+
</script>
|
| 469 |
|
| 470 |
<script>
|
| 471 |
+
// 動態創建和註冊 manifest
|
| 472 |
+
const manifestContent = document.getElementById('pwa-manifest').textContent;
|
| 473 |
+
const manifestBlob = new Blob([manifestContent], {{type: 'application/json'}});
|
| 474 |
+
const manifestUrl = URL.createObjectURL(manifestBlob);
|
| 475 |
+
const manifestLink = document.createElement('link');
|
| 476 |
+
manifestLink.rel = 'manifest';
|
| 477 |
+
manifestLink.href = manifestUrl;
|
| 478 |
+
document.head.appendChild(manifestLink);
|
| 479 |
+
|
| 480 |
+
// 簡化版 Service Worker
|
| 481 |
+
if ('serviceWorker' in navigator) {{
|
| 482 |
+
window.addEventListener('load', async () => {{
|
| 483 |
+
try {{
|
| 484 |
+
const registration = await navigator.serviceWorker.register(
|
| 485 |
+
new URL('service-worker.js', window.location.href),
|
| 486 |
+
{{scope: './'}}
|
| 487 |
+
);
|
| 488 |
+
console.log('ServiceWorker registered');
|
| 489 |
+
}} catch (err) {{
|
| 490 |
+
console.log('ServiceWorker registration failed:', err);
|
| 491 |
+
}}
|
| 492 |
+
}});
|
| 493 |
+
}}
|
| 494 |
</script>
|
| 495 |
|
| 496 |
<style>
|
| 497 |
+
body {{
|
| 498 |
overscroll-behavior-y: none;
|
| 499 |
-webkit-overflow-scrolling: touch;
|
| 500 |
+
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
+
@supports (padding: max(0px)) {{
|
| 503 |
+
body {{
|
| 504 |
+
padding-top: max(0px, env(safe-area-inset-top));
|
| 505 |
+
padding-bottom: max(0px, env(safe-area-inset-bottom));
|
| 506 |
+
}}
|
| 507 |
+
}}
|
| 508 |
</style>
|
| 509 |
"""
|
| 510 |
|