noracu 0.2.6 → 0.3.0

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.
@@ -28,17 +28,20 @@ import sys
28
28
  import tempfile
29
29
  import time
30
30
 
31
- from . import gestures, input, verify, vision
31
+ from . import gestures, input, pointer, screenrect, verify, vision
32
32
  from .vision import CaptureError
33
33
  import subprocess
34
34
 
35
- from .window import WindowError, ensure_frontmost, get_overlay, is_frontmost
35
+ from .window import WindowError, ensure_frontmost, get_overlay, get_window_info, is_frontmost
36
36
 
37
37
  # F31 / R13 §3: every phone input command starts in _require_live(), which probes
38
38
  # get_overlay() first so a paused or stopped mirror refuses without stealing focus,
39
39
  # then brings the mirror to the front (switching Spaces if needed and waiting for a
40
40
  # real frame) before any capture or input. Module-level callables so tests can swap them.
41
41
  _bring_front = ensure_frontmost
42
+ _screen_rect = verify.screen_rect # where the phone screen sits in the window (one capture); swappable in tests
43
+ _window_info = get_window_info # the mirror window's CGWindow record (its size keys the remembered edges); swappable in tests
44
+ _rect_file = None # where the screen's edges are remembered (None: screenrect.cache_file()); swappable in tests
42
45
  _is_front = is_frontmost
43
46
  sleep = time.sleep
44
47
 
@@ -66,12 +69,119 @@ _CAPTURE_FAILED_EXPECT_LINE = (
66
69
  )
67
70
 
68
71
 
72
+ # 2026-11-10: the same failure while measuring where the phone screen sits in the window, before a swipe
73
+ _CAPTURE_FAILED_EDGES_LINE = (
74
+ "capture_failed: could not read the iPhone Mirroring window's image to find the phone screen's edges "
75
+ "(it may be hidden, minimized or on another Space); nothing was sent"
76
+ )
77
+
78
+
69
79
  def _capture_failed() -> int:
70
80
  """Print the F25 capture-failure line; exit code 7."""
71
81
  print(_CAPTURE_FAILED_LINE, file=sys.stderr)
72
82
  return 7
73
83
 
74
84
 
