Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -705,6 +705,38 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 705 |
except Exception:
|
| 706 |
pass
|
| 707 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
async def shot_bg(label: str = "", delay: float = 0.5,
|
| 709 |
force_mx: int | None = None, force_my: int | None = None):
|
| 710 |
"""auto_shot ูู ุงูุฎูููุฉ โ ู
ุน rate limit + delta suppression."""
|
|
@@ -713,9 +745,7 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 713 |
if now - sess.get("last_bg_shot_ts", 0) < 0.3:
|
| 714 |
await asyncio.sleep(0.3 - (now - sess["last_bg_shot_ts"]))
|
| 715 |
|
| 716 |
-
result = await
|
| 717 |
-
capture_with_grid, display, 0.65, 72, force_mx, force_my
|
| 718 |
-
)
|
| 719 |
sess["last_bg_shot_ts"] = time.time()
|
| 720 |
if not result["data"]:
|
| 721 |
return
|
|
@@ -739,7 +769,7 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 739 |
|
| 740 |
async def shot_explicit(label: str = ""):
|
| 741 |
"""screenshot ุตุฑูุญ โ ููุฑุณู ุฏุงุฆู
ุงู ุจุฏูู delta suppression."""
|
| 742 |
-
result = await
|
| 743 |
if not result["data"]:
|
| 744 |
return
|
| 745 |
sess["last_bg_hash"] = _frame_hash(result["data"])
|
|
@@ -767,8 +797,12 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 767 |
return
|
| 768 |
|
| 769 |
# โโ screenshot โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
if action == "screenshot":
|
| 771 |
-
|
| 772 |
|
| 773 |
# โโ terminal โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 774 |
elif action == "terminal":
|
|
|
|
| 705 |
except Exception:
|
| 706 |
pass
|
| 707 |
|
| 708 |
+
# โโ ุฅุตูุงุญ ุฌุฐุฑู: ููู ุฎุงุต ุจูู session ูู
ูุน ุชุฑุงูู
/ุชุถุงุฑุจ ุนู
ููุงุช capture ุงูู
ุชุฒุงู
ูุฉ โโ
|
| 709 |
+
# ุงูู
ุดููุฉ ุงูุฃุตููุฉ: action == "screenshot" ูุงู ููููููุฐ ุจู await ู
ุจุงุดุฑ ุถู
ู ุญููุฉ
|
| 710 |
+
# while True ุงูุฑุฆูุณูุฉ ูู websocket_endpointุ ูุฅุฐุง ุชุฃุฎุฑุช capture_with_grid (ูุฏ ุชุตู
|
| 711 |
+
# ูุฏูููุฉ ููุตู ูู ุฃุณูุฃ ุณููุงุฑูู ูุดู/ุชุฃุฎุฑ scrot+import+ffmpeg)ุ ุชุจูู ุงูุญููุฉ ูููุง
|
| 712 |
+
# ู
ุญุฌูุจุฉ ููุง ุชุณุชูุจู ุฃู ุฑุณุงูุฉ ุนู
ูู ุฌุฏูุฏุฉ (ููุฑุฉุ ุทูุจ screenshot ุขุฎุฑุ ุฅูุฎ) ุญุชู ุชูุชูู.
|
| 713 |
+
# ุงูุญู: ูู ุทูุจ screenshot ููุดุบููู ููุฑุงู ุนุจุฑ create_task (ูุง ูุญุฌุจ ุงูุญููุฉ ุฃุจุฏุงู)ุ
|
| 714 |
+
# ููุณุชุฎุฏู
ูููุงู ูู
ูุน ุชุฑุงูู
ุฃูุซุฑ ู
ู ุนู
ููุฉ capture ูุนููุฉ ูุงุญุฏุฉ ุจููุณ ุงููุญุธุฉ ุนูู ููุณ
|
| 715 |
+
# ุงูู display (ูุชูุงุฏู ุชุถุงุฑุจ ู
ููุงุช /tmp ุงูู
ุคูุชุฉ ูุงุณุชููุงู CPU ู
ุถุงุนู ุจูุง ูุงุฆุฏุฉ) โ
|
| 716 |
+
# ูููุตุจุญ ุจุฅู
ูุงู ุงูุฐูุงุก ุงูุงุตุทูุงุนู ุทูุจ ููุทุฉ ุดุงุดุฉ ูู ุฃู ููุช ูู
ู ุฃู ู
ูุงู ุฏูู ุฃู ูุนูู
|
| 717 |
+
# ุฎูู ุทุงุจูุฑ ุฃู ุฅุฌุฑุงุก ุณุงุจู ุจุทูุก.
|
| 718 |
+
if "_shot_lock" not in sess:
|
| 719 |
+
sess["_shot_lock"] = asyncio.Lock()
|
| 720 |
+
_shot_lock = sess["_shot_lock"]
|
| 721 |
+
|
| 722 |
+
async def _safe_capture(scale, quality, force_mx=None, force_my=None):
|
| 723 |
+
"""
|
| 724 |
+
ูุญุตู ุนูู ุงูููู ุซู
ููุชูุท ุงูุดุงุดุฉุ ู
ุน ุณูู ุฒู
ูู ุฅุฌู
ุงูู ุตุงุฑู
(25 ุซุงููุฉ).
|
| 725 |
+
ูุฐุง ูุถู
ู ุฃูู ุญุชู ูู ุทุงู ุงูุชุธุงุฑ ุงูููู (ุทูุจุงุช ู
ุชุฑุงูู
ุฉ) ุฃู ุนููุช capture_with_grid
|
| 726 |
+
ูุณุจุจ ุบูุฑ ู
ุชููุนุ ูุง ูุจูู ุฃู ุทูุจ ููุทุฉ ุดุงุดุฉ ู
ุนูููุงู ููุฃุจุฏ โ ููุดู ุจูุฏูุก ุจุฏู ุฐูู
|
| 727 |
+
ูููุนุงุฏ ุงูู
ุญุงููุฉ ูู ุงูุทูุจ ุงูุชุงูู (ูู ุงูุงุณุชุฏุนุงุกุงุช ุชุชุนุงู
ู ุจุงููุนู ู
ุน data="" ููุดู ุตุงู
ุช).
|
| 728 |
+
"""
|
| 729 |
+
async def _do_capture():
|
| 730 |
+
async with _shot_lock:
|
| 731 |
+
return await asyncio.to_thread(
|
| 732 |
+
capture_with_grid, display, scale, quality, force_mx, force_my
|
| 733 |
+
)
|
| 734 |
+
try:
|
| 735 |
+
return await asyncio.wait_for(_do_capture(), timeout=25)
|
| 736 |
+
except asyncio.TimeoutError:
|
| 737 |
+
print(f"[shot:{display}] โ ๏ธ capture timed out after 25s โ skipping this frame")
|
| 738 |
+
return {"data": "", "width": 1920, "height": 1080, "mouse_x": 0, "mouse_y": 0}
|
| 739 |
+
|
| 740 |
async def shot_bg(label: str = "", delay: float = 0.5,
|
| 741 |
force_mx: int | None = None, force_my: int | None = None):
|
| 742 |
"""auto_shot ูู ุงูุฎูููุฉ โ ู
ุน rate limit + delta suppression."""
|
|
|
|
| 745 |
if now - sess.get("last_bg_shot_ts", 0) < 0.3:
|
| 746 |
await asyncio.sleep(0.3 - (now - sess["last_bg_shot_ts"]))
|
| 747 |
|
| 748 |
+
result = await _safe_capture(0.65, 72, force_mx, force_my)
|
|
|
|
|
|
|
| 749 |
sess["last_bg_shot_ts"] = time.time()
|
| 750 |
if not result["data"]:
|
| 751 |
return
|
|
|
|
| 769 |
|
| 770 |
async def shot_explicit(label: str = ""):
|
| 771 |
"""screenshot ุตุฑูุญ โ ููุฑุณู ุฏุงุฆู
ุงู ุจุฏูู delta suppression."""
|
| 772 |
+
result = await _safe_capture(0.65, 75)
|
| 773 |
if not result["data"]:
|
| 774 |
return
|
| 775 |
sess["last_bg_hash"] = _frame_hash(result["data"])
|
|
|
|
| 797 |
return
|
| 798 |
|
| 799 |
# โโ screenshot โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 800 |
+
# ุฅุตูุงุญ: create_task ุจุฏู await ู
ุจุงุดุฑ โ ูุง ูุญุฌุจ ุญููุฉ ุงุณุชูุจุงู ุงูุฑุณุงุฆู ุฃุจุฏุงูุ
|
| 801 |
+
# ุญุชู ูู ุชุฃุฎุฑุช capture_with_grid ูุฃู ุณุจุจ (CPU ุถุนููุ X11 ุจุทูุกุ ุฅูุฎ).
|
| 802 |
+
# ูุฐุง ูุถู
ู ุฃู ุฃู ุฅุฌุฑุงุก ูุงุญู (ููุฑุฉุ ุทุจุงุนุฉุ ุทูุจ screenshot ุขุฎุฑ) ูุตู ูููุนุงููุฌ
|
| 803 |
+
# ููุฑุงู ุฏูู ุงูุชุธุงุฑ ุงูุชู
ุงู ูุฐู ุงูููุทุฉ ุฃููุงู.
|
| 804 |
if action == "screenshot":
|
| 805 |
+
asyncio.create_task(shot_explicit("explicit screenshot"))
|
| 806 |
|
| 807 |
# โโ terminal โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 808 |
elif action == "terminal":
|