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()
+24
View File
@@ -16,6 +16,7 @@ pub(all) enum FaceHit {
Snap
DropSnap(Int)
ToggleFace(String)
UseCamera(String)
Apply
Cancel
} derive(Eq)
@@ -50,6 +51,7 @@ fn ChandraCompositor::face_window_activate(self : ChandraCompositor, h : FaceHit
Snap => f.snap()
DropSnap(i) => f.drop_snap(i)
ToggleFace(id) => f.toggle_remove(id)
UseCamera(path) => f.use_camera(path)
Apply => f.apply()
Cancel => f.cancel_window()
}
@@ -195,6 +197,28 @@ fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.
my = my + fs + 3
}
y = y + bh.max(msg_lines.length() * (fs + 3)) + 14
// The configured camera can't be used: the ones that can, to pick from (saved as root).
if win.ended && win.cameras.length() > 0 {
body.push(@scene.DrawOp::Text(pad, y + 8, "Cameras here", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
y = y + 20
let rh = 34
for c in win.cameras {
let (path, name, why) = c
let bw = @renderer.text_width("Use", fs - 1, false, false) + 32
let br = @scene.Rect::new(pad + inner - bw, y + 3, bw, rh - 6)
let title = if name != "" { name } else { path }
body.push(@scene.DrawOp::Text(pad, y + rh / 2 - 7, title, fs - 1, if why == "" { p.foreground } else { p.foreground_muted }, @scene.TextAlign::Left, why == ""))
let sub = if why == "" { path } else { path + ": " + why }
let sub_lines = wrap_text(sub, fs - 3, false, false, inner - bw - 12)
body.push(@scene.DrawOp::Text(pad, y + rh / 2 + 9, sub_lines[0], fs - 3, p.foreground_muted, @scene.TextAlign::Left, false))
if why == "" {
auth_button(br, "Use", false, false, hover == Some(UseCamera(path)), true, p, fs - 1, rad, body)
hits.push((br, UseCamera(path)))
}
y = y + rh + 4
}
y = y + 8
}
// The snaps: click one to drop it.
if win.snaps.length() > 0 {
body.push(@scene.DrawOp::Text(pad, y + 8, "New pictures (click one to drop it)", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))