85
+ def _phone_screen(*, retry_untrusted: bool):
86
+ """Where the phone screen sits in the mirror window as it is now: (rect or None, how).
87
+
88
+ Remembered per window size and macOS version (screenrect); the window is captured only when
89
+ nothing trusted is remembered for this size. Raises WindowError / CaptureError from that capture.
90
+ """
91
+ wi = _window_info()
92
+ if not wi:
93
+ raise WindowError("iPhone Mirroring window not found")
94
+ return screenrect.resolve(screenrect.key(wi["w"], wi["h"]), _screen_rect,
95
+ retry_untrusted=retry_untrusted, path=_rect_file)
96
+
97
+
98
+ _EDGES_UNTRUSTED = ("the window's image showed no strip above the screen, as it does while the pointer rests on "
99
+ "the window's top edge")
100
+ _EDGES_UNREADABLE = "the window's image could not be read"
101
+
102
+
103
+ _edges_note = "" # what a tap's result line adds when it went out with the screen's edges not known
104
+
105
+
106
+ def _refuse_off_screen(x: float, y: float, *, measure: bool) -> int | None:
107
+ """Refuse a tap or long press aimed at the mirror window's margin (exit 2); None lets it go on.
108
+
109
+ Called twice: first with measure=False, before the mirror is brought forward, from remembered
110
+ edges only (a refused point then takes no focus and makes no capture); then with measure=True,
111
+ once the mirror is live and in front, where the edges are measured if nothing is remembered.
112
+
113
+ When the measurement cannot be trusted (the pointer resting on the strip above the screen), a
114
+ point where the margin may be is refused as well — everything outside screenrect.fallback(): the
115
+ top of the window and a band along its other sides. The strip above the screen holds the
116
+ window's own controls, and a click there is a click on the Mac, not on the phone. Before a point
117
+ is refused on an untrusted measurement made earlier, the window is measured once more. A point
118
+ that goes out anyway says so in its result (_edges_note).
119
+
120
+ When nothing is remembered and the window's image cannot be read at all, nothing says where the
121
+ phone screen is: capture_failed (exit 7) and nothing is sent, as for a swipe. The same when the
122
+ window has no record once the mirror is live: without its size the bands cannot be measured.
123
+ """
124
+ global _edges_note
125
+ if measure:
126
+ _edges_note = ""
127
+ wi = None
128
+ try:
129
+ wi = _window_info()
130
+ if not measure:
131
+ rect = screenrect.remembered(screenrect.key(wi["w"], wi["h"]), path=_rect_file) if wi else None
132
+ if rect is None:
133
+ return None # nothing remembered: decided once the mirror is live and in front
134
+ elif not wi:
135
+ # the live check has just seen the window and now there is no record of it: nothing says where the
136
+ # phone screen is, and without the window's size the bands cannot be measured (pre-review P5)
137
+ raise WindowError("iPhone Mirroring window not found")
138
+ else:
139
+ rect, how = _phone_screen(retry_untrusted=False)
140
+ if rect is None and how == "not_measured":
141
+ safe = screenrect.fallback(wi["w"], wi["h"])
142
+ if safe is None or not screenrect.contains(safe, x, y):
143
+ # an earlier measurement could not be trusted and this point is where the margin may
144
+ # be: one more capture now, rather than a refusal on that old doubt
145
+ rect, how = _phone_screen(retry_untrusted=True)
146
+ except (WindowError, CaptureError):
147
+ if not measure:
148
+ return None
149
+ print(_CAPTURE_FAILED_EDGES_LINE, file=sys.stderr)
150
+ return 7
151
+ if rect is not None:
152
+ if screenrect.contains(rect, x, y):
153
+ return None
154
+ x0, y0, x1, y1 = rect
155
+ print(
156
+ f"out_of_screen: ({_num(x)},{_num(y)}) is on the iPhone Mirroring window's margin, not on the "
157
+ f"phone screen (x {x0:.3f}-{x1:.3f}, y {y0:.3f}-{y1:.3f}): a click there goes to the window's "
158
+ f"own controls or nowhere; nothing was sent",
159
+ file=sys.stderr,
160
+ )
161
+ return 2
162
+ safe = screenrect.fallback(wi["w"], wi["h"])
163
+ if safe is not None and screenrect.contains(safe, x, y):
164
+ _edges_note = (" — the phone screen's edges are not known; the point is clear of where the window's "
165
+ "margin may be")
166
+ return None
167
+ if safe is None:
168
+ print(
169
+ f"out_of_screen: the phone screen's edges are not known ({_EDGES_UNTRUSTED}) and the iPhone Mirroring window is too "
170
+ f"small to have a part that is certainly clear of its margin; nothing was sent",
171
+ file=sys.stderr,
172
+ )
173
+ return 2
174
+ x0, y0, x1, y1 = safe
175
+ print(
176
+ f"out_of_screen: ({_num(x)},{_num(y)}) may be on the iPhone Mirroring window's margin: the phone "
177
+ f"screen's edges are not known ({_EDGES_UNTRUSTED}), and while they are not, a point outside x {x0:.3f}-{x1:.3f}, "
178
+ f"y {y0:.3f}-{y1:.3f} is not sent — the strip above the screen holds the window's own controls; "
179
+ f"nothing was sent. Move the pointer off the top of the mirror window and try again, or aim further inside",
180
+ file=sys.stderr,
181
+ )
182
+ return 2
183
+
184
+
75
185
  def _mirror_not_live(overlay: dict) -> int:
76
186
  label = overlay.get("overlay") or "overlay shown"
