Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -446,36 +446,31 @@ def main():
|
|
446 |
<meta name="apple-mobile-web-app-title" content="PawMatch AI">
|
447 |
""")
|
448 |
|
449 |
-
# 2. PWA
|
450 |
-
gr.HTML("""
|
451 |
-
<link rel="manifest" href="manifest.json">
|
452 |
-
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
453 |
-
""")
|
454 |
-
|
455 |
-
# 3. 安全的 Service Worker 註冊
|
456 |
gr.HTML("""
|
457 |
<script>
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
if (currentDomain.includes('hf.space')) {
|
462 |
-
// 等待頁面完全載入
|
463 |
-
window.addEventListener('load', function() {
|
464 |
if ('serviceWorker' in navigator) {
|
465 |
-
// 使用相對路徑
|
466 |
navigator.serviceWorker.register('service-worker.js')
|
467 |
.then(function(registration) {
|
468 |
-
console.log('
|
469 |
})
|
470 |
-
.catch(function(
|
471 |
-
console.
|
472 |
});
|
473 |
}
|
474 |
-
});
|
475 |
-
}
|
476 |
-
})();
|
477 |
</script>
|
478 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
479 |
# Header HTML
|
480 |
gr.HTML("""
|
481 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
|
|
446 |
<meta name="apple-mobile-web-app-title" content="PawMatch AI">
|
447 |
""")
|
448 |
|
449 |
+
# 2. 分離 PWA 設定,確保不影響 Gradio 的 SSE 連接
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
gr.HTML("""
|
451 |
<script>
|
452 |
+
document.addEventListener('DOMContentLoaded', function() {
|
453 |
+
// 等待 Gradio 完全初始化
|
454 |
+
setTimeout(function() {
|
|
|
|
|
|
|
455 |
if ('serviceWorker' in navigator) {
|
|
|
456 |
navigator.serviceWorker.register('service-worker.js')
|
457 |
.then(function(registration) {
|
458 |
+
console.log('ServiceWorker registration successful');
|
459 |
})
|
460 |
+
.catch(function(error) {
|
461 |
+
console.error('ServiceWorker registration failed:', error);
|
462 |
});
|
463 |
}
|
464 |
+
}, 2000); // 給予 Gradio 足夠的初始化時間
|
465 |
+
});
|
|
|
466 |
</script>
|
467 |
""")
|
468 |
+
|
469 |
+
# 3. 確保 manifest 的載入不會干擾到 Gradio
|
470 |
+
gr.HTML("""
|
471 |
+
<link rel="manifest" href="manifest.json">
|
472 |
+
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
473 |
+
""")
|
474 |
# Header HTML
|
475 |
gr.HTML("""
|
476 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|