noracu 0.1.2 → 0.1.4

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.
@@ -21,10 +21,36 @@ from __future__ import annotations
21
21
 
22
22
  import argparse
23
23
  import json
24
+ import math
25
+ import os
26
+ import signal
24
27
  import sys
28
+ import tempfile
29
+ import time
25
30
 
26
31
  from . import gestures, input, verify, vision
27
- from .window import WindowError, get_overlay
32
+ from .vision import CaptureError
33
+ from .window import WindowError, ensure_frontmost, get_overlay
34
+
35
+ # F31: every phone input command starts in _require_live(), which first brings
36
+ # the mirror to the front — switching Spaces if needed and waiting for a real
37
+ # frame — so the expect OCR and scroll baseline that follow read the phone, not
38
+ # another Space or a transition frame. Module-level so tests can swap it.
39
+ _bring_front = ensure_frontmost
40
+
41
+ # F25: one line, one exit code for every capture failure. The pixels a check
42
+ # needed are not the phone's — report that, never guess from whatever
43
+ # another window happened to show inside the region.
44
+ _CAPTURE_FAILED_LINE = (
45
+ "capture_failed: could not capture the iPhone Mirroring window "
46
+ "(it may be hidden, minimized or on another Space); no image was returned"
47
+ )
48
+
49
+
50
+ def _capture_failed() -> int:
51
+ """Print the F25 capture-failure line; exit code 7."""
52
+ print(_CAPTURE_FAILED_LINE, file=sys.stderr)
53
+ return 7
28
54
 
29
55
 
30
56
  def _require_live() -> int | None:
@@ -32,7 +58,9 @@ def _require_live() -> int | None:
32
58
 
33
59
  Returns exit code 3 after printing a `mirror_not_live:` line when the mirror is
34
60
  verifiably not live; returns None (allow) when live or unknown (fail-open).
61
+ F31: brings the mirror to the front first (see _bring_front).
35
62
  """
63
+ _bring_front()
36
64
  overlay = get_overlay()
37
65
  if overlay["live"] is False:
38
66
  label = overlay["overlay"] or "overlay shown"
@@ -44,6 +72,47 @@ def _require_live() -> int | None:
44
72
  return None
45
73
 
46
74
 
75
+ def _require_expect(args, read_screen=None, read_sweep=None) -> int | None:
76
+ """Refuse input when the --expect anchor text is not on screen.
77
+
78
+ Between two phone_* calls the iPhone foreground can change (the user
79
+ picked up the phone, tapped a notification); the mirror cannot report
80
+ the phone's foreground app identity, so an OCR text anchor is the
81
+ only available guard — the iPhone-side counterpart of mac_key's app
82
+ focus guard. Returns None when no --expect was passed or the text is
83
+ on screen; returns exit code 5 after printing an ``expect_not_found:``
84
+ line when it is not, in which case nothing is sent. A capture failure
85
+ refuses the same way with ``capture_failed:`` and exit code 7 — an
86
+ unreadable screen is not a match, so nothing is sent then either.
87
+ """
88
+ expect = getattr(args, "expect", None)
89
+ if expect is None:
90
+ return None
91
+ if read_screen is None:
92
+ read_screen = vision.read_screen
93
+ if read_sweep is None:
94
+ def read_sweep():
95
+ return vision.read_screen(language_correction=False, sweep=True)
96
+ try:
97
+ hits = read_screen()
98
+ if (read_sweep is not None and verify.is_short_text(expect)
99
+ and not verify.screen_contains(expect, hits)):
100
+ # F27: a one- or two-character anchor (the app "X") can be invisible
101
+ # to the default OCR pass; read again with the sweep before refusing.
102
+ hits = read_sweep()
103
+ except (WindowError, CaptureError):
104
+ # F25: an unreadable screen is not a match — refuse exactly like
105
+ # expect_not_found; nothing is sent.
106
+ return _capture_failed()
107
+ if verify.screen_contains(expect, hits):
108
+ return None
109
+ print(
110
+ f"expect_not_found: {expect!r} is not on screen; nothing was sent",
111
+ file=sys.stderr,
112
+ )
113
+ return 5
114
+
115
+
47
116
  def _warn_if_not_live() -> None:
48
117
  """Print a heads-up before ocr/find output when the mirror is not live.
