From 422713ff5377c268d045d2041667f084c93685da Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 5 Jul 2021 12:58:26 +0200 Subject: [PATCH] fix camera selection issues on linux --- .../sparrow/control/QRScanDialog.java | 23 ++++++++++++++++++- .../sparrow/control/WebcamScanDriver.java | 5 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index c4ca7383..4f460931 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -131,6 +131,9 @@ public class QRScanDialog extends Dialog { if(org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.WINDOWS && nested.getMessage().startsWith("Library 'OpenIMAJGrabber' was not loaded successfully from file")) { exception = new WebcamDependencyException("Your system is missing a dependency required for the webcam. Follow the link below for more details.\n\n[https://sparrowwallet.com/docs/faq.html#your-system-is-missing-a-dependency-for-the-webcam]", exception); + } else if(nested.getMessage().startsWith("Cannot start native grabber") && Config.get().getWebcamDevice() != null) { + exception = new WebcamOpenException("Cannot open configured webcam " + Config.get().getWebcamDevice() + ", reverting to the default webcam"); + Config.get().setWebcamDevice(null); } final Throwable result = exception; @@ -597,7 +600,7 @@ public class QRScanDialog extends Dialog { } if(button instanceof Region) { - ((Region)button).setMaxWidth(140); + ((Region)button).setMaxWidth(150); } button.disableProperty().bind(webcamService.openingProperty()); @@ -783,6 +786,24 @@ public class QRScanDialog extends Dialog { } } + public static class WebcamOpenException extends ScanException { + public WebcamOpenException() { + super(); + } + + public WebcamOpenException(String message) { + super(message); + } + + public WebcamOpenException(Throwable cause) { + super(cause); + } + + public WebcamOpenException(String message, Throwable cause) { + super(message, cause); + } + } + public static class ScanDelayCalculator implements WebcamUpdater.DelayCalculator { public long calculateDelay(long snapshotDuration, double deviceFps) { return Math.max(SCAN_PERIOD_MILLIS - snapshotDuration, 0L); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java index 736be43c..79f01166 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java @@ -20,7 +20,10 @@ public class WebcamScanDriver extends WebcamDefaultDriver { List scanDevices = new ArrayList<>(); for(WebcamDevice device : devices) { WebcamDefaultDevice defaultDevice = (WebcamDefaultDevice)device; - scanDevices.add(new WebcamScanDevice(defaultDevice.getDeviceRef())); + WebcamScanDevice scanDevice = new WebcamScanDevice(defaultDevice.getDeviceRef()); + if(scanDevices.stream().noneMatch(dev -> ((WebcamScanDevice)dev).getDeviceName().equals(scanDevice.getDeviceName()))) { + scanDevices.add(scanDevice); + } } List newDevices = new ArrayList<>(scanDevices);