77
187
  print(
@@ -201,14 +311,20 @@ def _cmd_status(_args) -> int:
201
311
 
202
312
 
203
313
  def _cmd_tap(args) -> int:
314
+ guard = _refuse_off_screen(args.x, args.y, measure=False)
315
+ if guard is not None:
316
+ return guard
204
317
  guard = _require_live()
318
+ if guard is not None:
319
+ return guard
320
+ guard = _refuse_off_screen(args.x, args.y, measure=True)
205
321
  if guard is not None:
206
322
  return guard
207
323
  guard = _require_expect(args)
208
324
  if guard is not None:
209
325
  return guard
210
326
  input.tap(args.x, args.y)
211
- print(f"tapped ({args.x}, {args.y})")
327
+ print(f"tapped ({args.x}, {args.y}){_edges_note}")
212
328
  return 0
213
329
 
214
330
 
@@ -223,7 +339,13 @@ def _cmd_longpress(args) -> int:
223
339
  input._check_duration(_longpress_duration(args), 0.01, 10, "long-press duration (s)")
224
340
  except ValueError as exc:
225
341
  return _invalid_duration(exc)
342
+ guard = _refuse_off_screen(args.x, args.y, measure=False)
343
+ if guard is not None:
344
+ return guard
226
345
  guard = _require_live()
346
+ if guard is not None:
347
+ return guard
348
+ guard = _refuse_off_screen(args.x, args.y, measure=True)
227
349
  if guard is not None:
228
350
  return guard
229
351
  guard = _require_expect(args)
@@ -231,7 +353,7 @@ def _cmd_longpress(args) -> int:
231
353
  return guard
232
354
  duration = _longpress_duration(args)
233
355
  input.long_press(args.x, args.y, duration)
234
- print(f"long-pressed ({args.x}, {args.y}) for {duration}s")
356
+ print(f"long-pressed ({args.x}, {args.y}) for {duration}s{_edges_note}")
235
357
  return 0
236
358
 
237
359
 
@@ -252,11 +374,108 @@ def _cmd_swipe(args) -> int:
252
374
  guard = _require_expect(args)
253
375
  if guard is not None:
254
376
  return guard
255
- input.swipe(args.fx, args.fy, args.tx, args.ty, args.ms)
256
- print(f"swiped ({args.fx},{args.fy}) -> ({args.tx},{args.ty})")
377
+ asked = (args.fx, args.fy, args.tx, args.ty)
378
+ try:
379
+ rect, _how = _phone_screen(retry_untrusted=True)
380
+ except (WindowError, CaptureError):
381
+ print(_CAPTURE_FAILED_EDGES_LINE, file=sys.stderr)
382
+ return 7
383
+ if rect is None:
384
+ # the capture could not tell the phone screen from the window's margin: both points are kept clear of
385
+ # where that margin may be (the top of the window holds its own controls: a drag from there acts on the
386
+ # window, not on the phone)
387
+ try:
388
+ wi = _window_info()
389
+ except (WindowError, CaptureError):
390
+ wi = None
391
+ if not wi:
392
+ # the window was there for the measurement and has no record now: nothing is sent (pre-review P5)
393
+ print(_CAPTURE_FAILED_EDGES_LINE, file=sys.stderr)
394
+ return 7
395
+ safe = screenrect.fallback(wi["w"], wi["h"])
396
+ if safe is None:
397
+ print("out_of_screen: the phone screen's edges are not known and the iPhone Mirroring window is too small to "
398
+ "have a part that is certainly clear of its margin; nothing was sent", file=sys.stderr)
399
+ return 2
400
+ fx, fy = input.clamp_to_rect(args.fx, args.fy, safe, inset=0.0)
401
+ tx, ty = input.clamp_to_rect(args.tx, args.ty, safe, inset=0.0)
402
+ if _collapsed(asked, (fx, fy, tx, ty)):
403
+ return _refuse_collapsed(asked)
404
+ input.swipe(fx, fy, tx, ty, args.ms)
405
+ print(_swipe_line(asked, (fx, fy, tx, ty), safe, known=False))
406
+ return 0
407
+ fx, fy = input.clamp_to_rect(args.fx, args.fy, rect)
408
+ tx, ty = input.clamp_to_rect(args.tx, args.ty, rect)
409
+ if _collapsed(asked, (fx, fy, tx, ty)):
410
+ return _refuse_collapsed(asked)
411
+ input.swipe(fx, fy, tx, ty, args.ms)
412
+ print(_swipe_line(asked, (fx, fy, tx, ty), rect))
257
413
  return 0
258
414
 
259
415
 
416
+ def _num(v: float) -> str:
417
+ return f"{round(v, 3):g}"
418
+
419
+
420
+ # A swipe whose points were moved clear of the margin and that is left shorter than this (in points of the
421
+ # 280x620 pt mirror window measured on 2026-11-10) is refused: iOS starts a pan only after about 10 pt, so a
422
+ # shorter drag lands as a tap or press on whatever is under it (review S4A-s10-gemini-1).
423
+ _MIN_MOVED_SWIPE_PT = 10.0
424
+ _REF_WINDOW_PT = (280.0, 620.0)
425
+
426
+
427
+ def _collapsed(asked, sent) -> bool:
428
+ """True when moving a point clear of the margin left the swipe too short to be a swipe: a press, not a
429
+ swipe — whatever length it was asked for with (a pull-down from the margin that ends just inside the
430
+ screen would otherwise go out as a tap at the top of the app). That covers a swipe whose two ends read
431
+ as the same point in the result line. A swipe that was not moved goes out as it was asked."""
432
+ moved = any(abs(p - q) > 1e-9 for p, q in zip(asked, sent))
433
+ if not moved:
434
+ return False
435
+ if (_num(sent[0]), _num(sent[1])) == (_num(sent[2]), _num(sent[3])):
436
+ return True
437
+ w, h = _REF_WINDOW_PT
438
+ return math.hypot((sent[2] - sent[0]) * w, (sent[3] - sent[1]) * h) < _MIN_MOVED_SWIPE_PT
439
+
440
+
441
+ def _refuse_collapsed(asked) -> int:
442
+ print(
443
+ f"out_of_screen: the swipe from ({_num(asked[0])},{_num(asked[1])}) to ({_num(asked[2])},{_num(asked[3])}) "
444
+ f"starts or ends on the iPhone Mirroring window's margin, or where it may be: with its points moved "
445
+ f"onto the phone screen it would be shorter than a swipe (under about {_MIN_MOVED_SWIPE_PT:g} pt) — a press, "
446
+ f"not a swipe; nothing was sent",
447
+ file=sys.stderr,
448
+ )
449
+ return 2
450
+
451
+
452
+ def _swipe_line(asked, sent, rect, known: bool = True) -> str:
453
+ """The phone_swipe result line; names every point that was moved. ``rect`` is the phone screen, or —
454
+ with known=False, while its edges are not known — the part of the window clear of where the margin may be."""
455
+ line = f"swiped ({_num(sent[0])},{_num(sent[1])}) -> ({_num(sent[2])},{_num(sent[3])})"
456
+ moved = [
457
+ f"{name} ({_num(a[0])},{_num(a[1])})"
458
+ for name, a, b in (("start", asked[:2], sent[:2]), ("end", asked[2:], sent[2:]))
459
+ if any(abs(p - q) > 1e-9 for p, q in zip(a, b))
460
+ ]
461
+ x0, y0, x1, y1 = rect
462
+ if not known:
463
+ what = (f"moved the {' and '.join(moved)} clear of where the window's margin may be, into x {x0:.3f}-{x1:.3f} "
464
+ f"y {y0:.3f}-{y1:.3f}" if moved else "both points are clear of where the window's margin may be")
465
+ return line + (
466
+ " (the phone screen's edges are not known: the window's image showed no strip above the "
467
+ f"screen, as it does while the pointer rests on the window's top edge; {what}; iOS cancels a "
468
+ "drag that starts or ends on the transparent window margin)"
469
+ )
470
+ if moved:
471
+ line += (
472
+ f" (moved the {' and '.join(moved)} inside the phone screen, x {x0:.3f}-{x1:.3f} "
473
+ f"y {y0:.3f}-{y1:.3f}: iOS cancels a drag that starts or ends on the transparent "
474
+ f"window margin around it)"
475
+ )
476
+ return line
477
+
478
+
260
479
  def _cmd_home(_args) -> int:
261
480
  guard = _require_live()
262
481
  if guard is not None:
@@ -324,22 +543,33 @@ def _cmd_type(args) -> int:
324
543
  if guard is not None:
325
544
  return guard
326
545
  report = {}
327
- if input.type_text(args.text, replace=args.replace, report=report):
546
+ try:
547
+ typed_ok = input.type_text(args.text, replace=args.replace, report=report)
548
+ except input.PasteFocusLost:
549
+ # 0.2.7: another app came to the front during the wait after the clipboard write;
550
+ # ⌘V was called off rather than pulling iPhone Mirroring back to the front
551
+ sent = ("the select-all (⌘A) for replace was sent, but nothing was pasted" if args.replace
552
+ else "nothing was sent")
553
+ print("focus_lost: another app came to the front before ⌘V, so iPhone Mirroring was not "
554
+ f"brought back and the paste was called off — {sent}; the clipboard was put back "
555
+ "unless something else had copied meanwhile", file=sys.stderr)
556
+ return 6
557
+ if typed_ok:
328
558
  if report.get("seen", True):
329
559
  if _late_paste_probe(args.text) is None:
330
560
  # 0.2.5 (review Y6): one character that OCR saw appear is no proof of where it went,
331
561
  # and (review R38) no license to put the clipboard back
332
562
  print(f"typed {len(args.text)} chars (one character: OCR saw it appear, which is no "
333
- "proof of where it landed — check the field; the clipboard still holds the "
334
- "typed text)")
563
+ "proof of where it landed — check the field, which may hold the phone's own older "
564
+ "clipboard instead; the clipboard still holds the typed text)")
335
565
  return 0