49
118
 
@@ -64,6 +133,9 @@ def _cmd_status(_args) -> int:
64
133
 
65
134
  def _cmd_tap(args) -> int:
66
135
  guard = _require_live()
136
+ if guard is not None:
137
+ return guard
138
+ guard = _require_expect(args)
67
139
  if guard is not None:
68
140
  return guard
69
141
  input.tap(args.x, args.y)
@@ -73,6 +145,9 @@ def _cmd_tap(args) -> int:
73
145
 
74
146
  def _cmd_longpress(args) -> int:
75
147
  guard = _require_live()
148
+ if guard is not None:
149
+ return guard
150
+ guard = _require_expect(args)
76
151
  if guard is not None:
77
152
  return guard
78
153
  input.long_press(args.x, args.y, args.duration)
@@ -82,6 +157,9 @@ def _cmd_longpress(args) -> int:
82
157
 
83
158
  def _cmd_swipe(args) -> int:
84
159
  guard = _require_live()
160
+ if guard is not None:
161
+ return guard
162
+ guard = _require_expect(args)
85
163
  if guard is not None:
86
164
  return guard
87
165
  input.swipe(args.fx, args.fy, args.tx, args.ty, args.ms)
@@ -105,10 +183,27 @@ def _cmd_scroll(args) -> int:
105
183
  guard = _require_live()
106
184
  if guard is not None:
107
185
  return guard
108
- if args.direction == "down":
109
- gestures.scroll_down(args.distance)
110
- else:
111
- gestures.scroll_up(args.distance)
186
+ guard = _require_expect(args)
187
+ if guard is not None:
188
+ return guard
189
+ try:
190
+ moved = gestures.scroll_checked(args.direction, args.distance)
191
+ except ValueError:
192
+ print(
193
+ "phone_scroll: distance is in window heights, "
194
+ "0 < distance <= 3 (default 0.5)",
195
+ file=sys.stderr,
196
+ )
197
+ return 2
198
+ except (WindowError, CaptureError):
199
+ return _capture_failed()
200
+ if not moved:
201
+ print(
202
+ "scroll_no_effect: the screen did not change (end of the list, "
203
+ "or the view under the cursor does not scroll)",
204
+ file=sys.stderr,
205
+ )
206
+ return 4
112
207
  print(f"scrolled {args.direction} {args.distance}")
113
208
  return 0
114
209
 
@@ -129,13 +224,118 @@ def _cmd_type(args) -> int:
129
224
  guard = _require_live()
130
225
  if guard is not None:
131
226
  return guard
