Skip to content

Commit

Permalink
Merge pull request #1540 from tidepool-org/manufacturer-cable
Browse files Browse the repository at this point in the history
Prioritize manufacturer cable over alternative cable when both are connected (UPLOAD-923)
  • Loading branch information
gniezen authored Mar 7, 2023
2 parents 6d30956 + 8ada166 commit 84b48cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/actions/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import semver from 'semver';
import os from 'os';
import { push } from 'connected-react-router';
import { checkCacheValid } from 'redux-cache';
import { ipcRenderer } from 'electron';

import * as actionTypes from '../constants/actionTypes';
import * as actionSources from '../constants/actionSources';
Expand Down Expand Up @@ -379,6 +380,7 @@ export function doUpload(deviceKey, opts, utc) {
}));

try {
ipcRenderer.send('setSerialPortFilter', filters);
opts.port = await navigator.serial.requestPort({ filters: filters });
} catch (err) {
// not returning error, as we'll attempt user-space driver instead
Expand Down
18 changes: 17 additions & 1 deletion app/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const baseURL = `file://${__dirname}/app.html`;
let menu;
let template;
let mainWindow = null;
let serialPortFilter = null;

// Web Bluetooth should only be an experimental feature on Linux
app.commandLine.appendSwitch('enable-experimental-web-platform-features', true);
Expand Down Expand Up @@ -272,7 +273,18 @@ operating system, as soon as possible.`,
mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
event.preventDefault();
console.log('Port list:', portList);
const [selectedPort] = portList;

let selectedPort;
for (let i = 0; i < serialPortFilter.length; i++) {
selectedPort = portList.find((element) =>
serialPortFilter[i].usbVendorId === parseInt(element.vendorId, 10) &&
serialPortFilter[i].usbProductId === parseInt(element.productId, 10)
);
if (selectedPort) {
break; // prioritize according to the order in the driver manifest
}
}

if (!selectedPort) {
callback('');
} else {
Expand Down Expand Up @@ -613,6 +625,10 @@ ipcMain.on('autoUpdater', (event, arg) => {
autoUpdater[arg]();
});

ipcMain.on('setSerialPortFilter', (event, arg) => {
serialPortFilter = arg;
});

if(!app.isDefaultProtocolClient('tidepoolupload')){
app.setAsDefaultProtocolClient('tidepoolupload');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/driverManifests.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ const driverManifests = {
OneTouchUltraMini: {
mode: 'serial',
usb: [
{ vendorId: 1659, productId: 8963, driver: 'pl2303' },
{ vendorId: 1027, productId: 24577, driver: 'ftdi' }, // FTDI cable
{ vendorId: 1659, productId: 8963, driver: 'pl2303' },
{ vendorId: 6790, productId: 29987 }, // CH340 cable
],
},
Expand All @@ -138,8 +138,8 @@ const driverManifests = {
sendTimeout: 5000,
receiveTimeout: 5000,
usb: [
{ vendorId: 1659, productId: 8963, driver: 'pl2303' },
{ vendorId: 1027, productId: 24577, driver: 'ftdi' }, // FTDI cable
{ vendorId: 1659, productId: 8963, driver: 'pl2303' },
{ vendorId: 6790, productId: 29987 }, // CH340 cable
],
},
Expand Down

0 comments on commit 84b48cd

Please sign in to comment.