DawnC commited on
Commit
156a477
·
1 Parent(s): a7bc3f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -443,21 +443,29 @@ def main():
443
  gr.HTML("""
444
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
445
  <meta name="apple-mobile-web-app-capable" content="yes">
 
446
  """)
447
-
448
- # 第二步:加入 manifest
449
  gr.HTML("""
450
- <link rel="manifest" href="manifest.json">
 
451
  """)
452
-
453
- # 第三步:最後加入 Service Worker
454
- gr.HTML(f"""
455
  <script>
456
- if ('serviceWorker' in navigator) {{
457
- navigator.serviceWorker.register('service-worker.js')
458
- .then(registration => console.log('成功'))
459
- .catch(error => console.error('失敗:', error));
460
- }}
 
 
 
 
 
 
461
  </script>
462
  """)
463
  # Header HTML
 
443
  gr.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
+ # 第二層:添加 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
+ # 第三層:Service Worker 註冊
456
+ gr.HTML("""
457
  <script>
458
+ if ('serviceWorker' in navigator) {
459
+ window.addEventListener('load', function() {
460
+ navigator.serviceWorker.register('./service-worker.js')
461
+ .then(function(registration) {
462
+ console.log('成功註冊 Service Worker');
463
+ })
464
+ .catch(function(error) {
465
+ console.log('Service Worker 註冊失敗:', error);
466
+ });
467
+ });
468
+ }
469
  </script>
470
  """)
471
  # Header HTML