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

+30
View File
@@ -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.