132
- input.type_text(args.text)
133
- print(f"typed {args.text!r}")
134
- return 0
227
+ guard = _require_expect(args)
228
+ if guard is not None:
229
+ return guard
230
+ report = {}
231
+ if input.type_text(args.text, replace=args.replace, report=report):
232
+ print(f"typed {args.text!r}")
233
+ return 0
234
+ count_before = report.get("count_before")
235
+ late = _watch_late_paste(args.text, baseline=count_before)
236
+ if late is not None:
237
+ # F38: the paste did land, just late — report it so the caller does not
238
+ # retype it. The clipboard is deliberately NOT restored here: type_text()
239
+ # restores only under its own checks (a rise seen inside its window, the
240
+ # minimum hold, an untouched changeCount); after the fact, leaving the
241
+ # typed text on the clipboard is the choice that can never hand the phone
242
+ # the user's original clipboard (possibly a password).
243
+ print(f"typed {args.text!r} (the paste showed up late, during an extra "
244
+ f"{late:.0f}s check after the 2.5s confirmation window; the clipboard "
245
+ "still holds the typed text)")
246
+ return 0
247
+ watched = (f" or a further {LATE_PASTE_WATCH_S:.0f}s check"
248
+ if _late_paste_probe(args.text) else
249
+ " (one-character text cannot be confirmed by OCR afterwards)")
250
+ if args.replace and count_before:
251
+ # F41: the text was on screen before the paste, and a field replaced with
252
+ # the same text shows no change at all
253
+ advice = ("the text was already on screen before this paste, and replacing a "
254
+ "field with the same text shows no change — read the screen "
255
+ "(phone_ocr / phone_screenshot): if the field shows the text, it "
256
+ "holds it")
257
+ else:
258
+ advice = ("it may still land: read the screen (phone_ocr / phone_screenshot) "
259
+ "before typing again, or retype with replace=true")
260
+ print(
261
+ "type_not_confirmed: the paste did not show on screen within the 2.5s "
262
+ f"confirmation window{watched} — {advice}; the clipboard still holds the "
263
+ "typed text and your previous clipboard was not restored",
264
+ file=sys.stderr,
265
+ )
266
+ return 4
267
+
268
+
269
+ # F38 (2026-11-05 real-device): a paste reported unconfirmed after 2.5 s showed up a
270
+ # few seconds later, and the caller's retry typed the text twice ("… case … case").
271
+ # Before type_not_confirmed, keep watching — read-only, no second Cmd+V — for up to
272
+ # this long.
273
+ # F42: on the device a paste reached the phone up to more than 10 s after Cmd+V.
274
+ LATE_PASTE_WATCH_S = 15.0 # needs two consecutive sightings ~1 s apart
275
+
276
+
277
+ def _late_paste_probe(text):
278
+ """The OCR probe for ``text``, or None when OCR cannot confirm it (< 2 chars)."""
279
+ return verify.text_probe(text)
280
+
281
+
282
+ def _watch_late_paste(text, *, baseline=None, read_screen=None, sleep=time.sleep,
283
+ clock=time.monotonic, watch_s=LATE_PASTE_WATCH_S):
284
+ """Seconds into the watch until ``text`` showed up on screen, or None.
285
+
286
+ Read-only: it never pastes again. ``baseline`` is type_text()'s pre-paste
287
+ count of the text's probe (F41); the paste counts as arrived once the count
288
+ is above it in TWO consecutive readable frames (one OCR misread is not
289
+ enough). Without a baseline (type_text() could not read the screen before
290
+ the paste) the watch's own first two readable frames set it — the higher
291
+ count, as in type_text(): text already on screen elsewhere is then never
292
+ taken for the paste, at the price of missing a paste that landed before
293
+ those frames (reported unconfirmed — the caller is told to read the
294
+ screen before typing again). Text too short for a probe is
295
+ not watched at all (None at once). A capture failure breaks the run of
296
+ sightings (F25), never counts as one. ``read_screen``, ``sleep`` and
297
+ ``clock`` are injectable for tests.
298
+ """
299
+ if _late_paste_probe(text) is None:
300
+ return None
301
+ if read_screen is None:
302
+ read_screen = vision.read_screen
303
+ floor = baseline
304
+ floor_reads = [] # without a baseline: the counts of the first two readable frames
305
+ t0 = clock()
306
+ run = 0
307
+ # a first sighting always gets its confirming read, even past the window,
308
+ # and that read follows after a short pause rather than the usual second
309
+ while clock() - t0 < watch_s or run == 1:
310
+ try:
311
+ hits = read_screen()
312
+ except Exception as exc:
313
+ if not verify.is_capture_error(exc):
314
+ raise
315
+ hits = None
316
+ if hits is None:
317
+ run = 0
318
+ else:
319
+ seen = verify.probe_count(text, hits)
320
+ if floor is None:
321
+ floor_reads.append(seen) # no pre-paste count: these frames set the floor
322
+ if len(floor_reads) == 2:
323
+ floor = max(floor_reads)
324
+ elif seen > floor:
325
+ run += 1
326
+ if run >= 2:
327
+ return clock() - t0
328
+ else:
329
+ run = 0
330
+ sleep(0.4 if run == 1 else 1.0)
331
+ return None
135
332
 
136
333
 
137
334
  def _cmd_key(args) -> int:
138
335
  guard = _require_live()
336
+ if guard is not None:
337
+ return guard
338
+ guard = _require_expect(args)
139
339
  if guard is not None:
140
340
  return guard
141
341
  input.press_key(args.key)
@@ -145,7 +345,10 @@ def _cmd_key(args) -> int:
145
345
 
146
346
  def _cmd_ocr(_args) -> int:
147
347
  _warn_if_not_live()
148
- hits = gestures.read_text()
348
+ try:
349
+ hits = gestures.read_text()
350
+ except (WindowError, CaptureError):
351
+ return _capture_failed()
149
352
  for h in hits:
150
353
  print(h)