336
566
  print(f"typed {len(args.text)} chars")
337
567
  return 0
338
568
  if _late_paste_probe(args.text) is None:
339
569
  # one character: OCR cannot read it back, only the picture changed
340
570
  print(f"typed {len(args.text)} chars (the screen changed after the paste, but "
341
- "OCR cannot read this text back — check the field; the clipboard still "
342
- "holds the typed text)")
571
+ "OCR cannot read this text back — check the field, which may hold the phone's own "
572
+ "older clipboard instead; the clipboard still holds the typed text)")
343
573
  return 0
344
574
  # review 0.2.6 #7: the screen changed and OCR could not confirm the text for a reason
345
575
  # known now — say that one, instead of watching for a late paste that would only
@@ -348,12 +578,14 @@ def _cmd_type(args) -> int:
348
578
  if cause == "too_short":
349
579
  print(f"typed {len(args.text)} chars (the screen changed after the paste, but a text "
350
580
  "of fewer than four characters, spaces and case aside, is never confirmed by "
351
- "OCR — check the field; the clipboard still holds the typed text)")
581
+ "OCR — check the field, which may hold the phone's own older clipboard instead; the "
582
+ "clipboard still holds the typed text)")
352
583
  return 0
353
584
  if cause == "strip_only":
354
585
  print(f"typed {len(args.text)} chars (OCR saw the text appear only in the strip at the "
355
586
  "top of the screen, where a field cannot be told from a notification banner — "
356
- "check the field; the clipboard still holds the typed text)")
587
+ "check the field, which may hold the phone's own older clipboard instead; the "
588
+ "clipboard still holds the typed text)")
357
589
  return 0
