From 2f153686dd2caa65be7446486318e03b02e660b6 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sun, 4 Jul 2021 19:18:02 +0200 Subject: [PATCH] avoid hang on closing webcam due to rescans for new camera devices --- .../sparrow/control/WebcamScanDriver.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java index ca25239a..e31b3f66 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamScanDriver.java @@ -8,15 +8,21 @@ import java.util.ArrayList; import java.util.List; public class WebcamScanDriver extends WebcamDefaultDriver { + private List foundScanDevices; + @Override public List getDevices() { - List devices = super.getDevices(); - List scanDevices = new ArrayList<>(); - for(WebcamDevice device : devices) { - WebcamDefaultDevice defaultDevice = (WebcamDefaultDevice)device; - scanDevices.add(new WebcamScanDevice(defaultDevice.getDeviceRef())); + if(foundScanDevices == null || foundScanDevices.isEmpty()) { + List devices = super.getDevices(); + List scanDevices = new ArrayList<>(); + for(WebcamDevice device : devices) { + WebcamDefaultDevice defaultDevice = (WebcamDefaultDevice)device; + scanDevices.add(new WebcamScanDevice(defaultDevice.getDeviceRef())); + } + + foundScanDevices = scanDevices; } - return scanDevices; + return foundScanDevices; } }