Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -438,67 +438,64 @@ def show_details_html(choice, previous_output, initial_state):
|
|
| 438 |
return format_hint_html(error_msg), gr.update(visible=True), initial_state
|
| 439 |
|
| 440 |
def get_pwa_html():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
return """
|
| 442 |
<!DOCTYPE html>
|
| 443 |
<meta charset="UTF-8">
|
| 444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 445 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 446 |
|
|
|
|
| 447 |
<script>
|
| 448 |
-
//
|
| 449 |
-
function
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
// 基礎環境
|
| 455 |
-
initBasicFeatures();
|
| 456 |
-
}
|
| 457 |
-
}
|
| 458 |
-
|
| 459 |
-
function initBasicFeatures() {
|
| 460 |
-
// 基本的移動端優化
|
| 461 |
-
document.documentElement.style.webkitTouchCallout = 'none';
|
| 462 |
-
document.documentElement.style.webkitUserSelect = 'none';
|
| 463 |
-
}
|
| 464 |
-
|
| 465 |
-
function initPWA() {
|
| 466 |
-
// 只在支援的環境中嘗試 PWA 功能
|
| 467 |
-
try {
|
| 468 |
-
const manifestData = {
|
| 469 |
name: 'PawMatch AI',
|
| 470 |
short_name: 'PawMatch',
|
| 471 |
display: 'standalone'
|
| 472 |
};
|
| 473 |
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
}
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
|
|
|
| 490 |
</script>
|
| 491 |
|
|
|
|
| 492 |
<style>
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
-
|
| 496 |
-
overflow-x: hidden;
|
| 497 |
}
|
| 498 |
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
-
|
|
|
|
| 502 |
}
|
| 503 |
</style>
|
| 504 |
"""
|
|
|
|
| 438 |
return format_hint_html(error_msg), gr.update(visible=True), initial_state
|
| 439 |
|
| 440 |
def get_pwa_html():
|
| 441 |
+
"""
|
| 442 |
+
創建一個不依賴外部模組的 PWA 設定
|
| 443 |
+
通過直接嵌入所需的代碼來避免模組載入問題
|
| 444 |
+
"""
|
| 445 |
return """
|
| 446 |
<!DOCTYPE html>
|
| 447 |
<meta charset="UTF-8">
|
| 448 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 449 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 450 |
|
| 451 |
+
<!-- 直接在頁面中定義需要的功能,避免外部模組載入 -->
|
| 452 |
<script>
|
| 453 |
+
// 在 DOMContentLoaded 之前初始化,避免與其他腳本衝突
|
| 454 |
+
(function() {
|
| 455 |
+
// 定義我們自己的啟動函數,不依賴外部模組
|
| 456 |
+
function initializeApp() {
|
| 457 |
+
// PWA 相關設定
|
| 458 |
+
const config = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
name: 'PawMatch AI',
|
| 460 |
short_name: 'PawMatch',
|
| 461 |
display: 'standalone'
|
| 462 |
};
|
| 463 |
|
| 464 |
+
try {
|
| 465 |
+
// 使用內聯方式創建 manifest
|
| 466 |
+
const manifestData = new Blob(
|
| 467 |
+
[JSON.stringify(config)],
|
| 468 |
+
{type: 'application/json'}
|
| 469 |
+
);
|
| 470 |
+
|
| 471 |
+
// 在文檔準備好之後再添加 manifest
|
| 472 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 473 |
+
const link = document.createElement('link');
|
| 474 |
+
link.rel = 'manifest';
|
| 475 |
+
link.href = URL.createObjectURL(manifestData);
|
| 476 |
+
document.head.appendChild(link);
|
| 477 |
+
});
|
| 478 |
+
} catch(e) {
|
| 479 |
+
console.log('PWA initialization failed:', e);
|
| 480 |
+
}
|
| 481 |
}
|
| 482 |
+
|
| 483 |
+
// 立即執行初始化
|
| 484 |
+
initializeApp();
|
| 485 |
+
})();
|
| 486 |
</script>
|
| 487 |
|
| 488 |
+
<!-- 確保基本的移動端支援 -->
|
| 489 |
<style>
|
| 490 |
+
:root {
|
| 491 |
+
--safe-area-top: env(safe-area-inset-top);
|
| 492 |
+
--safe-area-bottom: env(safe-area-inset-bottom);
|
|
|
|
| 493 |
}
|
| 494 |
|
| 495 |
+
body {
|
| 496 |
+
margin: 0;
|
| 497 |
+
padding: var(--safe-area-top) 0 var(--safe-area-bottom) 0;
|
| 498 |
+
-webkit-overflow-scrolling: touch;
|
| 499 |
}
|
| 500 |
</style>
|
| 501 |
"""
|