Skip to content

Commit

Permalink
- Fixed usb-barcode when disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
fchienvuhoang committed Feb 18, 2020
1 parent 74b78ce commit 900865c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
13 changes: 9 additions & 4 deletions app/components/Account/ConnectDevices/ConnectDevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ class ConnectDevices extends Component<Props> {
</div>
<div className="form-group">
{errorConnect ? (
<p className="text-danger">
Error connect to device, please run this application
with root permission
</p>
<>
<p className="text-danger">
Error connect to device, please try the following:
</p>
<ul>
<li>Run app with root permission</li>
<li>Remove and re-plug the device</li>
</ul>
</>
) : (
<p></p>
)}
Expand Down
8 changes: 8 additions & 0 deletions app/reducers/db/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ export async function updateLoggedToken(payload) {
const tbl = db.table(table);
await tbl.update(id, { value: payload.value, update_at: new Date() });
}

export async function deleteByKeyV2(key) {
const tbl = db.table(table);
await tbl
.where('key')
.equals(key)
.delete();
}
20 changes: 4 additions & 16 deletions app/sagas/rootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
createConnectedDeviceSettings,
createSyncAllDataFlag,
haveToSyncAllData,
getConnectedDeviceSettings
getConnectedDeviceSettings,
removeScannerDeviceConnected
} from './services/SettingsService';
import {
getInfoCashierService,
Expand Down Expand Up @@ -1082,8 +1083,6 @@ function* connectToScannerDeviceSaga(payload) {
const allDevicesResult = yield select(allDevices);
const deviceSelected = allDevicesResult[index];

console.log('device selected:', deviceSelected);

const { vendorId, productId } = deviceSelected;

yield connectHIDScanner(vendorId, productId, deviceSelected);
Expand Down Expand Up @@ -1116,19 +1115,8 @@ function* connectHIDScanner(vendorId, productId, deviceSelected) {

function* changeScannerDeviceSaga() {
try {
const scannerConnectedSettings = yield getConnectedDeviceSettings();
console.log('scanner1:', window.scanner);
console.log('scanner2:', window.scanner.hid.getDeviceInfo());
if (scannerConnectedSettings) {
// const { vendorId, productId } = scannerConnectedSettings;
// // Close if exists connected
// const scanner = new UsbScanner({
// vendorId,
// productId
// });
//
// console.log('scanner change:', scanner);
}
// Remove scanner device
yield removeScannerDeviceConnected();
} catch (e) {
console.error('change scanner device error:', e);
}
Expand Down
7 changes: 6 additions & 1 deletion app/sagas/services/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
createKey,
getByKey,
getByKeyV2,
updateById
updateById,
deleteByKeyV2
} from '../../reducers/db/settings';

const syncAllDataLabel = 'sync_all_data';
Expand Down Expand Up @@ -113,3 +114,7 @@ export async function getConnectedDeviceSettings() {
const data = await getByKeyV2(connectedScannerDeviceLabel);
return data ? data.value : '';
}

export async function removeScannerDeviceConnected() {
await deleteByKeyV2(connectedScannerDeviceLabel);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
"locale-currency": "^0.0.2",
"lodash": "^4.17.15",
"node-hid": "^1.2.0",
"usb-barcode-scanner-brainos": "^1.0.3",
"usb-barcode-scanner-brainos": "^1.0.6",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13794,10 +13794,10 @@ url@^0.11.0, url@~0.11.0:
punycode "1.3.2"
querystring "0.2.0"

usb-barcode-scanner-brainos@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/usb-barcode-scanner-brainos/-/usb-barcode-scanner-brainos-1.0.3.tgz#aab61cc631eed30e3aa9cf5a10167800c07115bc"
integrity sha512-HnyYdX1c/UWmegGPZTJhMMih6GDgnuAe7DBc6ExWPpNhRpi6Igy2lczefL0A5lo/67tRsroofUD+fFmbgY6D3g==
usb-barcode-scanner-brainos@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/usb-barcode-scanner-brainos/-/usb-barcode-scanner-brainos-1.0.6.tgz#22646416de997825da42ef97555063461ae3f678"
integrity sha512-sQcxI+u6pAXNZpn88O9nZzyCZJvUQDtNVwiij1+ko+CQYc2aqM4Wqu1vA7rMs7bbspzvjYAyZzJk9hPOIw78fQ==
dependencies:
"@types/lodash" "^4.14.108"
"@types/node-hid" "^1.2.0"
Expand Down

0 comments on commit 900865c

Please sign in to comment.