Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -710,21 +710,27 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 710 |
# while True ุงูุฑุฆูุณูุฉ ูู websocket_endpointุ ูุฅุฐุง ุชุฃุฎุฑุช capture_with_grid (ูุฏ ุชุตู
|
| 711 |
# ูุฏูููุฉ ููุตู ูู ุฃุณูุฃ ุณููุงุฑูู ูุดู/ุชุฃุฎุฑ scrot+import+ffmpeg)ุ ุชุจูู ุงูุญููุฉ ูููุง
|
| 712 |
# ู
ุญุฌูุจุฉ ููุง ุชุณุชูุจู ุฃู ุฑุณุงูุฉ ุนู
ูู ุฌุฏูุฏุฉ (ููุฑุฉุ ุทูุจ screenshot ุขุฎุฑุ ุฅูุฎ) ุญุชู ุชูุชูู.
|
| 713 |
-
# ุงูุญู: ูู ุทูุจ screenshot ููุดุบููู ููุฑุงู ุนุจุฑ create_task (ูุง ูุญุฌุจ ุงูุญููุฉ ุฃุจุฏุงู)
|
| 714 |
-
#
|
| 715 |
-
#
|
| 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 |
-
|
| 725 |
-
|
| 726 |
-
ูุณุจุจ ุบูุฑ ู
ุชููุนุ ูุง ูุจูู ุฃู ุทูุจ ููุทุฉ ุดุงุดุฉ ู
ุนูููุงู ููุฃุจุฏ โ ููุดู ุจูุฏูุก ุจุฏู ุฐูู
|
| 727 |
-
ูููุนุงุฏ ุงูู
ุญุงููุฉ ูู ุงูุทูุจ ุงูุชุงูู (ูู ุงูุงุณุชุฏุนุงุกุงุช ุชุชุนุงู
ู ุจุงููุนู ู
ุน data="" ููุดู ุตุงู
ุช).
|
| 728 |
"""
|
| 729 |
async def _do_capture():
|
| 730 |
async with _shot_lock:
|
|
@@ -737,6 +743,34 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 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."""
|
|
@@ -768,8 +802,9 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 768 |
})
|
| 769 |
|
| 770 |
async def shot_explicit(label: str = ""):
|
| 771 |
-
"""screenshot ุตุฑูุญ โ ููุฑุณู ุฏุงุฆู
ุงู ุจุฏูู delta suppression
|
| 772 |
-
|
|
|
|
| 773 |
if not result["data"]:
|
| 774 |
return
|
| 775 |
sess["last_bg_hash"] = _frame_hash(result["data"])
|
|
@@ -985,7 +1020,7 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 985 |
await asyncio.sleep(0.2)
|
| 986 |
await xdo(["key", "--clearmodifiers", "Return"], display)
|
| 987 |
await send({"type": "ack", "action": "open_tab", "url": url})
|
| 988 |
-
asyncio.create_task(shot_bg("after open_tab", delay=
|
| 989 |
|
| 990 |
# โโ close_tab โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 991 |
elif action == "close_tab":
|
|
@@ -1014,7 +1049,7 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
|
|
| 1014 |
await asyncio.sleep(0.15)
|
| 1015 |
await xdo(["key", "--clearmodifiers", "Return"], display)
|
| 1016 |
await send({"type": "ack", "action": "browser_search"})
|
| 1017 |
-
asyncio.create_task(shot_bg("after search", delay=
|
| 1018 |
|
| 1019 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1020 |
elif action == "screen_info":
|
|
|
|
| 710 |
# while True ุงูุฑุฆูุณูุฉ ูู websocket_endpointุ ูุฅุฐุง ุชุฃุฎุฑุช capture_with_grid (ูุฏ ุชุตู
|
| 711 |
# ูุฏูููุฉ ููุตู ูู ุฃุณูุฃ ุณููุงุฑูู ูุดู/ุชุฃุฎุฑ scrot+import+ffmpeg)ุ ุชุจูู ุงูุญููุฉ ูููุง
|
| 712 |
# ู
ุญุฌูุจุฉ ููุง ุชุณุชูุจู ุฃู ุฑุณุงูุฉ ุนู
ูู ุฌุฏูุฏุฉ (ููุฑุฉุ ุทูุจ screenshot ุขุฎุฑุ ุฅูุฎ) ุญุชู ุชูุชูู.
|
| 713 |
+
# ุงูุญู: ูู ุทูุจ screenshot ููุดุบููู ููุฑุงู ุนุจุฑ create_task (ูุง ูุญุฌุจ ุงูุญููุฉ ุฃุจุฏุงู).
|
| 714 |
+
#
|
| 715 |
+
# โโ ุฅุตูุงุญ ุซุงูู (ู
ูู
ุฌุฏุงู): ุทูุจ screenshot ุงูุตุฑูุญ ู
ู ุงูุนู
ูู ูู ุฃููููุฉ ู
ุทููุฉ โโ
|
| 716 |
+
# ุงูู
ุดููุฉ ุงูู
ูุชุดูุฉ ูุงุญูุงู: ูู ุงุณุชูุฎุฏู
ููู ูุงุญุฏ ู
ุดุชุฑู ุจูู shot_bg (ุชููุงุฆูุฉุ ุจุนุฏ
|
| 717 |
+
# ูู ูุนู ูููุฑุฉ/ูุชุญ ุชุจููุจ) ู shot_explicit (ุตุฑูุญุฉุ ูุทูุจูุง ุงูุนู
ูู ู
ุจุงุดุฑุฉ ุจุนุฏ ูู
|
| 718 |
+
# ุฎุทูุฉ ูุชุญุฏูุซ ุงูุตูุฑุฉ ุงูู
ุนุฑูุถุฉ)ุ ูุฅู shot_explicit ูุฏ ุชูุชุธุฑ ุฎูู shot_bg ุทูููุงู
|
| 719 |
+
# ุฅุฐุง ูุงูุช ุงูุฃุฎูุฑุฉ ูุฏ ุจุฏุฃุช ูุนูุงู ูุนููุช ุฏุงุฎู capture_with_grid (ู
ุญุงููุงุช ูุงุดูุฉ
|
| 720 |
+
# ู
ุชุชุงููุฉ). ูุฐุง ูุฌุนู ุงูุนู
ูู ูุฑู "ูู
ุชุตู ููุทุฉ ุดุงุดุฉ" ุจุดูู ู
ุชูุฑุฑ ุญุชู ุจุนุฏ ูุฌุงุญ
|
| 721 |
+
# ุงูุฎุทูุฉ ุงููุนููุฉ (ู
ุซู open_tab)ุ ูุฃู ุทูุจู ุงูุนุงุฌู ูุงู ูุตุทู ุฎูู ุนู
ููุฉ ุชููุงุฆูุฉ ุจุทูุฆุฉ.
|
| 722 |
+
# ุงูุญู: shot_explicit (ุงูุตุฑูุญุฉ ููุท) ุชุญุงูู ุงูุญุตูู ุนูู ุงูููู ููุชุฑุฉ ูุตูุฑุฉ ุฌุฏุงู
|
| 723 |
+
# (1 ุซุงููุฉ)ุ ูุฅู ูู
ุชูุฌุญ (ูุฃู shot_bg ุชุณุชุฎุฏู
ู)ุ ุชูููููุฐ ุงูุชุตููุฑ ู
ุจุงุดุฑุฉ ุจุฏูู ููู
|
| 724 |
+
# ุจุฏู ุงูุงูุชุธุงุฑ โ ูุฃู ุงุณุชุฌุงุจุฉ ุงูุนู
ูู ุงูููุฑูุฉ ุฃูู
ู
ู ุชูุงุฏู ุชุฒุงุญู
CPU ุนุฑุถู ุจุณูุทุ
|
| 725 |
+
# ููุฑุงุกุฉ ุงูุดุงุดุฉ (X11) ุนู
ููุฉ ูุฑุงุกุฉ ููุท ูุง ุชูุณุจุจ ุฃู ุชูู ุจูุงูุงุช ุนูุฏ ุงูุชุฒุงุญู
.
|
| 726 |
if "_shot_lock" not in sess:
|
| 727 |
sess["_shot_lock"] = asyncio.Lock()
|
| 728 |
_shot_lock = sess["_shot_lock"]
|
| 729 |
|
| 730 |
async def _safe_capture(scale, quality, force_mx=None, force_my=None):
|
| 731 |
"""
|
| 732 |
+
ุชูุณุชุฎุฏู
ู
ู shot_bg (ุงูุชููุงุฆูุฉ) โ ุชูุชุธุฑ ุงูููู ุจุณูู ุฒู
ูู 25 ุซุงููุฉ ูุชูุงุฏู
|
| 733 |
+
ุชุฑุงูู
ุนุฏุฉ ุนู
ููุงุช capture ุชููุงุฆูุฉ ููู ุจุนุถูุง.
|
|
|
|
|
|
|
| 734 |
"""
|
| 735 |
async def _do_capture():
|
| 736 |
async with _shot_lock:
|
|
|
|
| 743 |
print(f"[shot:{display}] โ ๏ธ capture timed out after 25s โ skipping this frame")
|
| 744 |
return {"data": "", "width": 1920, "height": 1080, "mouse_x": 0, "mouse_y": 0}
|
| 745 |
|
| 746 |
+
async def _priority_capture(scale, quality, force_mx=None, force_my=None):
|
| 747 |
+
"""
|
| 748 |
+
ุชูุณุชุฎุฏู
ู
ู shot_explicit (ุงูุทูุจ ุงูุตุฑูุญ ู
ู ุงูุนู
ูู) ููุท โ ุฃููููุฉ ูุตูู.
|
| 749 |
+
ุชุญุงูู ุงูุญุตูู ุนูู ุงูููู ูู
ุฏุฉ ูุตูุฑุฉ (1 ุซุงููุฉ) ููุทุ ุฅู ูู
ุชูุฌุญ (ุงูููู
|
| 750 |
+
ู
ุญุฌูุฒ ู
ู shot_bg ุชููุงุฆูุฉ ุจุทูุฆุฉ)ุ ุชูููููุฐ ุงูุชุตููุฑ ููุฑุงู ุจุฏูู ููู ุจุฏู
|
| 751 |
+
ุงูุงูุชุธุงุฑ ุฎูู ุนู
ููุฉ ุฃุฎุฑู โ ุงูุนู
ูู ูุฌุจ ุฃู ูุญุตู ุนูู ุฑุฏ ุณุฑูุน ุฏุงุฆู
ุงู.
|
| 752 |
+
"""
|
| 753 |
+
try:
|
| 754 |
+
await asyncio.wait_for(_shot_lock.acquire(), timeout=1.0)
|
| 755 |
+
try:
|
| 756 |
+
return await asyncio.wait_for(
|
| 757 |
+
asyncio.to_thread(capture_with_grid, display, scale, quality, force_mx, force_my),
|
| 758 |
+
timeout=20
|
| 759 |
+
)
|
| 760 |
+
finally:
|
| 761 |
+
_shot_lock.release()
|
| 762 |
+
except asyncio.TimeoutError:
|
| 763 |
+
# ูู
ูุญุตู ุนูู ุงูููู ุจุณุฑุนุฉ ูุงููุฉุ ุฃู ุงูุชูุช ู
ููุฉ ุงูุชุตููุฑ ููุณู โ
|
| 764 |
+
# ููููุฐ ุงูุชุตููุฑ ู
ุจุงุดุฑุฉ ุจุฏูู ููู ุจุฏู ุชุฑู ุงูุนู
ูู ุจูุง ุฑุฏ ุฅุทูุงูุงู
|
| 765 |
+
try:
|
| 766 |
+
return await asyncio.wait_for(
|
| 767 |
+
asyncio.to_thread(capture_with_grid, display, scale, quality, force_mx, force_my),
|
| 768 |
+
timeout=20
|
| 769 |
+
)
|
| 770 |
+
except asyncio.TimeoutError:
|
| 771 |
+
print(f"[shot:{display}] โ ๏ธ priority capture timed out โ skipping this frame")
|
| 772 |
+
return {"data": "", "width": 1920, "height": 1080, "mouse_x": 0, "mouse_y": 0}
|
| 773 |
+
|
| 774 |
async def shot_bg(label: str = "", delay: float = 0.5,
|
| 775 |
force_mx: int | None = None, force_my: int | None = None):
|
| 776 |
"""auto_shot ูู ุงูุฎูููุฉ โ ู
ุน rate limit + delta suppression."""
|
|
|
|
| 802 |
})
|
| 803 |
|
| 804 |
async def shot_explicit(label: str = ""):
|
| 805 |
+
"""screenshot ุตุฑูุญ โ ููุฑุณู ุฏุงุฆู
ุงู ุจุฏูู delta suppressionุ ููู ุฃููููุฉ ู
ุทููุฉ
|
| 806 |
+
ุนูู ุฃู ุนู
ููุฉ shot_bg ุชููุงุฆูุฉ ุฌุงุฑูุฉ (ูุง ููุชุธุฑ ุฎูููุง ุทูููุงู)."""
|
| 807 |
+
result = await _priority_capture(0.65, 75)
|
| 808 |
if not result["data"]:
|
| 809 |
return
|
| 810 |
sess["last_bg_hash"] = _frame_hash(result["data"])
|
|
|
|
| 1020 |
await asyncio.sleep(0.2)
|
| 1021 |
await xdo(["key", "--clearmodifiers", "Return"], display)
|
| 1022 |
await send({"type": "ack", "action": "open_tab", "url": url})
|
| 1023 |
+
asyncio.create_task(shot_bg("after open_tab", delay=2.5))
|
| 1024 |
|
| 1025 |
# โโ close_tab โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1026 |
elif action == "close_tab":
|
|
|
|
| 1049 |
await asyncio.sleep(0.15)
|
| 1050 |
await xdo(["key", "--clearmodifiers", "Return"], display)
|
| 1051 |
await send({"type": "ack", "action": "browser_search"})
|
| 1052 |
+
asyncio.create_task(shot_bg("after search", delay=2.5))
|
| 1053 |
|
| 1054 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1055 |
elif action == "screen_info":
|