3 name = "lomiri-camera-app-standalone";
4 meta.maintainers = lib.teams.lomiri.members;
9 imports = [ ./common/x11.nix ];
11 services.xserver.enable = true;
17 feh # view photo result
18 ffmpeg # fake webcam stream
19 gnome-text-editor # somewhere to paste QR result
20 (imagemagick.override { ghostscriptSupport = true; }) # add label for OCR
21 qrtool # generate QR code
22 xdotool # clicking on QR button
24 ++ (with pkgs.lomiri; [
29 UITK_ICON_THEME = "suru";
33 i18n.supportedLocales = [ "all" ];
36 packages = with pkgs; [
37 # Intended font & helps with OCR
43 boot.extraModulePackages = with config.boot.kernelPackages; [ v4l2loopback ];
56 with subtest("lomiri camera launches"):
57 machine.succeed("lomiri-camera-app >&2 &")
58 machine.wait_for_text("Cannot access")
59 machine.screenshot("lomiri-camera_open")
61 machine.succeed("pkill -f lomiri-camera-app")
63 # Setup fake v4l2 camera
64 machine.succeed("modprobe v4l2loopback video_nr=10 card_label=Video-Loopback exclusive_caps=1")
65 machine.succeed("qrtool encode '${qrContent}' -s 20 -m 10 > qr.png")
66 # Horizontal flip, add text, flip back. Camera displays image mirrored, so need reversed text for OCR
67 machine.succeed("magick qr.png -flop -pointsize 70 -fill black -annotate +100+100 '${qrLabel}' -flop output.png")
68 machine.succeed("ffmpeg -re -loop 1 -i output.png -vf format=yuv420p -f v4l2 /dev/video10 -loglevel fatal >&2 &")
70 with subtest("lomiri camera uses camera"):
71 machine.succeed("lomiri-camera-app >&2 &")
72 machine.wait_for_text("${qrLabel}")
73 machine.screenshot("lomiri-camera_feed")
75 machine.succeed("xdotool mousemove 320 610 click 1") # take photo
76 machine.wait_until_succeeds("find /root/Pictures/camera.ubports -name '*.jpg'")
78 # Check that the image is correct
79 machine.send_key("ctrl-alt-right")
80 machine.succeed("magick /root/Pictures/camera.ubports/IMG_00000001.jpg -flop photo_flip.png")
81 machine.succeed("feh photo_flip.png >&2 &")
82 machine.wait_for_text("${qrLabel}")
83 machine.screenshot("lomiri-camera_photo")
85 machine.succeed("pkill -f feh")
86 machine.send_key("ctrl-alt-left")
87 machine.succeed("pkill -f lomiri-camera-app")
89 with subtest("lomiri barcode scanner uses camera"):
90 machine.succeed("lomiri-camera-app --mode=barcode-reader >&2 &")
91 machine.wait_for_text("${qrLabel}")
92 machine.succeed("xdotool mousemove 320 610 click 1") # open up QR decode result
94 # OCR is struggling to recognise the text. Click the clipboard button and paste the result somewhere else
96 machine.screenshot("lomiri-barcode_decode")
97 machine.succeed("xdotool mousemove 350 530 click 1")
100 # Need to make a new window without closing camera app, otherwise clipboard content gets lost?
101 machine.send_key("ctrl-alt-right")
102 machine.succeed("gnome-text-editor >&2 &")
103 machine.wait_for_text("New")
105 # Font size up to help with OCR
106 machine.send_key("ctrl-kp_add")
107 machine.send_key("ctrl-kp_add")
108 machine.send_key("ctrl-kp_add")
109 machine.send_key("ctrl-kp_add")
110 machine.send_key("ctrl-kp_add")
111 machine.send_key("ctrl-kp_add")
112 machine.send_key("ctrl-kp_add")
113 machine.send_key("ctrl-kp_add")
114 machine.send_key("ctrl-kp_add")
115 machine.send_key("ctrl-kp_add")
116 machine.send_key("ctrl-kp_add")
117 machine.send_key("ctrl-kp_add")
118 machine.send_key("ctrl-kp_add")
119 machine.send_key("ctrl-kp_add")
120 machine.send_key("ctrl-kp_add")
121 machine.send_key("ctrl-kp_add")
123 machine.send_key("ctrl-v")
124 machine.wait_for_text("${qrContent}")
126 machine.succeed("pkill -f gnome-text-editor")
127 machine.send_key("ctrl-alt-left")
128 machine.succeed("pkill -f lomiri-camera-app")
130 with subtest("lomiri camera localisation works"):
131 machine.succeed("env LANG=de_DE.UTF-8 lomiri-camera-app >&2 &")
132 machine.wait_for_text("Kamera")
133 machine.screenshot("lomiri-camera_localised")