151
354
  print(f"-- {len(hits)} hits")
@@ -154,7 +357,10 @@ def _cmd_ocr(_args) -> int:
154
357
 
155
358
  def _cmd_find(args) -> int:
156
359
  _warn_if_not_live()
157
- hit = vision.find(args.text, exact=args.exact)
360
+ try:
361
+ hit = vision.find(args.text, exact=args.exact)
362
+ except (WindowError, CaptureError):
363
+ return _capture_failed()
158
364
  if hit is None:
159
365
  print(f"not found: {args.text!r}", file=sys.stderr)
160
366
  return 1
@@ -162,18 +368,99 @@ def _cmd_find(args) -> int:
162
368
  return 0
163
369
 
164
370
 
371
+ def _open_deadline_kwargs(now=time.time) -> dict:
372
+ """open_app's time budget from NORACU_OPEN_DEADLINE_EPOCH, an absolute time the
373
+ server sets well before its own timeout (counted from the spawn, so start-up
374
+ and opening Spotlight are inside it). {} → open_app's default."""
375
+ try:
376
+ epoch = float(os.environ.get("NORACU_OPEN_DEADLINE_EPOCH", ""))
377
+ except ValueError:
378
+ return {}
379
+ if not math.isfinite(epoch) or epoch <= 0: # NaN, inf or nonsense
380
+ return {}
381
+ # already past → 0: open_app goes back to the Home Screen without clearing or typing
382
+ return {"deadline_s": max(0.0, epoch - now())}
383
+
384
+
165
385
  def _cmd_open(args) -> int:
166
386
  guard = _require_live()
167
387
  if guard is not None:
168
388
  return guard
169
389
  # Open Spotlight here (not inside open_app) so a failure can be
170
390
  # reported as its own condition instead of a bogus "app not found".
171
- if not gestures.open_spotlight():
172
- print("spotlight unavailable")
391
+ try:
392
+ return _open_and_report(args)
393
+ except SystemExit:
394
+ # Stopped from outside (the server's timeout sends SIGTERM, imctl turns it
395
+ # into SystemExit) — anywhere in open, not only inside open_app: leave the
396
+ # phone on the Home Screen rather than in Spotlight with text typed in.
397
+ # Best effort: the server sends SIGKILL 1.5 s after the SIGTERM.
398
+ try:
399
+ gestures.home_via_menu()
400
+ except BaseException:
401
+ pass
402
+ raise
403
+
404
+
405
+ def _open_and_report(args) -> int:
406
+ tidy = {} # open_app records whether its trip back to the Home Screen worked
407
+ try:
408
+ # F34: one retry — on the device the Spotlight command was once
409
+ # ignored right after an app closed. Each try goes Home first; when Home
410
+ # lands back in Spotlight (iOS 27, F43) the gate reports it open instead
411
+ # of toggling it shut.
412
+ if not (gestures.open_spotlight_checked()
413
+ or gestures.open_spotlight_checked()):
414
+ result = "spotlight_unavailable"
415
+ else:
416
+ result = gestures.open_app(args.app, spotlight_open=True, report=tidy,
417
+ **_open_deadline_kwargs())
418
+ except (WindowError, CaptureError):
419
+ # F25: the Spotlight gate and the result matching both read the
420
+ # mirroring window's pixels; without them nothing about the
421
+ # phone is known — refuse rather than guess.
422
+ return _capture_failed()
423
+ if result == "opened":
424
+ print(f"opened {args.app!r}")
425
+ return 0
426
+ # every unsuccessful path ends with a trip back to the Home Screen; say so only
427
+ # when it worked
428
+ home_note = ("back on the Home Screen" if tidy.get("home") else
429
+ "could not go back to the Home Screen — Spotlight may still be open")
430
+ # the app-not-found lines mention the Home Screen only when the trip back failed
431
+ stuck = "" if tidy.get("home") else f"; {home_note}"
432
+ if result == "not_found":
433
+ print(f"app not found: {args.app!r} (Spotlight's Top Hit did not show exactly "
434
+ f"this name — use the name the phone shows under the app icon){stuck}")
173
435
  return 1