358
590
  # device run 2026-11-06: only the picture changed (a selection highlight, a
359
591
  # results list redraw) and OCR never saw the text — watch for it like an
@@ -387,8 +619,11 @@ def _cmd_type(args) -> int:
387
619
  "(phone_ocr / phone_screenshot): if the field shows the text, it "
388
620
  "holds it")
389
621
  else:
390
- advice = ("it may still land: read the screen (phone_ocr / phone_screenshot) "
391
- "before typing again, or retype with replace=true")
622
+ # device run 2026-11-07/08: the phone can paste its own older clipboard when the Mac's
623
+ # new clipboard has not reached it yet — the field may hold other text, not nothing
624
+ advice = ("it may still land, or the phone may have pasted its own older clipboard "
625
+ "instead: read the screen (phone_ocr / phone_screenshot) before typing "
626
+ "again, or retype with replace=true")
392
627
  print(
393
628
  "type_not_confirmed: the paste did not show on screen within the 2.5s "
394
629
  f"confirmation window{watched} — {advice}; the clipboard still holds the "
@@ -515,6 +750,12 @@ def _open_deadline_kwargs(now=time.time) -> dict:
515
750
 
516
751
 
517
752
  def _cmd_open(args) -> int:
753
+ # a minimum that was meant to be on but cannot be read is not run without: said before anything is touched
754
+ problem = getattr(gestures, "OCR_MIN_CONFIDENCE_PROBLEM", None)
755
+ if problem is not None:
756
+ print(f"invalid_args: NORACU_OCR_MIN_CONFIDENCE is set to {str(problem)[:40]!r}, which is not a number above 0 "
757
+ f"and at most 1 — correct it or unset it; nothing was sent", file=sys.stderr)
758
+ return 2
518
759
  guard = _require_live()
519
760
  if guard is not None:
520
761
  return guard
@@ -527,6 +768,21 @@ def _cmd_open(args) -> int:
527
768
  return _open_and_report(args)
528
769
 
529
770
 
771
+ def _fmt_confidence(value) -> str:
772
+ return f"{value:.2f}" if isinstance(value, (int, float)) and not isinstance(value, bool) else "?"
773
+
774
+
775
+ def _confidence_note(report: dict) -> str:
776
+ """' (label read with confidence 0.90)' for phone_open's line; '' when open_app recorded none.
777
+ The opt-in minimum (NORACU_OCR_MIN_CONFIDENCE) is named when it is in force."""
778
+ conf = report.get("confidence")
779
+ if not isinstance(conf, (int, float)) or isinstance(conf, bool):
780
+ return ""
781
+ floor = report.get("min_confidence")
782
+ tail = f"; minimum {_fmt_confidence(floor)}" if floor is not None else ""
783
+ return f" (label read with confidence {_fmt_confidence(conf)}{tail})"
784
+
785
+
530
786
  def _open_and_report(args) -> int:
531
787
  tidy = {} # open_app records whether its trip back to the Home Screen worked
532
788
  try:
@@ -546,7 +802,7 @@ def _open_and_report(args) -> int:
546
802
  # phone is known — refuse rather than guess.
547
803
  return _capture_failed()
548
804
  if result == "opened":
549
- print(f"opened {args.app!r}")
805
+ print(f"opened {args.app!r}{_confidence_note(tidy)}")
550
806
  return 0
551
807
  # every unsuccessful path ends with a trip back to the Home Screen; say so only
552
808
  # when it worked
@@ -564,9 +820,14 @@ def _open_and_report(args) -> int:
564
820
  f"{', '.join(repr(x) for x in gestures.TOP_HIT_LABELS)} — no app by that "
565
821
  f"name, or NORACU_TOPHIT_LABELS does not match your iPhone's label){stuck}")
