DawnC commited on
Commit
c2e63e5
·
1 Parent(s): 40363f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -31
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
- (function() {
457
- // 當文檔載入完成時執行
458
- document.addEventListener('DOMContentLoaded', function() {
459
- // 記錄環境信息
460
- console.log('頁面已載入');
461
- console.log('URL:', window.location.href);
462
-
463
- // 檢查是否在正確的環境中
464
- if (window.self === window.top) {
465
- console.log('在主視窗中執行');
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