174
- ok = gestures.open_app(args.app, spotlight_open=True)
175
- print(f"opened {args.app!r}" if ok else f"app not found: {args.app!r}")
176
- return 0 if ok else 1
436
+ if result == "no_top_hit":
437
+ if os.environ.get("NORACU_TOPHIT_LABELS", "").strip():
438
+ print(f"app not found: {args.app!r} (Spotlight showed no Top Hit labelled "
439
+ f"{', '.join(repr(x) for x in gestures.TOP_HIT_LABELS)} — no app by that "
440
+ f"name, or NORACU_TOPHIT_LABELS does not match your iPhone's label){stuck}")
441
+ else:
442
+ print(f"app not found: {args.app!r} (Spotlight showed no Top Hit — no app by that "
443
+ "name, or the iPhone is not set to English: phone_open reads Spotlight's "
444
+ f"\"Top Hit\" label; set NORACU_TOPHIT_LABELS to the label your iPhone shows){stuck}")
445
+ return 1
446
+ if result == "deadline":
447
+ print(f"open_not_confirmed: ran out of time opening {args.app!r} (the Mac may be "
448
+ f"under heavy load); {home_note}", file=sys.stderr)
449
+ return 4
450
+ if result == "not_typed":
451
+ print(f"open_not_confirmed: the name {args.app!r} was pasted into Spotlight but never "
452
+ "showed up on the phone (a paste can take several seconds to reach the iPhone, "
453
+ "or be lost; an iPhone not set to English also needs NORACU_TOPHIT_LABELS) — "
454
+ f"nothing was tapped; {home_note}; retry phone_open", file=sys.stderr)
455
+ return 4
456
+ if result == "spotlight_unavailable":
457
+ print("spotlight unavailable (could not reach the Home Screen, the menu command failed, or the screen did not change)")
458
+ return 1
459
+ # "not_confirmed" (F24): the row — and possibly the Top Hit icon —
460
+ # was tapped but the app never verifiably opened; the phone is
461
+ # back on the Home Screen.
462
+ print(f"open_not_confirmed: tapped {args.app!r} in Spotlight but the app did not open; {home_note}", file=sys.stderr)
463
+ return 4
177
464
 
178
465
 
179
466
  def _cmd_verify(args) -> int:
@@ -192,20 +479,56 @@ def _cmd_verify(args) -> int:
192
479
 
193
480
 
194
481
  def _cmd_launch(_args) -> int:
195
- gestures.launch()
196
- print("iPhone Mirroring ready")
482
+ live = gestures.launch()
483
+ if live is False:
484
+ # F29: never report "ready" while the overlay is still up.
485
+ from .window import is_setup_screen
486
+
487
+ if is_setup_screen():
488
+ # F37: a welcome / setup screen is the user's to finish; nothing was clicked.
489
+ print(
490
+ "mirror_setup_required: iPhone Mirroring is showing a setup or welcome "
491
+ "screen (its window is not phone-shaped) — finish it in the iPhone "
492
+ "Mirroring window yourself (noracu never clicks through setup screens), "
493
+ "then call phone_launch again",
494
+ file=sys.stderr,
495
+ )
496
+ return 3
497
+ print(
498
+ "mirror_not_live: iPhone Mirroring is not live yet — if it shows a paused "
499
+ "notice, lock the iPhone and keep it near the Mac; if it is reconnecting, wait "
500
+ "a few seconds and check phone_status; then call phone_launch again",
501
+ file=sys.stderr,
502
+ )
503
+ return 3
504
+ print("iPhone Mirroring ready" if live else "iPhone Mirroring launched (stream state unknown)")
197
505
  return 0
198
506
 
199
507
 
200
508
  def _cmd_screenshot(args) -> int:
201
- path = vision.capture_window(args.path)
509
+ path = args.path
510
+ if path is None:
511
+ # A screenshot asked for outlives this process: an owner-only (0600)
512
+ # file in the temp directory, unlike the OCR frames, which are
513
+ # deleted once read.
514
+ fd, path = tempfile.mkstemp(prefix="imctl_screenshot_", suffix=".png")
515
+ os.close(fd)
516
+ try:
517
+ path = vision.capture_window(path)
518
+ except (WindowError, CaptureError):
519
+ if args.path is None:
520
+ try:
521
+ os.remove(path) # the empty placeholder made above
522
+ except OSError:
523
+ pass
524
+ return _capture_failed()
202
525
  print(path)
