@octavus/agent 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,13 +13,13 @@ Dependencies (apt):
13
13
 
14
14
  Usage mirrors the macOS driver exactly:
15
15
  linux-driver.py observe --screenshot /tmp/shot.png [--pid PID]
16
- linux-driver.py click <x> <y>
16
+ linux-driver.py click <x> <y> [--hold-seconds N]
17
17
  linux-driver.py double-click <x> <y>
18
18
  linux-driver.py right-click <x> <y>
19
19
  linux-driver.py type <text>
20
20
  linux-driver.py key <key-spec>
21
21
  linux-driver.py scroll <direction> [steps] [--at x y]
22
- linux-driver.py drag <from_x> <from_y> <to_x> <to_y> [--steps N] [--path x1,y1 ...]
22
+ linux-driver.py drag <from_x> <from_y> <to_x> <to_y> [--steps N] [--path x1,y1 ...] [--hold-seconds N]
23
23
  linux-driver.py screenshot <path>
24
24
  linux-driver.py screenshot-grid <path> --region x y w h --grid <2|3>
25
25
  linux-driver.py activate <app-name>
@@ -29,6 +29,8 @@ import glob
29
29
  import json
30
30
  import os
31
31
  import re
32
+ import shlex
33
+ import signal
32
34
  import subprocess
33
35
  import sys
34
36
  import time
@@ -38,8 +40,8 @@ import shutil
38
40
  # Output helpers (match Swift driver JSON contract)
39
41
  # ---------------------------------------------------------------------------
40
42
 
41
- def print_success(path=None):
42
- resp = {"success": True}
43
+ def print_success(path=None, **fields):
44
+ resp = {"success": True, **fields}
43
45
  if path is not None:
44
46
  resp["path"] = path
45
47
  print(json.dumps(resp))
@@ -917,6 +919,10 @@ def annotate_screenshot(screenshot_path, elements):
917
919
  # slightly-less-synchronous move instead of a hard failure.
918
920
  _MOUSEMOVE_SYNC_TIMEOUT = 3
919
921
 
922
+ # The longest a press-and-hold may keep the button down. A command's timeout
923
+ # grows by the requested hold, so this bound is what actually limits it.
924
+ _MAX_HOLD_SECONDS = 20
925
+
920
926
  # Every keysym a modifier can be held under, left and right variants.
