Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -444,26 +444,36 @@ def main():
|
|
444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
445 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
446 |
<meta name="apple-mobile-web-app-title" content="PawMatch AI">
|
|
|
|
|
|
|
|
|
447 |
<link rel="manifest" href="manifest.json">
|
448 |
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
449 |
""")
|
450 |
-
|
451 |
-
#
|
452 |
gr.HTML("""
|
453 |
<script>
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
</script>
|
468 |
""")
|
469 |
# Header HTML
|
|
|
444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
445 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
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 |
+
(function() {
|
459 |
+
// 確保在正確的網域上運行
|
460 |
+
var currentDomain = window.location.hostname;
|
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('Service Worker 註冊成功');
|
469 |
+
})
|
470 |
+
.catch(function(err) {
|
471 |
+
console.log('Service Worker 註冊失敗:', err);
|
472 |
+
});
|
473 |
+
}
|
474 |
+
});
|
475 |
+
}
|
476 |
+
})();
|
477 |
</script>
|
478 |
""")
|
479 |
# Header HTML
|