THEZYZSTUDIO commited on
Commit
93db5df
ยท
verified ยท
1 Parent(s): 7061eb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -22
app.py CHANGED
@@ -772,8 +772,18 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
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."""
 
 
 
 
 
 
 
 
 
 
777
  await asyncio.sleep(delay)
778
  now = time.time()
779
  if now - sess.get("last_bg_shot_ts", 0) < 0.3:
@@ -781,25 +791,40 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
781
 
782
  result = await _safe_capture(0.65, 72, force_mx, force_my)
783
  sess["last_bg_shot_ts"] = time.time()
784
- if not result["data"]:
785
- return
786
-
787
- fh = _frame_hash(result["data"])
788
- if fh == sess.get("last_bg_hash", ""):
789
- return
790
- sess["last_bg_hash"] = fh
791
-
792
- await send({
793
- "type": "screenshot",
794
- "data": result["data"],
795
- "ts": int(time.time() * 1000),
796
- "auto": True, "label": label,
797
- "screen_width": result["width"],
798
- "screen_height": result["height"],
799
- "mouse_x": result["mouse_x"],
800
- "mouse_y": result["mouse_y"],
801
- "has_grid": True,
802
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
803
 
804
  async def shot_explicit(label: str = ""):
805
  """screenshot ุตุฑูŠุญ โ€” ูŠูุฑุณู„ ุฏุงุฆู…ุงู‹ ุจุฏูˆู† delta suppressionุŒ ูˆู„ู‡ ุฃูˆู„ูˆูŠุฉ ู…ุทู„ู‚ุฉ
@@ -875,7 +900,7 @@ async def handle_action(ws: WebSocket, msg: dict, sess: dict):
875
  await xdo(["click", btn], display)
876
  btn_name = {"1": "left", "2": "middle", "3": "right"}.get(btn, "left")
877
  await send({"type": "ack", "action": "mouse_click", "x": x, "y": y, "button": btn_name})
878
- asyncio.create_task(shot_bg(f"click {btn_name} ({x},{y})", delay=0.5, force_mx=x, force_my=y))
879
 
880
  # โ”€โ”€ mouse_drag โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
881
  elif action == "mouse_drag":
 
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
+ extra_shot_delay: float | None = None):
777
+ """
778
+ auto_shot ููŠ ุงู„ุฎู„ููŠุฉ โ€” ู…ุน rate limit + delta suppression.
779
+ ุฅุฐุง ุชู… ุชู…ุฑูŠุฑ extra_shot_delayุŒ ุชูุฑุณู„ ู„ู‚ุทุฉ ุซุงู†ูŠุฉ ุฅุถุงููŠุฉ ุจุนุฏ ุฐู„ูƒ ุงู„ุชุฃุฎูŠุฑ
780
+ ุงู„ุฅุถุงููŠ (ู…ุญุณูˆุจุงู‹ ู…ู† ูˆู‚ุช ุงู†ุชู‡ุงุก ุงู„ู„ู‚ุทุฉ ุงู„ุฃูˆู„ู‰) โ€” ู‡ุฐุง ูŠุบุทูŠ ุญุงู„ุฉ ุงู„ู†ู‚ุฑ ุนู„ู‰
781
+ ุฑุงุจุท ูŠู†ู‚ู„ ู„ุตูุญุฉ ุฌุฏูŠุฏุฉ ู‚ุฏ ู„ุง ุชูƒุชู…ู„ ุชุญู…ูŠู„ู‡ุง ุฎู„ุงู„ ุงู„ุชุฃุฎูŠุฑ ุงู„ุฃูˆู„ูŠ ุงู„ู‚ุตูŠุฑ
782
+ (ู…ุซู„ุงู‹ ุตูุญุฉ ุจุทูŠุฆุฉ ุนู„ู‰ ุณูŠุฑูุฑ ู…ุญุฏูˆุฏ ุงู„ู…ูˆุงุฑุฏ)ุŒ ุฏูˆู† ุงู„ุญุงุฌุฉ ู„ู…ุนุฑูุฉ ู…ุณุจู‚ุฉ ุจู†ูˆุน
783
+ ุงู„ุนู†ุตุฑ ุงู„ู…ู†ู‚ูˆุฑ ุนู„ูŠู‡. ุชุชุฌุงู‡ู„ delta suppression ู„ู‡ุฐู‡ ุงู„ู„ู‚ุทุฉ ุงู„ุซุงู†ูŠุฉ ุชุญุฏูŠุฏุงู‹
784
+ ู„ุฃู† ุงู„ู…ุญุชูˆู‰ ู…ุชูˆู‚ุน ุฃู† ูŠูƒูˆู† ู…ุฎุชู„ูุงู‹ (ุตูุญุฉ ุชุญู…ู‘ู„ุช ุฃูƒุซุฑ) ุญุชู‰ ู„ูˆ ุชุดุงุจู‡ ุงู„ู€ hash
785
+ ุฌุฒุฆูŠุงู‹ ู…ุน ุฎู„ููŠุฉ ู…ุดุงุจู‡ุฉ.
786
+ """
787
  await asyncio.sleep(delay)