921
927
  _MODIFIER_KEYSYMS = [
922
928
  "Control_L", "Control_R", "Alt_L", "Alt_R", "Shift_L", "Shift_R", "Super_L", "Super_R",
@@ -946,30 +952,76 @@ def release_modifiers(keysyms=_MODIFIER_KEYSYMS):
946
952
  except (FileNotFoundError, subprocess.TimeoutExpired):
947
953
  pass
948
954
 
949
- def mouse_move(x, y):
950
- ix, iy = str(int(x)), str(int(y))
955
+ def _move_pointer(ix, iy):
956
+ """Move the pointer to integer (ix, iy) with a bounded ``--sync`` wait.
957
+
958
+ Returns True when the X server confirmed the arrival. When the sync stalls
959
+ (or errors) the move is re-issued without ``--sync``, which returns
960
+ immediately but carries no arrival confirmation, and False is returned so
961
+ the caller can give the async motion a longer settle.
962
+ """
951
963
  try:
952
964
  subprocess.run(
953
- ["xdotool", "mousemove", "--sync", ix, iy],
965
+ ["xdotool", "mousemove", "--sync", str(ix), str(iy)],
954
966
  capture_output=True,
955
967
  text=True,
956
968
  timeout=_MOUSEMOVE_SYNC_TIMEOUT,
957
969
  check=True,
958
970
  )
959
- time.sleep(0.025)
960
- return
971
+ return True
961
972
  except FileNotFoundError:
962
973
  exit_with_error("Required command not found: xdotool")
963
974
  except (subprocess.TimeoutExpired, subprocess.CalledProcessError):
964
975
  pass
965
- # Sync confirmation stalled - re-issue without --sync (returns immediately)
966
- # and give the async motion a slightly longer settle before the caller
967
- # clicks, since a non-sync move carries no server arrival confirmation.
968
- _run(["xdotool", "mousemove", ix, iy])
969
- time.sleep(0.1)
976
+ _run(["xdotool", "mousemove", str(ix), str(iy)])
977
+ return False
970
978
 
971
- def mouse_click(x, y):
979
+ def _pointer_location():
980
+ """The pointer's current integer (x, y), or None when it cannot be read."""
981
+ try:
982
+ out = subprocess.run(
983
+ ["xdotool", "getmouselocation", "--shell"],
984
+ capture_output=True,
985
+ text=True,
986
+ timeout=_MOUSEMOVE_SYNC_TIMEOUT,
987
+ check=True,
988
+ ).stdout
989
+ except (FileNotFoundError, subprocess.TimeoutExpired, subprocess.CalledProcessError):
990
+ return None
991
+ values = dict(line.split("=", 1) for line in out.split() if "=" in line)
992
+ try:
993
+ return int(values["X"]), int(values["Y"])
994
+ except (KeyError, ValueError):
995
+ return None
996
+
997
+ def mouse_move(x, y):
998
+ target = (int(x), int(y))
999
+ # `mousemove --sync` waits for the pointer to leave its origin, so a move to
1000
+ # the pixel it is already on never confirms and would burn the whole sync
1001
+ # timeout (clicking the same element twice, a drag that starts where the last
1002
+ # click landed, a repeated scroll at one spot). Nothing to move: return.
1003
+ if _pointer_location() == target:
1004
+ return
1005
+ confirmed = _move_pointer(*target)
1006
+ time.sleep(0.025 if confirmed else 0.1)
1007
+
1008
+ def _hold_button(button, hold_seconds):
1009
+ """Press ``button``, keep it down for ``hold_seconds``, then release it.
1010
+
1011
+ The release runs even when the hold is interrupted, so a press-and-hold
1012
+ can never leave the button logically down.
1013
+ """
1014
+ _run(["xdotool", "mousedown", button])
1015
+ try:
1016
+ time.sleep(hold_seconds)
1017
+ finally:
1018
+ _run(["xdotool", "mouseup", button], check=False)
1019
+
1020
+ def mouse_click(x, y, hold_seconds=0.0):
972
1021
  mouse_move(x, y)
1022
+ if hold_seconds > 0:
1023
+ _hold_button("1", hold_seconds)
1024
+ return
973
1025
  _run(["xdotool", "click", "1"])
974
1026
 
975
1027
  def mouse_double_click(x, y):
@@ -1047,12 +1099,20 @@ def _interpolate_points(from_x, from_y, to_x, to_y, steps):
1047
1099
  return points
1048
1100
 
1049
1101
 
1050
- def mouse_drag(from_x, from_y, to_x, to_y, steps=10, waypoints=None):
1102
+ def mouse_drag(from_x, from_y, to_x, to_y, steps=10, waypoints=None, hold_seconds=0.0):
1051
1103
  """Perform a smooth drag from one position to another.
1052
1104
 
1053
- Uses xdotool mousedown/mousemove/mouseup with --sync to ensure
1054
- Chrome recognizes the drag gesture. The 16ms sleep between moves
1055
- matches 60fps frame timing.
1105
+ Presses the button at the start - keeping it down for ``hold_seconds``
1106
+ first when given, the press-and-hold-then-slide gesture - then moves
1107
+ through the interpolated points with bounded ``--sync`` waits so Chrome
1108
+ recognizes the drag, and releases at the end. The 16ms sleep between
1109
+ moves matches 60fps frame timing.
1110
+
1111
+ A point that lands on the pixel the pointer is already on is not sent to
1112
+ xdotool: its ``mousemove --sync`` waits for the pointer to leave its
1113
+ origin, so a move to the current position blocks until the command
1114
+ timeout (a zero-length drag, a freehand loop whose points round to one
1115
+ pixel). The frame sleep still runs so the gesture keeps its timing.
1056
1116
 
1057
1117
  When waypoints are provided the last waypoint is the destination, so
1058
1118
  (to_x, to_y) is not appended to the segment list. The button is
@@ -1060,8 +1120,11 @@ def mouse_drag(from_x, from_y, to_x, to_y, steps=10, waypoints=None):
1060
1120
  cursor stuck in the down state.
1061
1121
  """
1062
1122
  mouse_move(from_x, from_y)
1123
+ last = (int(from_x), int(from_y))
1063
1124
  _run(["xdotool", "mousedown", "1"])
1064
1125
  try:
1126
+ if hold_seconds > 0:
1127
+ time.sleep(hold_seconds)
1065
1128
  if waypoints:
1066
1129
  segments = [(from_x, from_y)] + list(waypoints)
1067
1130
  else:
@@ -1070,7 +1133,10 @@ def mouse_drag(from_x, from_y, to_x, to_y, steps=10, waypoints=None):
1070
1133
  sx, sy = segments[seg_idx]
1071
1134
  ex, ey = segments[seg_idx + 1]
1072
1135
  for px, py in _interpolate_points(sx, sy, ex, ey, steps):
1073
- _run(["xdotool", "mousemove", "--sync", str(int(px)), str(int(py))])
1136
+ target = (int(px), int(py))
1137
+ if target != last:
1138
+ _move_pointer(*target)
1139
+ last = target
1074
1140
  time.sleep(0.016)
1075
1141
  finally:
1076
1142
  _run(["xdotool", "mouseup", "1"], check=False)
@@ -1104,17 +1170,51 @@ _DESKTOP_DIRS = [
1104
1170
  ]
1105
1171
 
1106
1172
 
1173
+ # How long a freshly launched app gets to show a window before `activate` reports
1174
+ # it as launched but not visible yet. LibreOffice and Evince routinely need well
1175
+ # over the few seconds a snappy app takes on these computers. A driver command
1176
+ # has 30 s in total, so this leaves room for the lookups before the launch and
1177
+ # the settle after it.
1178
+ _LAUNCH_WINDOW_TIMEOUT = 20.0
1179
+
1180
+ # The %f/%U/... placeholders in a .desktop Exec= line (files/URLs to open, icon,
1181
+ # caption), none of which apply to a bare launch.
1182
+ _DESKTOP_FIELD_CODES = re.compile(r"\s+%[fFuUdDnNickvm]")
1183
+
1184
+
1185
+ def _desktop_entry_lines(content):
1186
+ """Yield the lines of a .desktop file's ``[Desktop Entry]`` group only.
1187
+
1188
+ ``[Desktop Action ...]`` groups carry their own Name= and Exec= (the
1189
+ LibreOffice Start Center's actions are named "Writer", "Calc", ...), so
1190
+ reading them would match a component's short name to the launcher's entry
1191
+ and open the Start Center for "Calc".
1192
+ """
1193
+ in_entry = False
1194
+ for line in content.splitlines():
1195
+ if line.startswith("["):
1196
+ in_entry = line.strip() == "[Desktop Entry]"
1197
+ elif in_entry:
1198
+ yield line
1199
+
1200
+
1107
1201
  def _resolve_from_desktop_files(name):
1108
1202
  """Search .desktop files for an app matching *name*.
1109
1203
 
1110
- Checks the Name= and GenericName= fields (case-insensitive), plus the
1111
- desktop file basename (e.g. "chromium" matches "chromium-browser.desktop").
1112
- Returns (binaries, desktop_ids) - binary commands from Exec= lines and
1113
- matching .desktop filenames for gtk-launch.
1204
+ Matches the Name= and GenericName= fields of the main group
1205
+ (case-insensitive) and the desktop file basename (e.g. "chromium" matches
1206
+ "chromium-browser.desktop"). Exact Name/GenericName matches order before
1207
+ basename matches: "libreoffice" is a substring of every libreoffice-*.desktop
1208
+ basename but names the Start Center.
1209
+
1210
+ Returns a list of (argv, desktop_id) launch candidates. argv is the Exec=
1211
+ command with its arguments kept and the field codes removed, so "LibreOffice
1212
+ Calc" launches `libreoffice --calc` - not the bare `libreoffice`, which opens
1213
+ the Start Center instead of the component the agent asked for.
1114
1214
  """
1115
1215
  name_lower = name.lower()
1116
- binaries = []
1117
- desktop_ids = []
1216
+ exact = []
1217
+ partial = []
1118
1218
 
1119
1219
  for desktop_dir in _DESKTOP_DIRS:
1120
1220
  for filepath in glob.glob(os.path.join(desktop_dir, "*.desktop")):
@@ -1124,32 +1224,48 @@ def _resolve_from_desktop_files(name):
1124
1224
  except Exception:
1125
1225
  continue
1126
1226
 
1127
- basename = os.path.splitext(os.path.basename(filepath))[0].lower()
1128
- matched = name_lower in basename
1227
+ names = set()
1228
+ exec_cmd = None
1229
+ for line in _desktop_entry_lines(content):
1230
+ if line.startswith("Name=") or line.startswith("GenericName="):
1231
+ names.add(line.split("=", 1)[1].strip().lower())
1232
+ elif line.startswith("Exec=") and exec_cmd is None:
1233
+ exec_cmd = _DESKTOP_FIELD_CODES.sub("", line.split("=", 1)[1].strip())
1234
+
1235
+ desktop_id = os.path.basename(filepath)
1236
+ basename = os.path.splitext(desktop_id)[0].lower()
1237
+ if name_lower in names:
1238
+ bucket = exact
1239
+ elif name_lower in basename:
1240
+ bucket = partial
1241
+ else:
1242
+ continue
1129
1243
 
1130
- if not matched:
1131
- for line in content.splitlines():
1132
- if line.startswith("Name=") or line.startswith("GenericName="):
1133
- value = line.split("=", 1)[1].strip().lower()
1134
- if value == name_lower:
1135
- matched = True
1136
- break
1244
+ try:
1245
+ argv = shlex.split(exec_cmd) if exec_cmd else []
1246
+ except ValueError:
1247
+ argv = []
1248
+ bucket.append((argv, desktop_id))
1137
1249
 
1138
- if not matched:
1139
- continue
1250
+ return exact + partial
1140
1251
 
1141
- desktop_ids.append(os.path.basename(filepath))
1142
1252
 
1143
- for line in content.splitlines():
1144
- if line.startswith("Exec="):
1145
- exec_cmd = line.split("=", 1)[1].strip()
1146
- exec_cmd = re.sub(r"\s+%[fFuUdDnNickvm]", "", exec_cmd)
1147
- binary = exec_cmd.split()[0]
1148
- if binary not in binaries:
1149
- binaries.append(binary)
1150
- break
1253
+ def _window_classes_for_launch(argv, desktop_id):
1254
+ """WM_CLASS regexes that identify the window of a launch we just made.
1151
1255
 
1152
- return binaries, desktop_ids
1256
+ A .desktop id is the most specific signal (`libreoffice-calc` names the Calc
1257
+ window, never the Start Center that a bare `libreoffice` class would also
1258
+ match); a reverse-DNS id (`org.gnome.Evince`) also contributes its last
1259
+ segment, since GTK3 apps set WM_CLASS from the program name. Without a
1260
+ desktop entry, the executable's basename is all there is.
1261
+ """
1262
+ if desktop_id:
1263
+ base = os.path.splitext(desktop_id)[0]
1264
+ classes = [base]
1265
+ if "." in base:
1266
+ classes.append(base.rsplit(".", 1)[1])
1267
+ return classes
1268
+ return [os.path.basename(argv[0])]
1153
1269
 
1154
1270
 
1155
1271
  # WM_CLASS regex fragments for apps whose window title does not match the app name
@@ -1167,6 +1283,14 @@ _WINDOW_CLASS_ALIASES = {
1167
1283
 
1168
1284
 
1169
1285
  def activate_app(name):
1286
+ """Focus the app's window, launching the app first when it has none.
1287
+
1288
+ Returns True when a window of the app is focused, False when the app was
1289
+ launched but has not shown a window within the launch timeout - it is
1290
+ still starting, so the caller should wait rather than launch it again.
1291
+ Raises RuntimeError when nothing launchable matches the name, or when the
1292
+ launched process exits with a failure before showing a window.
1293
+ """
1170
1294
  def find_windows(flag, query):
1171
1295
  try:
1172
1296
  r = subprocess.run(
@@ -1177,13 +1301,16 @@ def activate_app(name):
1177
1301
  except Exception:
1178
1302
  return []
1179
1303
 
1180
- def activate_existing_window():
1304
+ def activate_existing_window(launch_classes=()):
1181
1305
  # Match an already-open window by title (--name) and by window class
1182
1306
  # (--class). A Chrome `--app=<url>` window carries the page title, not the
1183
1307
  # app name, so a title-only search misses it; the class aliases below focus
1184
1308
  # the running browser window instead of launching a second, duplicate one.
1309
+ # After a launch, the classes derived from what was launched find windows
1310
+ # whose title never carries the app name (Evince shows the document's).
1185
1311
  attempts = [("--name", name), ("--name", name.lower())]
1186
1312
  attempts += [("--class", cls) for cls in _WINDOW_CLASS_ALIASES.get(name.lower(), [])]
1313
+ attempts += [("--class", cls) for cls in launch_classes]
1187
1314
  for flag, query in attempts:
1188
1315
  wids = find_windows(flag, query)
1189
1316
  if wids:
@@ -1197,68 +1324,64 @@ def activate_app(name):
1197
1324
  return True
1198
1325
  return False
1199
1326
 
1200
- def wait_for_window(timeout_s=4.0):
1201
- deadline = time.time() + timeout_s
1327
+ def wait_for_window(proc, launch_classes):
1328
+ deadline = time.time() + _LAUNCH_WINDOW_TIMEOUT
1202
1329
  while time.time() < deadline:
1203
- if activate_existing_window():
1330
+ if activate_existing_window(launch_classes):
1204
1331
  return True
1332
+ # A launcher that hands off to a running instance exits 0 with no
1333
+ # window of its own, so only a failure exit ends the wait early.
1334
+ code = proc.poll()
1335
+ if code is not None and code != 0:
1336
+ status = f"signal {-code}" if code < 0 else f"exit status {code}"
1337
+ raise RuntimeError(
1338
+ f"'{name}' crashed on launch ({status}) before showing a window."
1339
+ )
1205
1340
  time.sleep(0.2)
1206
1341
  return False
1207
1342
 
1208
1343
  if activate_existing_window():
1209
- return
1210
-
1211
- desktop_binaries, desktop_ids = _resolve_from_desktop_files(name)
1212
-
1213
- candidates = list(desktop_binaries)
1214
- direct = name.lower()
1215
- if direct not in candidates:
1216
- candidates.append(direct)
1217
- if name != direct and name not in candidates:
1218
- candidates.append(name)
1219
-
1220
- launch_attempted = False
1221
- for command in candidates:
1222
- executable = shutil.which(command)
1223
- if executable is None:
1344
+ return True
1345
+
1346
+ candidates = _resolve_from_desktop_files(name)
1347
+ known = {argv[0] for argv, _ in candidates if argv}
1348
+ for direct in (name.lower(), name):
1349
+ if direct not in known:
1350
+ candidates.append(([direct], None))
1351
+ known.add(direct)
1352
+
1353
+ # Launch once: the first candidate whose executable exists. Each candidate
1354
+ # names the same app, so launching more than one would only stack windows
1355
+ # and make the agent wait for every one in turn.
1356
+ launch = None
1357
+ for argv, desktop_id in candidates:
1358
+ if not argv:
1224
1359
  continue
1225
-
1226
- launch_attempted = True
1227
- try:
1228
- subprocess.Popen(
1229
- [executable],
1230
- stdout=subprocess.DEVNULL,
1231
- stderr=subprocess.DEVNULL,
1232
- )
1233
- if wait_for_window():
1234
- return
1235
- except Exception:
1236
- pass
1237
-
1238
- if not launch_attempted and desktop_ids:
1360
+ executable = shutil.which(argv[0])
1361
+ if executable is not None:
1362
+ launch = ([executable, *argv[1:]], desktop_id)
1363
+ break
1364
+
1365
+ # A desktop entry whose Exec= cannot be resolved directly (D-Bus activated
1366
+ # apps, launcher wrappers off PATH) still launches through gtk-launch.
1367
+ if launch is None:
1239
1368
  gtk_launch = shutil.which("gtk-launch")
1240
- if gtk_launch:
1241
- for desktop_id in desktop_ids:
1242
- try:
1243
- subprocess.Popen(
1244
- [gtk_launch, desktop_id],
1245
- stdout=subprocess.DEVNULL,
1246
- stderr=subprocess.DEVNULL,
1247
- )
1248
- if wait_for_window():
1249
- return
1250
- except Exception:
1251
- pass
1369
+ desktop_ids = [desktop_id for _, desktop_id in candidates if desktop_id]
1370
+ if gtk_launch and desktop_ids:
1371
+ launch = ([gtk_launch, desktop_ids[0]], desktop_ids[0])
1372
+
1373
+ if launch is None:
1374
+ raise RuntimeError(
1375
+ f"Could not find an application named '{name}': no open window, "
1376
+ f".desktop entry, or executable matches it."
1377
+ )
1252
1378
 
1379
+ argv, desktop_id = launch
1253
1380
  try:
1254
- active_pid = _get_active_window_pid()
1255
- except Exception:
1256
- active_pid = None
1257
-
1258
- raise RuntimeError(
1259
- f"Could not open or focus application '{name}'. "
1260
- f"Active window pid remains {active_pid if active_pid is not None else 'unknown'}."
1261
- )
1381
+ proc = subprocess.Popen(argv, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
1382
+ except OSError as e:
1383
+ raise RuntimeError(f"Could not launch '{name}' ({argv[0]}): {e}") from e
1384
+ return wait_for_window(proc, _window_classes_for_launch(argv, desktop_id))
1262
1385
 
1263
1386
 
1264
1387
  # ---------------------------------------------------------------------------
@@ -1273,6 +1396,32 @@ def activate_app(name):
1273
1396
  _INPUT_COMMANDS = {"click", "double-click", "right-click", "type", "key", "scroll", "drag"}
1274
1397
 
1275
1398
 
1399
+ def _parse_hold_seconds(args):
1400
+ """Read an optional ``--hold-seconds N`` out of a command's trailing args."""
1401
+ for i, arg in enumerate(args):
1402
+ if arg != "--hold-seconds":
1403
+ continue
1404
+ try:
1405
+ hold = float(args[i + 1])
1406
+ except (IndexError, ValueError):
1407
+ exit_with_error("--hold-seconds requires a number")
1408
+ if hold < 0 or hold > _MAX_HOLD_SECONDS:
1409
+ exit_with_error(f"--hold-seconds must be between 0 and {_MAX_HOLD_SECONDS}")
1410
+ return hold
1411
+ return 0.0
1412
+
1413
+
1414
+ def _exit_on_sigterm(signum, frame):
1415
+ """Unwind on SIGTERM instead of dying in place.
1416
+
1417
+ A driver that outlives its command timeout is ended with SIGTERM. Python's
1418
+ default disposition terminates without unwinding, which would skip the
1419
+ ``finally`` blocks that release a mouse button held by a drag or a
1420
+ press-and-hold; raising SystemExit runs them first.
1421
+ """
1422
+ sys.exit(1)
1423
+
1424
+
1276
1425
  def main():
1277
1426
  args = sys.argv[1:]
1278
1427
  if not args:
@@ -1280,6 +1429,7 @@ def main():
1280
1429
 
1281
1430
  command = args[0]
1282
1431
  if command in _INPUT_COMMANDS:
1432
+ signal.signal(signal.SIGTERM, _exit_on_sigterm)
1283
1433
  release_modifiers()
1284
1434
 
1285
1435
  if command == "observe":
@@ -1308,8 +1458,8 @@ def main():
1308
1458
 
1309
1459
  elif command == "click":
1310
1460
  if len(args) < 3:
1311
- exit_with_error("Usage: linux-driver.py click <x> <y>")
1312
- mouse_click(float(args[1]), float(args[2]))
1461
+ exit_with_error("Usage: linux-driver.py click <x> <y> [--hold-seconds N]")
1462
+ mouse_click(float(args[1]), float(args[2]), _parse_hold_seconds(args[3:]))
1313
1463
  print_success()
1314
1464
 
1315
1465
  elif command == "double-click":
@@ -1363,12 +1513,13 @@ def main():
1363
1513
  if len(args) < 5:
1364
1514
  exit_with_error(
1365
1515
  "Usage: linux-driver.py drag <from_x> <from_y> <to_x> <to_y> "
1366
- "[--steps N] [--path x1,y1 ...]"
1516
+ "[--steps N] [--path x1,y1 ...] [--hold-seconds N]"
1367
1517
  )
1368
1518
  from_x, from_y = float(args[1]), float(args[2])
1369
1519
  to_x, to_y = float(args[3]), float(args[4])
1370
1520
  steps = 10
1371
1521
  waypoints = None
1522
+ hold_seconds = _parse_hold_seconds(args[5:])
1372
1523
  di = 5
1373
1524
  while di < len(args):
1374
1525
  if args[di] == "--steps" and di + 1 < len(args):
@@ -1383,7 +1534,7 @@ def main():
1383
1534
  di += 1
1384
1535
  else:
1385
1536
  di += 1
1386
- mouse_drag(from_x, from_y, to_x, to_y, steps, waypoints)
1537
+ mouse_drag(from_x, from_y, to_x, to_y, steps, waypoints, hold_seconds)
1387
1538
  print_success()
1388
1539
 
1389
1540
  elif command == "screenshot":
@@ -1426,11 +1577,13 @@ def main():
1426
1577
  exit_with_error("Usage: linux-driver.py activate <app-name>")
1427
1578
  app_name = " ".join(args[1:])
1428
1579
  try:
1429
- activate_app(app_name)
1580
+ window_visible = activate_app(app_name)
1430
1581
  except RuntimeError as e:
1431
1582
  exit_with_error(str(e))
1432
1583
  time.sleep(0.5)
1433
- print_success()
1584
+ # `windowVisible: false` reports an app that was launched but has not shown
1585
+ # a window yet, so the caller waits instead of launching it again.
1586
+ print_success(windowVisible=window_visible)
1434
1587
 
1435
1588
  else:
1436
1589
  exit_with_error(f"Unknown command: '{command}'")