Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -443,25 +443,47 @@ def main():
|
|
443 |
# Header HTML
|
444 |
|
445 |
gr.HTML("""
|
446 |
-
<
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
</head>
|
455 |
<script>
|
|
|
456 |
if ('serviceWorker' in navigator) {
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
.
|
463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
});
|
466 |
}
|
467 |
</script>
|
|
|
443 |
# Header HTML
|
444 |
|
445 |
gr.HTML("""
|
446 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
447 |
+
<meta name="theme-color" content="#4299e1">
|
448 |
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
449 |
+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
450 |
+
<meta name="apple-mobile-web-app-title" content="PawMatch AI">
|
451 |
+
<link rel="manifest" href="manifest.json">
|
452 |
+
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
453 |
+
|
|
|
454 |
<script>
|
455 |
+
// 等待頁面完全載入後再註冊 Service Worker
|
456 |
if ('serviceWorker' in navigator) {
|
457 |
+
// 使用相對路徑以確保在 Hugging Face Space 環境中正常運作
|
458 |
+
const swPath = 'service-worker.js';
|
459 |
+
|
460 |
+
window.addEventListener('load', async () => {
|
461 |
+
try {
|
462 |
+
const registration = await navigator.serviceWorker.register(swPath);
|
463 |
+
console.log('ServiceWorker 註冊成功!範圍是:', registration.scope);
|
464 |
+
|
465 |
+
// 監聽 Service Worker 狀態變化
|
466 |
+
registration.addEventListener('updatefound', () => {
|
467 |
+
const newWorker = registration.installing;
|
468 |
+
console.log('發現新的 Service Worker');
|
469 |
+
|
470 |
+
newWorker.addEventListener('statechange', () => {
|
471 |
+
console.log('Service Worker 狀態:', newWorker.state);
|
472 |
+
});
|
473 |
});
|
474 |
+
|
475 |
+
} catch (error) {
|
476 |
+
console.error('ServiceWorker 註冊失敗:', error);
|
477 |
+
}
|
478 |
+
});
|
479 |
+
|
480 |
+
// 監聽離線/上線狀態
|
481 |
+
window.addEventListener('online', () => {
|
482 |
+
console.log('應用程式已連線');
|
483 |
+
});
|
484 |
+
|
485 |
+
window.addEventListener('offline', () => {
|
486 |
+
console.log('應用程式已離線');
|
487 |
});
|
488 |
}
|
489 |
</script>
|