566
822
  else:
567
- print(f"app not found: {args.app!r} (Spotlight showed no Top Hit — no app by that "
568
- "name, or the iPhone is not set to English: phone_open reads Spotlight's "
569
- f"\"Top Hit\" label; set NORACU_TOPHIT_LABELS to the label your iPhone shows){stuck}")
823
+ # 2026-11-08: the top-field Spotlight shows no Top Hit header at all; there the
824
+ # evidence is the field completing the name with "— Open"
825
+ print(f"app not found: {args.app!r} (Spotlight showed no Top Hit, and its search "
826
+ "field did not complete the name with \"— Open\" — no app by that name, or "
827
+ "the iPhone is not set to English: phone_open reads Spotlight's \"Top Hit\" "
828
+ "label and \"Open\" completion; NORACU_TOPHIT_LABELS sets the Top Hit label for "
829
+ "another language, the \"Open\" completion is read in English only)"
830
+ f"{stuck}")
570
831
  return 1
571
832
  if result == "deadline":
572
833
  print(f"open_not_confirmed: ran out of time opening {args.app!r} (the Mac may be "
@@ -577,6 +838,12 @@ def _open_and_report(args) -> int:
577
838
  f"spot, so nothing was tapped; {home_note} — open it from its Home Screen icon "
578
839
  "instead (phone_screenshot, then phone_tap)", file=sys.stderr)
579
840
  return 4
