Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -445,41 +445,26 @@ def main():
|
|
| 445 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 446 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 447 |
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
| 448 |
-
<link rel="manifest" href="manifest.json">
|
| 449 |
-
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
| 450 |
""")
|
| 451 |
-
|
| 452 |
-
# 第二步:添加一個簡單的初始化檢查
|
| 453 |
gr.HTML("""
|
| 454 |
<script>
|
| 455 |
-
|
| 456 |
-
(
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
// 嘗試註冊 Service Worker
|
| 468 |
-
if ('serviceWorker' in navigator) {
|
| 469 |
-
// 使用延遲註冊以確保不會干擾頁面載入
|
| 470 |
-
setTimeout(function() {
|
| 471 |
-
navigator.serviceWorker.register('service-worker.js')
|
| 472 |
-
.then(function(registration) {
|
| 473 |
-
console.log('Service Worker 註冊成功');
|
| 474 |
-
})
|
| 475 |
-
.catch(function(error) {
|
| 476 |
-
console.error('Service Worker 註冊失敗:', error);
|
| 477 |
-
});
|
| 478 |
-
}, 1000);
|
| 479 |
-
}
|
| 480 |
-
}
|
| 481 |
});
|
| 482 |
-
}
|
|
|
|
| 483 |
</script>
|
| 484 |
""")
|
| 485 |
|
|
|
|
| 445 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 446 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 447 |
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
| 448 |
+
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials">
|
| 449 |
+
<link rel="apple-touch-icon" href="/assets/icon-192.png">
|
| 450 |
""")
|
| 451 |
+
|
|
|
|
| 452 |
gr.HTML("""
|
| 453 |
<script>
|
| 454 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 455 |
+
if ('serviceWorker' in navigator) {
|
| 456 |
+
const swPath = new URL('service-worker.js', window.location.href).href;
|
| 457 |
+
navigator.serviceWorker.register(swPath, {
|
| 458 |
+
scope: './'
|
| 459 |
+
})
|
| 460 |
+
.then(registration => {
|
| 461 |
+
console.log('Service Worker 註冊成功:', registration);
|
| 462 |
+
})
|
| 463 |
+
.catch(error => {
|
| 464 |
+
console.error('Service Worker 註冊失敗:', error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
});
|
| 466 |
+
}
|
| 467 |
+
});
|
| 468 |
</script>
|
| 469 |
""")
|
| 470 |
|