diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 2af5c0cbe..b51b02d37 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -994,6 +994,7 @@ public class Editor extends JFrame implements RunnerListener { try { + String devicesListOutput = Base.getPlatform().preListAllCandidateDevices(); for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();) { CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement(); @@ -1004,7 +1005,7 @@ public class Editor extends JFrame implements RunnerListener { String curr_port = commportidentifier.getName(); String description = curr_port; - String additionalDescription = Base.getPlatform().resolveDeviceAttachedTo(curr_port, Base.packages); + String additionalDescription = Base.getPlatform().resolveDeviceAttachedTo(curr_port, Base.packages, devicesListOutput); if (additionalDescription != null) { description += " (" + additionalDescription + ")"; } diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 83283ca05..834dd68f5 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -136,7 +136,11 @@ public class Platform { } } - public String resolveDeviceAttachedTo(String serial, Map packages) { + public String resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { + return null; + } + + public String preListAllCandidateDevices() { return null; } diff --git a/app/src/processing/app/linux/Platform.java b/app/src/processing/app/linux/Platform.java index f932d67e6..ab1c78c01 100644 --- a/app/src/processing/app/linux/Platform.java +++ b/app/src/processing/app/linux/Platform.java @@ -129,7 +129,7 @@ public class Platform extends processing.app.Platform { } @Override - public String resolveDeviceAttachedTo(String serial, Map packages) { + public String resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Executor executor = new ExternalProcessExecutor(baos); @@ -143,12 +143,12 @@ public class Platform extends processing.app.Platform { String vidPid = new UDevAdmParser().extractVIDAndPID(new String(baos.toByteArray())); if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages); + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); } return super.resolveDeviceByVendorIdProductId(packages, vidPid); } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages); + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); } } } diff --git a/app/src/processing/app/macosx/Platform.java b/app/src/processing/app/macosx/Platform.java index 1ee00696c..eb0d5a663 100644 --- a/app/src/processing/app/macosx/Platform.java +++ b/app/src/processing/app/macosx/Platform.java @@ -205,24 +205,35 @@ public class Platform extends processing.app.Platform { } @Override - public String resolveDeviceAttachedTo(String serial, Map packages) { + public String resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { + if (devicesListOutput == null) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + + try { + String vidPid = new SystemProfilerParser().extractVIDAndPID(devicesListOutput, serial); + + if (vidPid == null) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + + return super.resolveDeviceByVendorIdProductId(packages, vidPid); + } catch (IOException e) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + } + + @Override + public String preListAllCandidateDevices() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Executor executor = new ExternalProcessExecutor(baos); try { CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType"); executor.execute(toDevicePath); - String output = new String(baos.toByteArray()); - - String vidPid = new SystemProfilerParser().extractVIDAndPID(output, serial); - - if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages); - } - - return super.resolveDeviceByVendorIdProductId(packages, vidPid); + return new String(baos.toByteArray()); } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages); + return super.preListAllCandidateDevices(); } } } diff --git a/app/src/processing/app/windows/Platform.java b/app/src/processing/app/windows/Platform.java index 9cac00bda..0c546d225 100644 --- a/app/src/processing/app/windows/Platform.java +++ b/app/src/processing/app/windows/Platform.java @@ -316,7 +316,26 @@ public class Platform extends processing.app.Platform { } @Override - public String resolveDeviceAttachedTo(String serial, Map packages) { + public String resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { + if (devicesListOutput == null) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + + try { + String vidPid = new ListComPortsParser().extractVIDAndPID(devicesListOutput, serial); + + if (vidPid == null) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + + return super.resolveDeviceByVendorIdProductId(packages, vidPid); + } catch (IOException e) { + return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); + } + } + + @Override + public String preListAllCandidateDevices() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Executor executor = new ExternalProcessExecutor(baos); @@ -325,17 +344,9 @@ public class Platform extends processing.app.Platform { CommandLine toDevicePath = CommandLine.parse(listComPorts); executor.execute(toDevicePath); - String vidPid = new ListComPortsParser().extractVIDAndPID(new String(baos.toByteArray()), serial); - - if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages); - } - - return super.resolveDeviceByVendorIdProductId(packages, vidPid); + return new String(baos.toByteArray()); } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages); + return super.preListAllCandidateDevices(); } } - - }