THEZYZSTUDIO commited on
Commit
7061eb4
ยท
verified ยท
1 Parent(s): 2446f86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -13
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
- # ูˆู†ุณุชุฎุฏู… ู‚ูู„ุงู‹ ู„ู…ู†ุน ุชุฑุงูƒู… ุฃูƒุซุฑ ู…ู† ุนู…ู„ูŠุฉ 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:
@@ -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
- result = await _safe_capture(0.65, 75)
 
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=1.5))
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=1.5))
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":