From 8caf5e4b4fdf786a34cdc1ecf71945ce7fb28c88 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 25 May 2026 20:28:22 +0200 Subject: [PATCH] Fix screenrecording webcam selector --- ...marchy-capture-screenrecording-with-webcam | 11 ++- test/shell.d/screenrecording-test.sh | 78 +++++++++++++++++++ 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 test/shell.d/screenrecording-test.sh diff --git a/bin/omarchy-capture-screenrecording-with-webcam b/bin/omarchy-capture-screenrecording-with-webcam index 6d3825a4..fb35cb8e 100755 --- a/bin/omarchy-capture-screenrecording-with-webcam +++ b/bin/omarchy-capture-screenrecording-with-webcam @@ -17,17 +17,16 @@ webcam_list() { done } -devices=$(webcam_list) -if [[ -z $devices ]]; then +mapfile -t devices < <(webcam_list) +if (( ${#devices[@]} == 0 )); then omarchy-notification-send "No webcam devices found" -u critical -t 3000 exit 1 fi -count=$(grep -c . <<<"$devices") -if (( count == 1 )); then - device="${devices%%[[:space:]]*}" +if (( ${#devices[@]} == 1 )); then + device="${devices[0]%%[[:space:]]*}" else - selection=$(omarchy-menu-select "Select Webcam" "$devices") || exit 1 + selection=$(omarchy-menu-select "Select Webcam" "${devices[@]}" -- --width 520 --maxheight 520) || exit 1 device="${selection%%[[:space:]]*}" fi diff --git a/test/shell.d/screenrecording-test.sh b/test/shell.d/screenrecording-test.sh new file mode 100644 index 00000000..93d5bc94 --- /dev/null +++ b/test/shell.d/screenrecording-test.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "$0")/base-test.sh" + +tmp_dir=$(mktemp -d) +trap 'rm -rf "$tmp_dir"' EXIT + +stub_bin="$tmp_dir/bin" +mkdir -p "$stub_bin" + +cat >"$stub_bin/v4l2-ctl" <<'SH' +#!/bin/bash + +printf '%s\n' "Built-in Webcam: Integrated Camera" +printf '\t%s\n' "/dev/video0" +printf '\t%s\n' "/dev/video1" +printf '\n' +printf '%s\n' "USB Capture Card: External Camera" +printf '\t%s\n' "/dev/video2" +SH + +cat >"$stub_bin/omarchy-menu-select" <<'SH' +#!/bin/bash + +printf '%s\n' "$@" >"$OMARCHY_TEST_MENU_ARGS" +printf '%s\n' "$3" +SH + +cat >"$stub_bin/omarchy-capture-screenrecording" <<'SH' +#!/bin/bash + +printf '%s\n' "$@" >"$OMARCHY_TEST_RECORDER_ARGS" +SH + +cat >"$stub_bin/omarchy-notification-send" <<'SH' +#!/bin/bash + +printf '%s\n' "$@" >"$OMARCHY_TEST_NOTIFICATION_ARGS" +SH + +chmod +x "$stub_bin"/* + +export PATH="$stub_bin:$ROOT/bin:$PATH" +export OMARCHY_TEST_MENU_ARGS="$tmp_dir/menu-args" +export OMARCHY_TEST_RECORDER_ARGS="$tmp_dir/recorder-args" +export OMARCHY_TEST_NOTIFICATION_ARGS="$tmp_dir/notification-args" + +"$ROOT/bin/omarchy-capture-screenrecording-with-webcam" + +expected_menu_args="$tmp_dir/expected-menu-args" +printf '%s\n' \ + "Select Webcam" \ + "/dev/video0 Built-in Webcam: Integrated Camera" \ + "/dev/video2 USB Capture Card: External Camera" \ + "--" \ + "--width" \ + "520" \ + "--maxheight" \ + "520" >"$expected_menu_args" + +if ! cmp -s "$OMARCHY_TEST_MENU_ARGS" "$expected_menu_args"; then + fail "screenrecording webcam picker passes each webcam as a menu option" "$(diff -u "$expected_menu_args" "$OMARCHY_TEST_MENU_ARGS")" +fi +pass "screenrecording webcam picker passes each webcam as a menu option" + +expected_recorder_args="$tmp_dir/expected-recorder-args" +printf '%s\n' \ + "--with-desktop-audio" \ + "--with-microphone-audio" \ + "--with-webcam" \ + "--webcam-device=/dev/video2" >"$expected_recorder_args" + +if ! cmp -s "$OMARCHY_TEST_RECORDER_ARGS" "$expected_recorder_args"; then + fail "screenrecording webcam picker starts recording with selected device" "$(diff -u "$expected_recorder_args" "$OMARCHY_TEST_RECORDER_ARGS")" +fi +pass "screenrecording webcam picker starts recording with selected device"