refactor: drop bluebird dependency (#3279)

master
Tomas Chmelevskij 2023-02-03 15:50:22 +01:00 committed by GitHub
parent 3c8ad50005
commit 293ca70077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 54 deletions

View File

@ -53,7 +53,6 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.13.0", "@fortawesome/fontawesome-free": "^5.13.0",
"@panter/vue-i18next": "^0.15.2", "@panter/vue-i18next": "^0.15.2",
"bluebird": "^3.7.2",
"bonjour": "^3.5.0", "bonjour": "^3.5.0",
"crypto-es": "^1.2.7", "crypto-es": "^1.2.7",
"d3": "^7.8.2", "d3": "^7.8.2",

View File

@ -111,24 +111,27 @@ cli.initialize = function (callback) {
self.history.add(outString.trim()); self.history.add(outString.trim());
const outputArray = outString.split("\n"); const outputArray = outString.split("\n");
return Promise.reduce(outputArray, function(delay, line, index) { return outputArray.reduce((p, line, index) =>
return new Promise(function (resolve) { p.then((delay) =>
GUI.timeout_add('CLI_send_slowly', function () { new Promise((resolve) => {
let processingDelay = self.lineDelayMs; GUI.timeout_add('CLI_send_slowly', function () {
line = line.trim(); let processingDelay = self.lineDelayMs;
if (line.toLowerCase().startsWith('profile')) { line = line.trim();
processingDelay = self.profileSwitchDelayMs; if (line.toLowerCase().startsWith('profile')) {
} processingDelay = self.profileSwitchDelayMs;
const isLastCommand = outputArray.length === index + 1; }
if (isLastCommand && self.cliBuffer) { const isLastCommand = outputArray.length === index + 1;
line = getCliCommand(line, self.cliBuffer); if (isLastCommand && self.cliBuffer) {
} line = getCliCommand(line, self.cliBuffer);
self.sendLine(line, function () { }
resolve(processingDelay); self.sendLine(line, function () {
}); resolve(processingDelay);
}, delay); });
}); }, delay);
}, 0); }),
),
Promise.resolve(0),
);
} }
$('#content').load("./tabs/cli.html", function () { $('#content').load("./tabs/cli.html", function () {

View File

@ -254,10 +254,18 @@ FONT.msp = {
}; };
FONT.upload = function($progress) { FONT.upload = function($progress) {
return Promise.mapSeries(FONT.data.characters, function(data, i) { return FONT.data.characters
$progress.val((i / FONT.data.characters.length) * 100); .reduce(
return MSP.promise(MSPCodes.MSP_OSD_CHAR_WRITE, FONT.msp.encode(i)); (p, x, i) =>
}) p.then(() => {
$progress.val((i / FONT.data.characters.length) * 100);
return MSP.promise(
MSPCodes.MSP_OSD_CHAR_WRITE,
FONT.msp.encode(i),
);
}),
Promise.resolve(),
)
.then(function() { .then(function() {
console.log(`Uploaded all ${FONT.data.characters.length} characters`); console.log(`Uploaded all ${FONT.data.characters.length} characters`);

View File

@ -61,7 +61,6 @@
<script type="text/javascript" src="./node_modules/jquery-ui-npm/jquery-ui.min.js"></script> <script type="text/javascript" src="./node_modules/jquery-ui-npm/jquery-ui.min.js"></script>
<script type="text/javascript" src="./js/libraries/jquery.nouislider.all.min.js"></script> <script type="text/javascript" src="./js/libraries/jquery.nouislider.all.min.js"></script>
<script type="text/javascript" src="./js/libraries/jquery.flightindicators.js"></script> <script type="text/javascript" src="./js/libraries/jquery.flightindicators.js"></script>
<script type="text/javascript" src="./node_modules/bluebird/js/browser/bluebird.min.js"></script>
<script type="text/javascript" src="./node_modules/jquery-textcomplete/dist/jquery.textcomplete.min.js"></script> <script type="text/javascript" src="./node_modules/jquery-textcomplete/dist/jquery.textcomplete.min.js"></script>
<script type="text/javascript" src="./node_modules/jquery-touchswipe/jquery.touchSwipe.min.js"></script> <script type="text/javascript" src="./node_modules/jquery-touchswipe/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="./node_modules/select2/dist/js/select2.min.js"></script> <script type="text/javascript" src="./node_modules/select2/dist/js/select2.min.js"></script>

View File

@ -88,29 +88,32 @@ export default class CliEngine
this._reportSendCommandsProgress(0); this._reportSendCommandsProgress(0);
const totalCommandsCount = strings.length; const totalCommandsCount = strings.length;
return Promise.reduce(strings, (delay, line, index) => { return strings.reduce(strings, (p, line, index) =>
return new Promise((resolve) => { p.then((delay) =>
GUI.timeout_add('CLI_send_slowly', () => { new Promise((resolve) => {
let processingDelay = this.lineDelayMs; GUI.timeout_add('CLI_send_slowly', () => {
line = line.trim(); let processingDelay = this.lineDelayMs;
line = line.trim();
if (line.toLowerCase().startsWith('profile')) { if (line.toLowerCase().startsWith('profile')) {
processingDelay = this.profileSwitchDelayMs; processingDelay = this.profileSwitchDelayMs;
} }
const isLastCommand = totalCommandsCount === index + 1; const isLastCommand = totalCommandsCount === index + 1;
if (isLastCommand && this.cliBuffer) { if (isLastCommand && this.cliBuffer) {
line = this.getCliCommand(line, this.cliBuffer); line = this.getCliCommand(line, this.cliBuffer);
} }
this.sendLine(line, ()=>{ /* empty on-send callback */ }, () => { this.sendLine(line, () => { /* empty on-send callback */ }, () => {
resolve(processingDelay); resolve(processingDelay);
this._reportSendCommandsProgress(100.0 * index / totalCommandsCount); this._reportSendCommandsProgress(100.0 * index / totalCommandsCount);
}); });
}, delay); }, delay);
}); }),
}, 0).then(() => { ),
Promise.resolve(0),
).then(() => {
this._reportSendCommandsProgress(100); this._reportSendCommandsProgress(100);
}); });
} }

View File

@ -66,7 +66,7 @@ export default class PresetsRepoIndexed {
return this._executeIncludeOnce(strings) return this._executeIncludeOnce(strings)
.then(resultStrings => this._executeIncludeNested(resultStrings)); .then(resultStrings => this._executeIncludeNested(resultStrings));
} else { } else {
return new Promise.resolve(strings); return Promise.resolve(strings);
} }
} }

View File

@ -1,4 +1,3 @@
import "bluebird";
import { JSDOM } from "jsdom"; import { JSDOM } from "jsdom";
import $ from "jquery"; import $ from "jquery";
import { vi } from "vitest"; import { vi } from "vitest";

View File

@ -1,4 +1,3 @@
import { Promise } from "bluebird";
import { import {
describe, describe,
it, it,
@ -88,7 +87,7 @@ describe("cli", () => {
cli.cliBuffer = "se"; cli.cliBuffer = "se";
cli.read({ cli.read({
data: toArrayBuffer( data: toArrayBuffer(
"\r\x1B[Kserialpassthrough\tservo\r\n# ser" "\r\x1B[Kserialpassthrough\tservo\r\n# ser",
), ),
}); });
// Ambigous auto-complete from firmware is preceded with an \r carriage return // Ambigous auto-complete from firmware is preceded with an \r carriage return
@ -153,11 +152,7 @@ describe("cli", () => {
send: () => {}, send: () => {},
}; };
}); });
vi.spyOn(Promise, "reduce").mockImplementation((items, cb) => {
items.forEach((line, idx) => cb(0, line, idx));
});
vi.spyOn(Promise, "Promise").mockResolvedValue(0);
vi.spyOn(GUI, "timeout_add").mockImplementation((name, cb) => { vi.spyOn(GUI, "timeout_add").mockImplementation((name, cb) => {
cb(); cb();
}); });
@ -222,7 +217,7 @@ describe("cli", () => {
expect(cli.send).toHaveBeenCalledOnce(); expect(cli.send).toHaveBeenCalledOnce();
expect(cli.send).toHaveBeenCalledWith( expect(cli.send).toHaveBeenCalledWith(
`${backspaceCode.repeat(3)}\t` `${backspaceCode.repeat(3)}\t`,
); );
done(); done();
}); });
@ -266,7 +261,7 @@ describe("cli", () => {
expect(cli.send).toHaveBeenCalledOnce(); expect(cli.send).toHaveBeenCalledOnce();
expect(cli.send).toHaveBeenCalledWith( expect(cli.send).toHaveBeenCalledWith(
`${backspaceCode.repeat(3)}\n` `${backspaceCode.repeat(3)}\n`,
); );
done(); done();
}); });

View File

@ -4282,7 +4282,7 @@ bl@^4.0.3:
inherits "^2.0.4" inherits "^2.0.4"
readable-stream "^3.4.0" readable-stream "^3.4.0"
bluebird@^3.1.1, bluebird@^3.3.5, bluebird@^3.5.5, bluebird@^3.7.2: bluebird@^3.1.1, bluebird@^3.3.5, bluebird@^3.5.5:
version "3.7.2" version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==