THEZYZSTUDIO commited on
Commit
1a6a3ec
ยท
verified ยท
1 Parent(s): 3fc9631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -5
app.py CHANGED
@@ -656,8 +656,47 @@ def _sanitize_pkill_self_match(cmd: str) -> str:
656
  return _PKILL_SELF_MATCH_RE.sub(_fix, cmd)
657
 
658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  def run_raw_command(cmd: str, timeout: int = 60) -> dict:
660
  cmd = _sanitize_pkill_self_match(cmd)
 
661
  env = {**os.environ, "DISPLAY": DISPLAY_OF(),
662
  "PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
663
  try:
@@ -1039,7 +1078,7 @@ async def handle_action(ws: WebSocket, msg: dict):
1039
 
1040
  # โ”€โ”€ keyboard_type โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1041
  elif action == "keyboard_type":
1042
- text = data.get("text", "")
1043
  if text:
1044
  result = await type_text_smart(text)
1045
  await send({"type": "ack", "action": "keyboard_type",
@@ -1102,12 +1141,12 @@ async def handle_action(ws: WebSocket, msg: dict):
1102
  elif action == "open_app":
1103
  app_cmd = data.get("cmd", "")
1104
  if app_cmd:
1105
- fixed_cmd = app_cmd
1106
  # ุฅุตู„ุงุญ firefox-esr
1107
- if "firefox-esr" in app_cmd:
1108
  esr_check = await asyncio.to_thread(subprocess.run, ["which", "firefox-esr"], capture_output=True, text=True)
1109
  if esr_check.returncode != 0:
1110
- fixed_cmd = app_cmd.replace("firefox-esr", BROWSER)
1111
 
1112
  # โ”€โ”€ ุญู…ุงูŠุฉ ุฅุถุงููŠุฉ: ุญุฐู ู…ู„ูุงุช ู‚ูู„ Firefox ุงู„ู…ุชุจู‚ูŠุฉ ู‚ุจู„ ูุชุญ ู†ุงูุฐุฉ ุฌุฏูŠุฏุฉ โ”€โ”€
1113
  # ูŠู…ู†ุน ุธู‡ูˆุฑ "Firefox is already running, but is not responding" ุญุชู‰ ู„ูˆ
@@ -1165,6 +1204,48 @@ async def handle_action(ws: WebSocket, msg: dict):
1165
  # โ”€โ”€ start_stream / stop_stream: ุบูŠุฑ ู…ุณุชุฎุฏู…ุฉ ู…ู† ุงู„ูˆุงุฌู‡ุฉ ุงู„ุญุงู„ูŠุฉุŒ ุฃูุฒูŠู„ุช ู„ู…ู†ุน
1166
  # ุชุดุบูŠู„ ุญู„ู‚ุฉ ุชุตูˆูŠุฑ ู…ุณุชู…ุฑุฉ ููŠ ุงู„ุฎู„ููŠุฉ ุจู„ุง ุฏุงุนู (ูƒุงู†ุช ุชุณุชู‡ู„ูƒ ู…ูˆุงุฑุฏ ุญุชู‰ ุจุนุฏ ุฅุบู„ุงู‚ ุงู„ุงุชุตุงู„) โ”€โ”€
1167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1168
  # โ”€โ”€ screen_info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1169
  elif action == "screen_info":
1170
  w, h = await asyncio.to_thread(_get_screen_size)
@@ -1198,7 +1279,7 @@ async def handle_action(ws: WebSocket, msg: dict):
1198
  else:
1199
  await send({
1200
  "type": "error",
1201
- "msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_browser, paste, simple_command, screen_info"
1202
  })
1203
 
1204
 
 
656
  return _PKILL_SELF_MATCH_RE.sub(_fix, cmd)
657
 
658
 
659
+ _BING_URL_RE = re.compile(r"https?://(?:www\.)?bing\.com[^\s'\"]*")
660
+ _DDG_URL_RE = re.compile(r"https?://(?:www\.)?duckduckgo\.com[^\s'\"]*")
661
+ _GOOGLE_URL_RE = re.compile(r"https?://(?:www\.)?google\.[a-z.]+[^\s'\"]*")
662
+
663
+ def _enforce_safesearch(text: str) -> str:
664
+ """
665
+ ูŠูุฑุถ ู…ุนุงู…ู„ุงุช SafeSearch ุงู„ุตุงุฑู…ุฉ ุชู„ู‚ุงุฆูŠุงู‹ ุนู„ู‰ ุฃูŠ ุฑุงุจุท Bing ุฃูˆ DuckDuckGo ุฃูˆ Google
666
+ ู…ูˆุฌูˆุฏ ููŠ ุงู„ู†ุตุŒ ุจุบุถ ุงู„ู†ุธุฑ ุนู…ู‘ุง ูƒุชุจู‡ ุงู„ุฐูƒุงุก โ€” ุญู…ุงูŠุฉ ุฅู„ุฒุงู…ูŠุฉ ุนู„ู‰ ู…ุณุชูˆู‰ ุงู„ุณูŠุฑูุฑ
667
+ ู„ู…ู†ุน ุธู‡ูˆุฑ ู…ุญุชูˆู‰ ุบูŠุฑ ู„ุงุฆู‚ ููŠ ู†ุชุงุฆุฌ ุงู„ุจุญุซุŒ ู…ุณุชู‚ู„ุฉ ุนู† ุชุนู„ูŠู…ุงุช ุงู„ู€ prompt.
668
+ ุชุบุทูŠ ุฃูŠุถุงู‹ ุญุงู„ุฉ ุงู„ูˆุตูˆู„ ู„ู€ Google ุจุดูƒู„ ุบูŠุฑ ู…ุจุงุดุฑ (ุนุจุฑ ุฑุงุจุท ู…ูƒุชูˆุจ ุตุฑูŠุญ ููŠ ุงู„ุฃู…ุฑ).
669
+ """
670
+ def _fix_bing(m):
671
+ url = m.group(0)
672
+ if "adlt=" in url:
673
+ return re.sub(r"adlt=\w+", "adlt=strict", url)
674
+ sep = "&" if "?" in url else "?"
675
+ return url + f"{sep}adlt=strict"
676
+
677
+ def _fix_ddg(m):
678
+ url = m.group(0)
679
+ if "kp=" in url:
680
+ return re.sub(r"kp=\d", "kp=1", url)
681
+ sep = "&" if "?" in url else "?"
682
+ return url + f"{sep}kp=1"
683
+
684
+ def _fix_google(m):
685
+ url = m.group(0)
686
+ if "safe=" in url:
687
+ return re.sub(r"safe=\w+", "safe=strict", url)
688
+ sep = "&" if "?" in url else "?"
689
+ return url + f"{sep}safe=strict"
690
+
691
+ text = _BING_URL_RE.sub(_fix_bing, text)
692
+ text = _DDG_URL_RE.sub(_fix_ddg, text)
693
+ text = _GOOGLE_URL_RE.sub(_fix_google, text)
694
+ return text
695
+
696
+
697
  def run_raw_command(cmd: str, timeout: int = 60) -> dict:
698
  cmd = _sanitize_pkill_self_match(cmd)
699
+ cmd = _enforce_safesearch(cmd)
700
  env = {**os.environ, "DISPLAY": DISPLAY_OF(),
701
  "PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
702
  try:
 
1078
 
1079
  # โ”€โ”€ keyboard_type โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1080
  elif action == "keyboard_type":
1081
+ text = _enforce_safesearch(data.get("text", ""))
1082
  if text:
1083
  result = await type_text_smart(text)
1084
  await send({"type": "ack", "action": "keyboard_type",
 
1141
  elif action == "open_app":
1142
  app_cmd = data.get("cmd", "")
1143
  if app_cmd:
1144
+ fixed_cmd = _enforce_safesearch(app_cmd)
1145
  # ุฅุตู„ุงุญ firefox-esr
1146
+ if "firefox-esr" in fixed_cmd:
1147
  esr_check = await asyncio.to_thread(subprocess.run, ["which", "firefox-esr"], capture_output=True, text=True)
1148
  if esr_check.returncode != 0:
1149
+ fixed_cmd = fixed_cmd.replace("firefox-esr", BROWSER)
1150
 
1151
  # โ”€โ”€ ุญู…ุงูŠุฉ ุฅุถุงููŠุฉ: ุญุฐู ู…ู„ูุงุช ู‚ูู„ Firefox ุงู„ู…ุชุจู‚ูŠุฉ ู‚ุจู„ ูุชุญ ู†ุงูุฐุฉ ุฌุฏูŠุฏุฉ โ”€โ”€
1152
  # ูŠู…ู†ุน ุธู‡ูˆุฑ "Firefox is already running, but is not responding" ุญุชู‰ ู„ูˆ
 
1204
  # โ”€โ”€ start_stream / stop_stream: ุบูŠุฑ ู…ุณุชุฎุฏู…ุฉ ู…ู† ุงู„ูˆุงุฌู‡ุฉ ุงู„ุญุงู„ูŠุฉุŒ ุฃูุฒูŠู„ุช ู„ู…ู†ุน
1205
  # ุชุดุบูŠู„ ุญู„ู‚ุฉ ุชุตูˆูŠุฑ ู…ุณุชู…ุฑุฉ ููŠ ุงู„ุฎู„ููŠุฉ ุจู„ุง ุฏุงุนู (ูƒุงู†ุช ุชุณุชู‡ู„ูƒ ู…ูˆุงุฑุฏ ุญุชู‰ ุจุนุฏ ุฅุบู„ุงู‚ ุงู„ุงุชุตุงู„) โ”€โ”€
1206
 
1207
+ # โ”€โ”€ open_tab โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1208
+ elif action == "open_tab":
1209
+ url = _enforce_safesearch(data.get("url", "") or "about:blank")
1210
+ await xdo(["key", "--clearmodifiers", "ctrl+t"])
1211
+ await asyncio.sleep(0.4)
1212
+ await xdo(["key", "--clearmodifiers", "ctrl+l"])
1213
+ await asyncio.sleep(0.2)
1214
+ await type_text_smart(url)
1215
+ await asyncio.sleep(0.2)
1216
+ await xdo(["key", "--clearmodifiers", "Return"])
1217
+ await send({"type": "ack", "action": "open_tab", "url": url})
1218
+ await auto_shot_grid("ุจุนุฏ ูุชุญ ุชุจูˆูŠุจ ุฌุฏูŠุฏ", delay=1.5)
1219
+
1220
+ # โ”€โ”€ close_tab โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1221
+ elif action == "close_tab":
1222
+ await xdo(["key", "--clearmodifiers", "ctrl+w"])
1223
+ await send({"type": "ack", "action": "close_tab"})
1224
+ await auto_shot_grid("ุจุนุฏ ุฅุบู„ุงู‚ ุงู„ุชุจูˆูŠุจ", delay=0.5)
1225
+
1226
+ # โ”€โ”€ browser_back โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1227
+ elif action == "browser_back":
1228
+ await xdo(["key", "--clearmodifiers", "alt+Left"])
1229
+ await send({"type": "ack", "action": "browser_back"})
1230
+ await auto_shot_grid("ุจุนุฏ ุงู„ุฑุฌูˆุน", delay=0.8)
1231
+
1232
+ # โ”€โ”€ browser_forward โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1233
+ elif action == "browser_forward":
1234
+ await xdo(["key", "--clearmodifiers", "alt+Right"])
1235
+ await send({"type": "ack", "action": "browser_forward"})
1236
+ await auto_shot_grid("ุจุนุฏ ุงู„ุชู‚ุฏู…", delay=0.8)
1237
+
1238
+ # โ”€โ”€ browser_search: ุงุฎุชุตุงุฑ ู„ูุชุญ ุจุญุซ ู…ุจุงุดุฑุฉ ููŠ ุงู„ุชุจูˆูŠุจ ุงู„ุญุงู„ูŠ โ”€โ”€
1239
+ elif action == "browser_search":
1240
+ url = _enforce_safesearch(data.get("url", "") or data.get("query", ""))
1241
+ await xdo(["key", "--clearmodifiers", "ctrl+l"])
1242
+ await asyncio.sleep(0.2)
1243
+ await type_text_smart(url)
1244
+ await asyncio.sleep(0.2)
1245
+ await xdo(["key", "--clearmodifiers", "Return"])
1246
+ await send({"type": "ack", "action": "browser_search", "url": url})
1247
+ await auto_shot_grid("ุจุนุฏ ุงู„ุจุญุซ", delay=1.5)
1248
+
1249
  # โ”€โ”€ screen_info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1250
  elif action == "screen_info":
1251
  w, h = await asyncio.to_thread(_get_screen_size)
 
1279
  else:
1280
  await send({
1281
  "type": "error",
1282
+ "msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_tab, close_tab, browser_back, browser_forward, browser_search, open_browser, paste, simple_command, screen_info"
1283
  })
1284
 
1285