Face unlock: say why a camera can't be used, list the cameras, pick one
CI / test (push) Canceled after 21m7s
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:
7 files changed
+251
-9
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -39,6 +39,8 @@ pub(all) struct FaceUnlock {
|
||||
mut loaded : Bool
|
||||
mut dirty : Bool
|
||||
/// The Face unlock window, while it is open, and a count of its changes (the host redraws).
|
||||
/// `reopen`: open it again when the running change (set-camera) ends.
|
||||
mut reopen : Bool
|
||||
mut window : FaceWindow?
|
||||
mut window_rev : Int
|
||||
/// Image handles to reuse for the live picture (two, in turn, so a new picture is a changed
|
||||
@@ -75,6 +77,9 @@ pub(all) struct FaceWindow {
|
||||
mut applying : Bool
|
||||
/// When the camera process ended without a picture: the window shows why.
|
||||
mut ended : Bool
|
||||
/// The cameras chandra-face found when the configured one can't be used: (path, name, why
|
||||
/// not; empty when it takes pictures). The window offers the usable ones.
|
||||
cameras : Array[(String, String, String)]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -103,6 +108,7 @@ pub fn FaceUnlock::new() -> FaceUnlock {
|
||||
queue: [],
|
||||
loaded: false,
|
||||
dirty: true,
|
||||
reopen: false,
|
||||
window: None,
|
||||
window_rev: 0,
|
||||
pics: [],
|
||||
@@ -222,6 +228,10 @@ pub fn FaceUnlock::poll(self : FaceUnlock) -> Unit {
|
||||
self.change = false
|
||||
self.dirty = true
|
||||
self.refresh()
|
||||
if self.reopen {
|
||||
self.reopen = false
|
||||
self.open_window(None)
|
||||
}
|
||||
} else {
|
||||
self.apply_status(self.lines)
|
||||
}
|
||||
@@ -365,6 +375,7 @@ pub fn FaceUnlock::open_window(self : FaceUnlock, mark : String?) -> Unit {
|
||||
error: false,
|
||||
applying: false,
|
||||
ended: fd < 0,
|
||||
cameras: [],
|
||||
}
|
||||
if fd < 0 {
|
||||
w.message = "Couldn't run chandra-face"
|
||||
@@ -425,6 +436,19 @@ pub fn FaceUnlock::toggle_remove(self : FaceUnlock, id : String) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///| Use the camera at `path` from now on (root: one password), then open the window again.
|
||||
pub fn FaceUnlock::use_camera(self : FaceUnlock, path : String) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if w.ended => {
|
||||
self.close_window()
|
||||
self.message = "Waiting for the password…"
|
||||
self.reopen = true
|
||||
self.run(["set-camera", path], true)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether Apply has anything to do.
|
||||
pub fn FaceWindow::can_apply(self : FaceWindow) -> Bool {
|
||||
!self.applying && self.fd >= 0 && (self.snaps.length() > 0 || self.remove.length() > 0)
|
||||
@@ -573,6 +597,12 @@ fn FaceUnlock::window_line(self : FaceUnlock, w : FaceWindow, kind : String, tex
|
||||
w.message = text
|
||||
w.error = true
|
||||
}
|
||||
"camera" => {
|
||||
let f = text.split("\t").map(s => s.to_string()).to_array()
|
||||
if f.length() == 3 {
|
||||
w.cameras.push((f[0], f[1], f[2]))
|
||||
}
|
||||
}
|
||||
"applied" =>
|
||||
if text != "0" {
|
||||
// Refused or cancelled: the camera starts again, the snaps and marks are still there.
|
||||
|
||||
Reference in new issue
Block a user