DawnC commited on
Commit
6807bb0
·
verified ·
1 Parent(s): 3ac1970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -41
app.py CHANGED
@@ -439,58 +439,58 @@ def show_details_html(choice, previous_output, initial_state):
439
 
440
 
441
  def get_pwa_html():
442
- base_url = "https://dawnc-pawmatchai.hf.space"
443
- manifest_content = f'''{{
444
- "name": "PawMatch AI",
445
- "short_name": "PawMatch",
446
- "start_url": "{base_url}/",
447
- "display": "standalone",
448
- "background_color": "#ffffff",
449
- "theme_color": "#4299e1",
450
- "icons": [
451
- {{
452
- "src": "{base_url}/icon-192.png",
453
- "sizes": "192x192",
454
- "type": "image/png"
455
- }}
456
- ]
457
- }}'''
458
 
459
- return f"""
 
460
  <!DOCTYPE html>
461
  <meta charset="UTF-8">
462
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
463
  <meta name="apple-mobile-web-app-capable" content="yes">
464
- <meta name="apple-mobile-web-app-status-bar-style" content="default">
465
  <meta name="theme-color" content="#4299e1">
 
466
 
467
- <script type="application/json" id="pwa-manifest">
468
- {manifest_content}
469
- </script>
470
-
471
  <script>
472
- window.addEventListener('load', function() {{
473
- try {{
474
- const manifestContent = document.getElementById('pwa-manifest').textContent;
475
- const manifestBlob = new Blob([manifestContent], {{type: 'application/json'}});
476
- const manifestUrl = URL.createObjectURL(manifestBlob);
477
- const manifestLink = document.createElement('link');
478
- manifestLink.rel = 'manifest';
479
- manifestLink.href = manifestUrl;
480
- document.head.appendChild(manifestLink);
481
- }} catch (error) {{
482
- console.error('Manifest registration error:', error);
483
- }}
484
- }});
485
  </script>
 
486
 
 
 
487
  <style>
488
- body {{
489
- overscroll-behavior-y: none;
490
- -webkit-overflow-scrolling: touch;
491
- }}
 
492
  </style>
493
- """
 
 
494
 
495
  def main():
496
  with gr.Blocks(css=get_css_styles()) as iface:
 
439
 
440
 
441
  def get_pwa_html():
442
+ # 先定義基本的 manifest 內容,使用最簡單的字串連接方式
443
+ manifest = (
444
+ '{'
445
+ '"name": "PawMatch AI",'
446
+ '"short_name": "PawMatch",'
447
+ '"start_url": "/index.html",'
448
+ '"display": "standalone",'
449
+ '"background_color": "#ffffff",'
450
+ '"theme_color": "#4299e1",'
451
+ '"icons": [{'
452
+ ' "src": "/icon-192.png",'
453
+ ' "sizes": "192x192",'
454
+ ' "type": "image/png"'
455
+ '}]'
456
+ '}'
457
+ )
458
 
459
+ # 構建 HTML,避免使用複雜的格式化
460
+ html = '''
461
  <!DOCTYPE html>
462
  <meta charset="UTF-8">
463
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
464
  <meta name="apple-mobile-web-app-capable" content="yes">
 
465
  <meta name="theme-color" content="#4299e1">
466
+ '''
467
 
468
+ # 添加 manifest 相關代碼
469
+ html += f'''
 
 
470
  <script>
471
+ window.addEventListener('load', function() {{
472
+ var manifest = {manifest};
473
+ var blob = new Blob([JSON.stringify(manifest)], {{type: 'application/json'}});
474
+ var link = document.createElement('link');
475
+ link.rel = 'manifest';
476
+ link.href = URL.createObjectURL(blob);
477
+ document.head.appendChild(link);
478
+ }});
 
 
 
 
 
479
  </script>
480
+ '''
481
 
482
+ # 添加基本樣式
483
+ html += '''
484
  <style>
485
+ body {
486
+ margin: 0;
487
+ padding: 0;
488
+ -webkit-overflow-scrolling: touch;
489
+ }
490
  </style>
491
+ '''
492
+
493
+ return html
494
 
495
  def main():
496
  with gr.Blocks(css=get_css_styles()) as iface: