Face unlock: say why a camera can't be used, list the cameras, pick one
CI / test (push) Canceled after 21m7s

"no camera at PATH" now says why (not there or a broken link, permission
denied, not a V4L2 device, a metadata node rather than the picture node,
OpenCV couldn't start it or it gives no picture: another app using it) and
lists the cameras found (VIDIOC_QUERYCAP on /dev/v4l/by-id/* and /dev/video*).
New commands: `chandra-face cameras`, `chandra-face set-camera PATH` (root,
edits device in face.conf after checking it is a capture node). The Face
unlock window shows the cameras found with a Use button (one password), then
opens again. just install prints NOT READY with the reason when the
configured camera can't be used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
Claude committed 2026-11-26 04:47:06 +00:00
1 parent ff6f733810
commit 516180196f
7 files changed
+251 -9

No files matched your search

+36
View File
@@ -24,6 +24,12 @@ fn fake_face_tool(dir : String) -> String {
#| # The Face unlock window's camera: a grey 4x3 picture with a face box, a white 2x2
#| # thumbnail per snap, and an apply that changes the faces file.
#| pic() { printf 'frame 4 3 1 0 2 2 36\n'; head -c 36 /dev/zero | tr '\000' '\200'; }
#| if [ -e "$S/nocam" ]; then
#| echo "error no camera at /dev/v4l/by-id/usb-Old-video-index0 (not there: unplugged, or its name differs)"
#| printf 'camera /dev/v4l/by-id/usb-EMEET-video-index0\tEMEET SmartCam C960\t\n'
#| printf 'camera /dev/v4l/by-id/usb-EMEET-video-index1\tEMEET SmartCam C960\tnot a picture node\n'
#| exit 2
#| fi
#| echo "info Look at the camera and press Snap"; pic
#| n=0; kept=0
#| while read -r cmd arg; do
@@ -47,6 +53,8 @@ fn fake_face_tool(dir : String) -> String {
#| quit) exit 0 ;;
#| esac
#| done ;;
#|set-camera)
#| echo "$2" > "$S/camera"; rm -f "$S/nocam"; echo "done Camera: EMEET SmartCam C960" ;;
#|pam)
#| if [ "$2" = enable ]; then echo "polkit-1,sudo" > "$S/pam"; else : > "$S/pam"; fi
#| echo "done ok" ;;
@@ -174,6 +182,34 @@ test "the Face unlock window: live picture, snaps, a face marked for removal, on
comp.close()
}
///|
test "the Face unlock window: a missing camera says why and offers the cameras found" {
let dir = "/tmp/chandra-face-nocam-" + @sys.getpid().to_string()
let tool = fake_face_tool(dir)
ignore(@sys.write_file_bytes(dir + "/nocam", b""))
let comp = new_comp("facenocam")
comp.shell.set_face_tool(["/bin/sh", tool])
assert_true(comp.shell.open_settings(Session))
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Desk") }))
face_click(comp, "Add or remove faces…", 10U)
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.ended).unwrap_or(false) }))
let w = comp.shell.face.window.unwrap()
assert_true(w.error)
assert_true(w.message.has_prefix("no camera at /dev/v4l/by-id/usb-Old-video-index0"))
assert_eq(w.cameras.length(), 2)
assert_eq(w.cameras[1].2, "not a picture node")
let shots = @sys.getenv("CHANDRA_AUTH_SHOTS")
if shots != "" {
ignore(@sys.write_file_bytes(shots + "/19-face-no-camera.png", @renderer.encode_png_compressed(comp.compose_frame())))
}
// "Use" saves it (as root) and opens the window again, now with a picture.
comp.shell.face.use_camera(w.cameras[0].0)
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
assert_eq(@sys.read_file_bytes(dir + "/camera") |> @utf8.decode_lossy, "/dev/v4l/by-id/usb-EMEET-video-index0\n")
comp.shell.face.cancel_window()
comp.close()
}
///|
test "face unlock status lines" {
let f = @shell.FaceUnlock::new()