DawnC commited on
Commit
4864eeb
·
1 Parent(s): 727ad73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -445,26 +445,32 @@ 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" 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
 
 
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
  gr.HTML("""
453
  <script>
454
+ // 等待頁面完全載入後再註冊 Service Worker
455
+ document.addEventListener('DOMContentLoaded', function() {
456
+ // 確認瀏覽器支援 Service Worker
457
+ if ('serviceWorker' in navigator) {
458
+ // 使用相對路徑註冊 Service Worker
459
+ try {
460
+ navigator.serviceWorker.register('./service-worker.js', {
461
+ scope: './'
462
+ }).then(function(registration) {
463
+ console.log('Service Worker 註冊成功,範圍:', registration.scope);
464
+ }).catch(function(error) {
465
+ console.error('Service Worker 註冊失敗:', error.message);
466
+ });
467
+ } catch(e) {
468
+ console.error('Service Worker 註冊時發生錯誤:', e.message);
469
+ }
470
+ } else {
471
+ console.log('此瀏覽器不支援 Service Worker');
472
+ }
473
+ });
474
  </script>
475
  """)
476