788
  now = time.time()
789
  if now - sess.get("last_bg_shot_ts", 0) < 0.3:
 
791
 
792
  result = await _safe_capture(0.65, 72, force_mx, force_my)
793
  sess["last_bg_shot_ts"] = time.time()
794
+ if result["data"]:
795
+ fh = _frame_hash(result["data"])
796
+ if fh != sess.get("last_bg_hash", ""):
797
+ sess["last_bg_hash"] = fh
798
+ await send({
799
+ "type": "screenshot",
800
+ "data": result["data"],
801
+ "ts": int(time.time() * 1000),
802
+ "auto": True, "label": label,
803
+ "screen_width": result["width"],
804
+ "screen_height": result["height"],
805
+ "mouse_x": result["mouse_x"],
806
+ "mouse_y": result["mouse_y"],
807
+ "has_grid": True,
808
+ })
809
+
810
+ if extra_shot_delay:
811
+ await asyncio.sleep(extra_shot_delay)
812
+ result2 = await _safe_capture(0.65, 72, force_mx, force_my)
813
+ sess["last_bg_shot_ts"] = time.time()
814
+ if result2["data"]:
815
+ fh2 = _frame_hash(result2["data"])
816
+ sess["last_bg_hash"] = fh2
817
+ await send({
818
+ "type": "screenshot",
819
+ "data": result2["data"],
820
+ "ts": int(time.time() * 1000),
821
+ "auto": True, "label": f"{label} (delayed)",
822
+ "screen_width": result2["width"],
823
+ "screen_height": result2["height"],
824
+ "mouse_x": result2["mouse_x"],
825
+ "mouse_y": result2["mouse_y"],
826
+ "has_grid": True,
827
+ })
828
 
829
  async def shot_explicit(label: str = ""):
830
  """screenshot ุตุฑูŠุญ โ€” ูŠูุฑุณู„ ุฏุงุฆู…ุงู‹ ุจุฏูˆู† delta suppressionุŒ ูˆู„ู‡ ุฃูˆู„ูˆูŠุฉ ู…ุทู„ู‚ุฉ
 
900
  await xdo(["click", btn], display)
901
  btn_name = {"1": "left", "2": "middle", "3": "right"}.get(btn, "left")
902
  await send({"type": "ack", "action": "mouse_click", "x": x, "y": y, "button": btn_name})
903
+ asyncio.create_task(shot_bg(f"click {btn_name} ({x},{y})", delay=0.5, force_mx=x, force_my=y, extra_shot_delay=3.0))
904
 
905
  # โ”€โ”€ mouse_drag โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
906
  elif action == "mouse_drag":