DawnC commited on
Commit
5a04b2f
·
1 Parent(s): 0a49bef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -17
app.py CHANGED
@@ -444,28 +444,37 @@ def main():
444
  gr.HTML("""
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-title" content="PawMatch AI">
 
 
 
448
  <link rel="manifest" href="manifest.json">
449
  <link rel="apple-touch-icon" href="assets/icon-192.png">
450
 
 
451
  <script>
452
- (function() {
453
- // 等待 DOM 完全載入
454
- document.addEventListener('DOMContentLoaded', function() {
455
- // 延遲 Service Worker 註冊,等待 Gradio 完成初始化
456
- setTimeout(function() {
457
- if ('serviceWorker' in navigator) {
458
- navigator.serviceWorker.register('service-worker.js')
459
- .then(function(registration) {
460
- console.log('Service Worker 註冊成功:', registration.scope);
461
- })
462
- .catch(function(error) {
463
- console.error('Service Worker 註冊失敗:', error);
464
- });
465
- }
466
- }, 2000);
467
- });
468
- })();
 
 
 
 
469
  </script>
470
  """)
471
 
 
444
  gr.HTML("""
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
  <meta name="apple-mobile-web-app-title" content="PawMatch AI">
449
+ <meta name="theme-color" content="#4299e1">
450
+
451
+ <!-- PWA 必要檔案的連結,使用相對路徑 -->
452
  <link rel="manifest" href="manifest.json">
453
  <link rel="apple-touch-icon" href="assets/icon-192.png">
454
 
455
+ <!-- Service Worker 註冊程序 -->
456
  <script>
457
+ // 等待頁面完全載入後再註冊 Service Worker
458
+ document.addEventListener('DOMContentLoaded', function() {
459
+ // 確保我們不是在 iframe 中執行
460
+ if (window.self === window.top) {
461
+ // 確認瀏覽器支援 Service Worker
462
+ if ('serviceWorker' in navigator) {
463
+ // 使用相對路徑註冊 Service Worker
464
+ navigator.serviceWorker.register('service-worker.js')
465
+ .then(function(registration) {
466
+ console.log('Service Worker 註冊成功,範圍:', registration.scope);
467
+ })
468
+ .catch(function(error) {
469
+ console.log('Service Worker 註冊失敗:', error);
470
+ });
471
+ } else {
472
+ console.log('此瀏覽器不支援 Service Worker');
473
+ }
474
+ } else {
475
+ console.log('在 iframe 中執行,跳過 Service Worker 註冊');
476
+ }
477
+ });
478
  </script>
479
  """)
480