203
526
  return 0
204
527
 
205
528
 
206
529
  def _cmd_resume(_args) -> int:
207
530
  ok = gestures.resume()
208
- print("resumed" if ok else "still paused (unlock the iPhone, then retry)")
531
+ print("resumed" if ok else "still paused (lock the iPhone, keep it near the Mac, then retry)")
209
532
  return 0 if ok else 1
210
533
 
211
534
 
@@ -226,12 +549,14 @@ def build_parser() -> argparse.ArgumentParser:
226
549
  sp = sub.add_parser("tap", help="tap at normalized coords")
227
550
  sp.add_argument("x", type=float)
228
551
  sp.add_argument("y", type=float)
552
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
229
553
  sp.set_defaults(func=_cmd_tap)
230
554
 
231
555
  sp = sub.add_parser("longpress", help="long-press at normalized coords")
232
556
  sp.add_argument("x", type=float)
233
557
  sp.add_argument("y", type=float)
234
558
  sp.add_argument("--duration", type=float, default=0.8)
559
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
235
560
  sp.set_defaults(func=_cmd_longpress)
236
561
 
237
562
  sp = sub.add_parser("swipe", help="swipe between two normalized points")
@@ -240,6 +565,7 @@ def build_parser() -> argparse.ArgumentParser:
240
565
  sp.add_argument("tx", type=float)
241
566
  sp.add_argument("ty", type=float)
242
567
  sp.add_argument("--ms", type=int, default=300)
568
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
243
569
  sp.set_defaults(func=_cmd_swipe)
244
570
 
245
571
  sub.add_parser("home", help="home gesture").set_defaults(func=_cmd_home)
@@ -248,6 +574,7 @@ def build_parser() -> argparse.ArgumentParser:
248
574
  sp = sub.add_parser("scroll", help="scroll up/down")
249
575
  sp.add_argument("direction", choices=["up", "down"])
250
576
  sp.add_argument("distance", type=float, nargs="?", default=0.5)
577
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
251
578
  sp.set_defaults(func=_cmd_scroll)
252
579
 
253
580
  sp = sub.add_parser("page", help="page left/right on home screen")
@@ -256,10 +583,14 @@ def build_parser() -> argparse.ArgumentParser:
256
583
 
257
584
  sp = sub.add_parser("type", help="type text (clipboard-based, IME-safe)")
258
585
  sp.add_argument("text")
586
+ sp.add_argument("--replace", action="store_true",
587
+ help="select all in the focused field first, then overwrite it")
588
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
259
589
  sp.set_defaults(func=_cmd_type)
260
590
 
261
591
  sp = sub.add_parser("key", help="press a key (return/delete/up/down/left/right)")
262
592
  sp.add_argument("key")
593
+ sp.add_argument("--expect", help="refuse to act unless this text is on screen (OCR)")
263
594
  sp.set_defaults(func=_cmd_key)
264
595
 
265
596
  sub.add_parser("ocr", help="OCR the screen").set_defaults(func=_cmd_ocr)
@@ -280,11 +611,28 @@ def build_parser() -> argparse.ArgumentParser:
280
611
  return p
281
612
 
282
613
 
614
+ def _on_sigterm(signum, _frame):
615
+ # The server ends a call that runs past its time limit with SIGTERM. As
616
+ # SystemExit it unwinds normally: OCR frames are deleted, and a paste
617
+ # that never went out puts the clipboard back (type_text decides).
618
+ raise SystemExit(128 + signum)
619
+
620
+
283
621
  def main(argv: list[str] | None = None) -> int:
622
+ signal.signal(signal.SIGTERM, _on_sigterm)
284
623
  parser = build_parser()
285
624
  args = parser.parse_args(argv)
286
625
  try:
287
626
  return args.func(args)
627
+ except input.FocusLost:
628
+ # F26: the frontmost check failed right before an event — either
629
+ # nothing was sent at all, or (mid-scroll) nothing further was.
630
+ print(
631
+ "focus_lost: iPhone Mirroring is not the frontmost app; "
632
+ "nothing (or nothing further) was sent",
633
+ file=sys.stderr,
634
+ )
635
+ return 6
288
636
  except WindowError as exc:
289
637
  print(f"window error: {exc}", file=sys.stderr)
290
638
  return 3