841
+ if result == "low_confidence":
842
+ print(f"open_not_confirmed: Spotlight showed {args.app!r} but the label was read with "
843
+ f"confidence {_fmt_confidence(tidy.get('confidence'))}, below "
844
+ f"NORACU_OCR_MIN_CONFIDENCE={_fmt_confidence(tidy.get('min_confidence'))}, so "
845
+ f"nothing was tapped; {home_note}", file=sys.stderr)
846
+ return 4
580
847
  if result == "short_unreadable":
581
848
  print(f"open_not_confirmed: could not read {args.app!r} in Spotlight — OCR often misses a "
582
849
  "one- or two-letter name, in the Top Hit card and in the search field alike, so "
@@ -584,10 +851,27 @@ def _open_and_report(args) -> int:
584
851
  "its Home Screen icon instead (phone_screenshot, then phone_tap)", file=sys.stderr)
585
852
  return 4
586
853
  if result == "not_typed":
587
- print(f"open_not_confirmed: the name {args.app!r} was pasted into Spotlight but never "
854
+ # 0.2.7: the paste may have put the phone's own older clipboard into the field
855
+ # instead of the name — never claim the name was pasted
856
+ print(f"open_not_confirmed: ⌘V was sent to Spotlight but the name {args.app!r} never "
588
857
  "showed up on the phone (a paste can take several seconds to reach the iPhone, "
589
- "or be lost; an iPhone not set to English also needs NORACU_TOPHIT_LABELS) — "
590
- f"nothing was tapped; {home_note}; retry phone_open", file=sys.stderr)
858
+ "or be lost, and the phone may have pasted its own older clipboard into the "
859
+ "search field instead; an iPhone not set to English also needs "
860
+ f"NORACU_TOPHIT_LABELS) — nothing was tapped; {home_note}; retry phone_open, "
861
+ "which clears the search field first", file=sys.stderr)
862
+ return 4
863
+ if result == "focus_lost":
864
+ # 0.2.7: the paste was called off because another app came to the front; no trip
865
+ # Home either — that would pull iPhone Mirroring forward again
866
+ print(f"focus_lost: another app came to the front before ⌘V, so iPhone Mirroring was not "
867
+ f"brought back and {args.app!r} was not pasted or tapped — Spotlight was opened and "
868
+ "cleared on the phone and may still be open; the clipboard was put back unless "
869
+ "something else had copied meanwhile; retry phone_open", file=sys.stderr)
870
+ return 6
871
+ if result == "clipboard_changed":
872
+ print(f"open_not_confirmed: another app or device changed the clipboard before ⌘V, so "
873
+ f"{args.app!r} was not pasted or tapped and the new clipboard was left as it is; "
874
+ f"{home_note}; retry phone_open", file=sys.stderr)
591
875
  return 4
592
876
  if result == "spotlight_unavailable":
593
877
  print("spotlight unavailable (could not reach the Home Screen, the menu command failed, or the screen did not change)")
@@ -595,7 +879,7 @@ def _open_and_report(args) -> int:
595
879
  # "not_confirmed" (F24): the row — and possibly the Top Hit icon —
596
880
  # was tapped but the app never verifiably opened; the phone is
597
881
  # back on the Home Screen.
598
- print(f"open_not_confirmed: tapped {args.app!r} in Spotlight but the app did not open; {home_note}", file=sys.stderr)
882
+ print(f"open_not_confirmed: tapped {args.app!r} in Spotlight{_confidence_note(tidy)} but the app did not open; {home_note}", file=sys.stderr)
599
883
  return 4
600
884
 
601
885
 
@@ -773,6 +1057,14 @@ def main(argv: list[str] | None = None) -> int:
773
1057
  parser = build_parser()
774
1058
  args = parser.parse_args(argv)
775
1059
  _stdin_values(args)
1060
+ pointer.remember() # 0.2.7: a gesture's pointer goes back where it was (see pointer.py)
1061
+ try:
1062
+ return _run(args)
1063
+ finally:
1064
+ pointer.restore()
1065
+
1066
+
1067
+ def _run(args) -> int:
776
1068
  try:
777
1069
  return args.func(args)
778
1070
  except input.KeyboardLayoutMismatch as exc: