DawnC commited on
Commit
b3536fa
·
1 Parent(s): 9abf257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -33
app.py CHANGED
@@ -439,8 +439,7 @@ def show_details_html(choice, previous_output, initial_state):
439
 
440
 
441
  def get_pwa_html():
442
- # manifest 內容直接嵌入到 HTML 中
443
- manifest_content = {
444
  "name": "PawMatch AI",
445
  "short_name": "PawMatch",
446
  "start_url": ".",
@@ -454,7 +453,7 @@ def get_pwa_html():
454
  "type": "image/png"
455
  }
456
  ]
457
- }
458
 
459
  return f"""
460
  <!DOCTYPE html>
@@ -463,47 +462,60 @@ def get_pwa_html():
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
- {json.dumps(manifest_content)}
469
  </script>
470
 
471
  <script>
472
- // 動態創建和註冊 manifest
473
- const manifestContent = document.getElementById('pwa-manifest').textContent;
474
- const manifestBlob = new Blob([manifestContent], {{type: 'application/json'}});
475
- const manifestUrl = URL.createObjectURL(manifestBlob);
476
- const manifestLink = document.createElement('link');
477
- manifestLink.rel = 'manifest';
478
- manifestLink.href = manifestUrl;
479
- document.head.appendChild(manifestLink);
480
-
481
- // 簡化版 Service Worker
482
- if ('serviceWorker' in navigator) {{
483
- window.addEventListener('load', async () => {{
484
- try {{
485
- const registration = await navigator.serviceWorker.register(
486
- new URL('service-worker.js', window.location.href),
487
- {{scope: './'}}
488
- );
489
- console.log('ServiceWorker registered');
490
- }} catch (err) {{
491
- console.log('ServiceWorker registration failed:', err);
492
- }}
493
- }});
494
- }}
 
 
 
 
 
 
 
 
 
495
  </script>
496
 
497
  <style>
498
- body {{
499
- overscroll-behavior-y: none;
500
- -webkit-overflow-scrolling: touch;
 
 
 
501
  }}
502
 
503
- @supports (padding: max(0px)) {{
504
  body {{
505
- padding-top: max(0px, env(safe-area-inset-top));
506
- padding-bottom: max(0px, env(safe-area-inset-bottom));
507
  }}
508
  }}
509
  </style>
 
439
 
440
 
441
  def get_pwa_html():
442
+ manifest_content = '''{
 
443
  "name": "PawMatch AI",
444
  "short_name": "PawMatch",
445
  "start_url": ".",
 
453
  "type": "image/png"
454
  }
455
  ]
456
+ }'''
457
 
458
  return f"""
459
  <!DOCTYPE html>
 
462
  <meta name="apple-mobile-web-app-capable" content="yes">
463
  <meta name="apple-mobile-web-app-status-bar-style" content="default">
464
  <meta name="theme-color" content="#4299e1">
465
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob: https:">
466
 
467
  <script type="application/json" id="pwa-manifest">
468
+ {manifest_content}
469
  </script>
470
 
471
  <script>
472
+ window.addEventListener('load', function() {{
473
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
474
+
475
+ if (isSafari) {{
476
+ document.body.classList.add('safari-browser');
477
+
478
+ const fileInputs = document.querySelectorAll('input[type="file"]');
479
+ fileInputs.forEach(input => {{
480
+ input.addEventListener('change', async function(e) {{
481
+ const file = e.target.files[0];
482
+ if (file) {{
483
+ const formData = new FormData();
484
+ formData.append('file', file);
485
+
486
+ try {{
487
+ const response = await fetch('/upload', {{
488
+ method: 'POST',
489
+ body: formData
490
+ }});
491
+
492
+ if (!response.ok) throw new Error('Upload failed');
493
+
494
+ const result = await response.json();
495
+ console.log('Upload successful:', result);
496
+ }} catch (error) {{
497
+ console.error('Upload error:', error);
498
+ }}
499
+ }}
500
+ }});
501
+ }});
502
+ }}
503
+ }});
504
  </script>
505
 
506
  <style>
507
+ .safari-browser .file-upload {{
508
+ -webkit-appearance: none;
509
+ appearance: none;
510
+ border-radius: 8px;
511
+ padding: 10px;
512
+ background: #f3f4f6;
513
  }}
514
 
515
+ @media (display-mode: standalone) {{
516
  body {{
517
+ padding-top: env(safe-area-inset-top);
518
+ padding-bottom: env(safe-area-inset-bottom);
519
  }}
520
  }}
521
  </style>