Skip to content

Commit

Permalink
update usb library, fix electron target downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
freshollie committed Dec 16, 2021
1 parent 4ffe8b8 commit 855703f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 60 deletions.
15 changes: 15 additions & 0 deletions .yarn/patches/usb-npm-2.0.3-20d40266b6
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/dist/usb/bindings.js b/dist/usb/bindings.js
index a80a550c29a45ff7ab2231c903da3c7ddc23be21..6c05c970ee9c35aa68e752d28ba9156233939dfa 100644
--- a/dist/usb/bindings.js
+++ b/dist/usb/bindings.js
@@ -3,8 +3,7 @@
// Eric Brody <https://github.com/underscorebrody>
// Rob Moran <https://github.com/thegecko>
Object.defineProperty(exports, "__esModule", { value: true });
-var path_1 = require("path");
/* eslint-disable @typescript-eslint/no-var-requires */
-var usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
+var usb = require('node-gyp-build')(__dirname + '/../..');
module.exports = usb;
//# sourceMappingURL=bindings.js.map
\ No newline at end of file
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "edgetx-buddy",
"version": "0.1.0",
"private": true,
"license": "MIT",
"main": "./build/main/main.js",
"build": {
"productName": "EdgeTX Buddy",
Expand Down Expand Up @@ -50,7 +51,6 @@
"@mui/icons-material": "^5.1.1",
"@mui/material": "^5.1.1",
"@octokit/core": "^3.5.1",
"abort-controller": "^3.0.0",
"antd": "^4.17.2",
"apollo-bus-link": "^0.4.4",
"apollo-link-logger": "^2.0.0",
Expand All @@ -76,10 +76,9 @@
"styled-components": "^5.3.3",
"type-guards": "^0.15.0",
"unzipit": "^1.3.6",
"usb": "^1.9.2",
"usb": "2.0.3",
"uuid": "^8.3.2",
"web-streams-polyfill": "^3.2.0",
"webusb": "^2.2.0"
"web-streams-polyfill": "^3.2.0"
},
"scripts": {
"start": "yarn compile:main && yarn start:renderer",
Expand Down Expand Up @@ -195,6 +194,7 @@
"workerloader-jest-transformer": "^0.0.5"
},
"resolutions": {
"@graphql-codegen/[email protected]": "patch:@graphql-codegen/cli@npm:2.3.0#.yarn/patches/@graphql-codegen-cli-npm-2.3.0-4b6eb70c79"
"@graphql-codegen/[email protected]": "patch:@graphql-codegen/cli@npm:2.3.0#.yarn/patches/@graphql-codegen-cli-npm-2.3.0-4b6eb70c79",
"[email protected]": "patch:usb@npm:2.0.3#.yarn/patches/usb-npm-2.0.3-20d40266b6"
}
}
22 changes: 5 additions & 17 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
import { electronBus } from "apollo-bus-link/electron";
import getOriginPrivateDirectory from "native-file-system-adapter/src/getOriginPrivateDirectory";
import nodeAdapter from "native-file-system-adapter/src/adapters/node";
import { USB } from "webusb";
import { Device as NativeUSBDevice } from "usb";
import { WebUSB } from "usb";
import * as backend from "shared/backend";
import type { FileSystemApi, UsbApi } from "shared/backend";
import config from "shared/config";
Expand Down Expand Up @@ -141,25 +140,14 @@ if (process.platform === "win32") {

const usbApi = (): UsbApi => {
// Some operations can take longer for stem boards
NativeUSBDevice.prototype.timeout = 60000;
let availableDevices: USBDevice[] = [];

const usb = new USB({
devicesFound: (devices) => {
availableDevices = devices;
return Promise.resolve(undefined);
},
const usb = new WebUSB({
deviceTimeout: 60000,
allowAllDevices: true,
});

return {
requestDevice: usb.requestDevice.bind(usb),
deviceList: async () => {
// No device will be returned, so ignore errors from this
await usb
.requestDevice({ filters: [{ vendorId: 0x483 }] })
.catch(() => {});
return availableDevices;
},
deviceList: async () => usb.getDevices(),
};
};

Expand Down
6 changes: 4 additions & 2 deletions src/shared/backend/utils/ZipHTTPRangeReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export default class ZipHTTPRangeReader implements Reader {
if (this.length === undefined) {
const req = await ky(this.url, {
method: "HEAD",
prefixUrl: config.proxyUrl,
prefixUrl: !config.isMain ? config.proxyUrl : undefined,
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
"user-agent": fakeUserAgent,
Referer: "https://github.com/",
},
Expand All @@ -49,11 +50,12 @@ export default class ZipHTTPRangeReader implements Reader {
return new Uint8Array(0);
}
const req = await ky(this.url, {
prefixUrl: config.proxyUrl,
prefixUrl: !config.isMain ? config.proxyUrl : undefined,
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
Range: `bytes=${offset}-${offset + size - 1}`,
"user-agent": fakeUserAgent,
Referer: "https://github.com/",
Expand Down
2 changes: 1 addition & 1 deletion src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const extractParam = (key: string): string | null =>
export default {
isMain,
isElectron,
proxyUrl: isElectron ? "" : process.env.PROXY_URL ?? "",
proxyUrl: process.env.PROXY_URL,
isProduction: PRODUCTION,
isE2e: E2E,
github: {
Expand Down
53 changes: 18 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5258,13 +5258,6 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^8.0.54":
version: 8.10.66
resolution: "@types/node@npm:8.10.66"
checksum: c52039de862654a139abdc6a51de532a69dd80516ac35a959c3b3a2831ecbaaf065b0df5f9db943f5e28b544ebb9a891730d52b52f7a169b86a82bc060210000
languageName: node
linkType: hard

"@types/normalize-package-data@npm:^2.4.0":
version: 2.4.1
resolution: "@types/normalize-package-data@npm:2.4.1"
Expand Down Expand Up @@ -5479,15 +5472,6 @@ __metadata:
languageName: node
linkType: hard

"@types/usb@npm:^1.5.1":
version: 1.5.4
resolution: "@types/usb@npm:1.5.4"
dependencies:
"@types/node": "*"
checksum: 6004717c1c31f335531ed7bf60f1b0a1e748c98c143de73497f2682e44afe9624bf8714013e98f46cdc343d0aea6cde90420319a19aa81b027f3d28e400fbd13
languageName: node
linkType: hard

"@types/uuid@npm:^8.3.3":
version: 8.3.3
resolution: "@types/uuid@npm:8.3.3"
Expand Down Expand Up @@ -10316,7 +10300,6 @@ __metadata:
"@types/wicg-file-system-access": ^2020.9.4
"@typescript-eslint/eslint-plugin": ^5.6.0
"@typescript-eslint/parser": ^5.6.0
abort-controller: ^3.0.0
antd: ^4.17.2
apollo-bus-link: ^0.4.4
apollo-link-logger: ^2.0.0
Expand Down Expand Up @@ -10383,15 +10366,14 @@ __metadata:
type-guards: ^0.15.0
typescript: ^4.5.2
unzipit: ^1.3.6
usb: ^1.9.2
usb: 2.0.3
uuid: ^8.3.2
web-streams-polyfill: ^3.2.0
webpack: ^5.64.4
webpack-bundle-analyzer: ^4.5.0
webpack-cli: ^4.9.1
webpack-dev-server: ^4.6.0
webpackbar: ^5.0.2
webusb: ^2.2.0
workerloader-jest-transformer: ^0.0.5
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -23250,14 +23232,27 @@ __metadata:
languageName: node
linkType: hard

"usb@npm:^1.6.0, usb@npm:^1.9.2":
version: 1.9.2
resolution: "usb@npm:1.9.2"
"usb@npm:2.0.3":
version: 2.0.3
resolution: "usb@npm:2.0.3"
dependencies:
"@types/w3c-web-usb": ^1.0.4
node-addon-api: ^4.2.0
node-gyp: latest
node-gyp-build: ^4.3.0
checksum: df8c15a64174a30da98e15c364e7632a4bf18cb0bb0ee8319e8793b4982cd419ce1aa125d4223afa150e69a088025bfefa7e9f85a67a7d2c69d71de9c9b5681f
languageName: node
linkType: hard

"usb@patch:usb@npm:2.0.3#.yarn/patches/usb-npm-2.0.3-20d40266b6::locator=edgetx-buddy%40workspace%3A.":
version: 2.0.3
resolution: "usb@patch:usb@npm%3A2.0.3#.yarn/patches/usb-npm-2.0.3-20d40266b6::version=2.0.3&hash=bf06d4&locator=edgetx-buddy%40workspace%3A."
dependencies:
"@types/w3c-web-usb": ^1.0.4
node-addon-api: ^4.2.0
node-gyp: latest
node-gyp-build: ^4.3.0
checksum: 7aaf6669f02c6f4bebe571de1c364447ca44be4dc8c60fc3261f38660e04015099ebed3943935ad64755afccd11213245d697ea05571a2f142d912bb801bb54f
checksum: 75f2e9dac80c969d7bd6bf64f6b045fdcf274e71122ecf53ba8c044db8ca2a946723685cfcca90b0a474e75008920a79b14299beaa5ac8ca866e7fb8e1287616
languageName: node
linkType: hard

Expand Down Expand Up @@ -24002,18 +23997,6 @@ __metadata:
languageName: node
linkType: hard

"webusb@npm:^2.2.0":
version: 2.2.0
resolution: "webusb@npm:2.2.0"
dependencies:
"@types/node": ^8.0.54
"@types/usb": ^1.5.1
"@types/w3c-web-usb": ^1.0.4
usb: ^1.6.0
checksum: 020ae79966c194eef00cbaeafbbf2f52a644413d0ca72e448e833a3993c4d02234f232efade03f5e3f5df2c709fe564eabeed3697e9cadc7869201bbd8b47f30
languageName: node
linkType: hard

"whatwg-encoding@npm:^1.0.5":
version: 1.0.5
resolution: "whatwg-encoding@npm:1.0.5"
Expand Down

0 comments on commit 855703f

Please sign in to comment.