Skip to content

fix(desktop qr): show an error on Linux when the camera can't be opened - #1488

Merged
julian-CStack merged 1 commit into
fix/qr-image-file-decodingfrom
fix/linux-qr-camera-timeout
Nov 3, 2026
Merged

julian-CStack merged 1 commit into
fix/qr-image-file-decodingfrom
fix/linux-qr-camera-timeout

Conversation

@sneurlax

@sneurlax sneurlax commented Nov 1, 2026

Copy link
Copy Markdown
Member

Base: fix/qr-image-file-decoding. Third of three stacked PRs on top of the Windows QR camera fix.

On Linux, opening the QR dialog with no working camera shows a spinner forever instead of an error.

Cause

camera_linux's initializeCamera() only starts a capture thread and never fails. If OpenCV can't open a camera, the thread exits, and captureImage() keeps returning empty frames (or throws on a null frame pointer) indefinitely. The dialog treated a successful initializeCamera() as an open camera and kept polling. Also, the plugin was constructed in a field initializer, and its constructor dlopens libcamera_linux.so, so a missing or broken library threw outside the dialog's error handling.

Change

All in lib/widgets/desktop/qr_code_scanner_dialog.dart:

  • Linux: the plugin is constructed inside _initializeCamera's try, so a library load failure becomes the dialog's normal "unable to open the camera" error.
  • After initializeCamera(), the dialog waits up to 10 seconds for a first non-empty frame. If none arrives, it stops the plugin and shows that error, with the usual pointer to "Select file".
  • While scanning, on every desktop platform, the "camera is not returning images" error now appears after 10 seconds without a usable frame. It used to appear after 20 consecutive exceptions. Empty and undecodable frames count towards the 10 seconds, and any good frame resets it.
  • TimeoutException gets a readable message in the init error.

This only changes when the error appears. Capture and decoding are unchanged.

@sneurlax
sneurlax added this pull request to stack #1487 November 1, 2026 21:03
@sneurlax sneurlax added the bug Something isn't working label Nov 1, 2026
@sneurlax
sneurlax force-pushed the fix/linux-qr-camera-timeout branch from 987df2c to 738f304 Compare November 2, 2026 21:01
@julian-CStack
julian-CStack force-pushed the fix/linux-qr-camera-timeout branch from 738f304 to b3f5e9f Compare November 2, 2026 21:13
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 11.66%. Comparing base (c41b06e) to head (9c21af9).

Files with missing lines Patch % Lines
lib/widgets/desktop/qr_code_scanner_dialog.dart 0.00% 32 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           fix/qr-image-file-decoding    #1488      +/-   ##
==============================================================
- Coverage                       11.66%   11.66%   -0.01%     
==============================================================
  Files                            1136     1136              
  Lines                          114344   114368      +24     
==============================================================
  Hits                            13341    13341              
- Misses                         101003   101027      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

camera_linux's initializeCamera() only starts a capture thread, so with no
camera it succeeds and captureImage() returns empty frames forever, leaving
the dialog spinning. Wait up to 10 s for a first frame and report the camera
as unavailable otherwise. Create the plugin inside the guarded init, since
its constructor throws if libcamera_linux.so can't be loaded. On every
platform, show an error once no usable frame has arrived for 10 s instead
of only after 20 capture exceptions.
@julian-CStack
julian-CStack merged commit cc99e01 into staging Nov 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants