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": {
"@fortawesome/fontawesome-free": "^5.13.0",
"@panter/vue-i18next": "^0.15.2",
"bluebird": "^3.7.2",
"bonjour": "^3.5.0",
"crypto-es": "^1.2.7",
"d3": "^7.8.2",

View File

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

View File

@ -254,10 +254,18 @@ FONT.msp = {
};
FONT.upload = function($progress) {
return Promise.mapSeries(FONT.data.characters, function(data, i) {
$progress.val((i / FONT.data.characters.length) * 100);
return MSP.promise(MSPCodes.MSP_OSD_CHAR_WRITE, FONT.msp.encode(i));
})
return FONT.data.characters
.reduce(
(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() {
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="./js/libraries/jquery.nouislider.all.min.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-touchswipe/jquery.touchSwipe.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);
const totalCommandsCount = strings.length;
return Promise.reduce(strings, (delay, line, index) => {
return new Promise((resolve) => {
GUI.timeout_add('CLI_send_slowly', () => {
let processingDelay = this.lineDelayMs;
line = line.trim();
return strings.reduce(strings, (p, line, index) =>
p.then((delay) =>
new Promise((resolve) => {
GUI.timeout_add('CLI_send_slowly', () => {
let processingDelay = this.lineDelayMs;
line = line.trim();
if (line.toLowerCase().startsWith('profile')) {
processingDelay = this.profileSwitchDelayMs;
}
if (line.toLowerCase().startsWith('profile')) {
processingDelay = this.profileSwitchDelayMs;
}
const isLastCommand = totalCommandsCount === index + 1;
const isLastCommand = totalCommandsCount === index + 1;
if (isLastCommand && this.cliBuffer) {
line = this.getCliCommand(line, this.cliBuffer);
}
if (isLastCommand && this.cliBuffer) {
line = this.getCliCommand(line, this.cliBuffer);
}
this.sendLine(line, ()=>{ /* empty on-send callback */ }, () => {
resolve(processingDelay);
this._reportSendCommandsProgress(100.0 * index / totalCommandsCount);
});
}, delay);
});
}, 0).then(() => {
this.sendLine(line, () => { /* empty on-send callback */ }, () => {
resolve(processingDelay);
this._reportSendCommandsProgress(100.0 * index / totalCommandsCount);
});
}, delay);
}),
),
Promise.resolve(0),
).then(() => {
this._reportSendCommandsProgress(100);
});
}

View File

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

View File

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

View File

@ -1,4 +1,3 @@
import { Promise } from "bluebird";
import {
describe,
it,
@ -88,7 +87,7 @@ describe("cli", () => {
cli.cliBuffer = "se";
cli.read({
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
@ -153,11 +152,7 @@ describe("cli", () => {
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) => {
cb();
});
@ -222,7 +217,7 @@ describe("cli", () => {
expect(cli.send).toHaveBeenCalledOnce();
expect(cli.send).toHaveBeenCalledWith(
`${backspaceCode.repeat(3)}\t`
`${backspaceCode.repeat(3)}\t`,
);
done();
});
@ -266,7 +261,7 @@ describe("cli", () => {
expect(cli.send).toHaveBeenCalledOnce();
expect(cli.send).toHaveBeenCalledWith(
`${backspaceCode.repeat(3)}\n`
`${backspaceCode.repeat(3)}\n`,
);
done();
});

View File

@ -4282,7 +4282,7 @@ bl@^4.0.3:
inherits "^2.0.4"
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"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==