1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 16:55:24 +03:00

Change lexical scope remaing root

This commit is contained in:
Mark Haslinghuis 2020-12-08 20:13:20 +01:00
parent 317f937fd5
commit 57539eb6de
10 changed files with 55 additions and 59 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var Analytics = function (trackingId, userId, appName, appVersion, changesetId, os, checkForDebugVersions, optOut, debugMode, buildType) { const Analytics = function (trackingId, userId, appName, appVersion, changesetId, os, checkForDebugVersions, optOut, debugMode, buildType) {
this._trackingId = trackingId; this._trackingId = trackingId;
this.setOptOut(optOut); this.setOptOut(optOut);
@ -85,12 +85,12 @@ var Analytics = function (trackingId, userId, appName, appVersion, changesetId,
}; };
Analytics.prototype.setDimension = function (dimension, value) { Analytics.prototype.setDimension = function (dimension, value) {
var dimensionName = 'dimension' + dimension; const dimensionName = `dimension${dimension}`;
this._googleAnalytics.custom(dimensionName, value); this._googleAnalytics.custom(dimensionName, value);
} }
Analytics.prototype.setMetric = function (metric, value) { Analytics.prototype.setMetric = function (metric, value) {
var metricName = 'metric' + metric; const metricName = `metric${metric}`;
this._googleAnalytics.custom(metricName, value); this._googleAnalytics.custom(metricName, value);
} }
@ -99,9 +99,9 @@ Analytics.prototype.sendEvent = function (category, action, options) {
} }
Analytics.prototype.sendChangeEvents = function (category, changeList) { Analytics.prototype.sendChangeEvents = function (category, changeList) {
for (var actionName in changeList) { for (const actionName in changeList) {
if (changeList.hasOwnProperty(actionName)) { if (changeList.hasOwnProperty(actionName)) {
var actionValue = changeList[actionName]; const actionValue = changeList[actionName];
if (actionValue !== undefined) { if (actionValue !== undefined) {
this.sendEvent(category, actionName, { eventLabel: actionValue }); this.sendEvent(category, actionName, { eventLabel: actionValue });
} }

View file

@ -4,7 +4,7 @@
* Encapsulates the Clipboard logic, depending on web or nw * Encapsulates the Clipboard logic, depending on web or nw
* *
*/ */
var Clipboard = { const Clipboard = {
_nwClipboard: null, _nwClipboard: null,
available : null, available : null,
readAvailable : null, readAvailable : null,

View file

@ -1,10 +1,10 @@
'use strict'; 'use strict';
var css_dark = [ const css_dark = [
'./css/dark-theme.css', './css/dark-theme.css',
]; ];
var DarkTheme = { const DarkTheme = {
configEnabled: undefined, configEnabled: undefined,
}; };

View file

@ -5,7 +5,7 @@
// and then manually setting vcp to true for boards that use VCP // and then manually setting vcp to true for boards that use VCP
// Also, please note that the targets in this list are ordered in the order they are returned by the above command. Please do not reorder to avoid churn. // Also, please note that the targets in this list are ordered in the order they are returned by the above command. Please do not reorder to avoid churn.
var BOARD_DEFINITIONS = [ const BOARD_DEFINITIONS = [
{name: 'AIR32', identifier: 'AR32', vcp: true}, {name: 'AIR32', identifier: 'AR32', vcp: true},
{name: 'AIRHEROF3', identifier: 'AIR3', vcp: false}, {name: 'AIRHEROF3', identifier: 'AIR3', vcp: false},
{name: 'ALIENFLIGHTF1', identifier: 'AFF1', vcp: false}, {name: 'ALIENFLIGHTF1', identifier: 'AFF1', vcp: false},
@ -74,17 +74,15 @@ var BOARD_DEFINITIONS = [
{name: 'ZCOREF3', identifier: 'ZCF3', vcp: false} {name: 'ZCOREF3', identifier: 'ZCF3', vcp: false}
]; ];
var DEFAULT_BOARD_DEFINITION = { const DEFAULT_BOARD_DEFINITION = {
name: "Unknown", identifier: "????", vcp: false name: "Unknown", identifier: "????", vcp: false
}; };
var BOARD = {}; const BOARD = {};
BOARD.find_board_definition = function (identifier) { BOARD.find_board_definition = function (identifier) {
for (var i = 0; i < BOARD_DEFINITIONS.length; i++) { for (const candidate of BOARD_DEFINITIONS) {
var candidate = BOARD_DEFINITIONS[i]; if (candidate.identifier === identifier) {
if (candidate.identifier == identifier) {
return candidate; return candidate;
} }
} }

View file

@ -15,7 +15,7 @@ const API_VERSION_1_42 = '1.42.0';
const API_VERSION_1_43 = '1.43.0'; const API_VERSION_1_43 = '1.43.0';
const API_VERSION_1_44 = '1.44.0'; const API_VERSION_1_44 = '1.44.0';
var CONFIGURATOR = { const CONFIGURATOR = {
// all versions are specified and compared using semantic versioning http://semver.org/ // all versions are specified and compared using semantic versioning http://semver.org/
API_VERSION_ACCEPTED: '1.2.1', API_VERSION_ACCEPTED: '1.2.1',
API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE: '1.5.0', API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE: '1.5.0',

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var defaultHuffmanTree = [ const defaultHuffmanTree = [
{ value: 0x00, codeLen: 2, code: 0x0003 }, // 11 { value: 0x00, codeLen: 2, code: 0x0003 }, // 11
{ value: 0x01, codeLen: 3, code: 0x0005 }, // 101 { value: 0x01, codeLen: 3, code: 0x0005 }, // 101
{ value: 0x02, codeLen: 4, code: 0x0009 }, // 1001 { value: 0x02, codeLen: 4, code: 0x0009 }, // 1001
@ -260,12 +260,11 @@ var defaultHuffmanTree = [
{ value: HUFFMAN_EOF, codeLen: 12, code: 0x0000 }, // 000000000000 { value: HUFFMAN_EOF, codeLen: 12, code: 0x0000 }, // 000000000000
]; ];
var defaultHuffmanLenIndex = function() const defaultHuffmanLenIndex = function() {
{ const result = Array(defaultHuffmanTree.length).fill(-1);
var result = Array(defaultHuffmanTree.length).fill(-1);
for (var i = 0; i < defaultHuffmanTree.length; ++i) { for (let i = 0; i < defaultHuffmanTree.length; ++i) {
if (result[defaultHuffmanTree[i].codeLen] == -1) { if (result[defaultHuffmanTree[i].codeLen] === -1) {
result[defaultHuffmanTree[i].codeLen] = i; result[defaultHuffmanTree[i].codeLen] = i;
} }
} }

View file

@ -1,14 +1,13 @@
'use strict'; 'use strict';
var HUFFMAN_EOF = -1; const HUFFMAN_EOF = -1;
function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenIndex) function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenIndex) {
{ let code = 0;
var code = 0; let codeLen = 0;
var codeLen = 0; let testBit = 0x80;
var testBit = 0x80; let eof = false;
var eof = false; const outBuf = [];
var outBuf = [];
while (!eof && inBuf.byteLength != 0) { while (!eof && inBuf.byteLength != 0) {
if (outBuf.length == inBufCharacterCount) { if (outBuf.length == inBufCharacterCount) {
@ -35,10 +34,10 @@ function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenInd
// check if the code is a leaf node or an interior node // check if the code is a leaf node or an interior node
if (huffmanLenIndex[codeLen] != -1) { if (huffmanLenIndex[codeLen] != -1) {
// look for the code in the tree, only leaf nodes are stored in the tree // look for the code in the tree, only leaf nodes are stored in the tree
for (var i = huffmanLenIndex[codeLen]; (i < huffmanTree.length) && (huffmanTree[i].codeLen == codeLen); ++i) { for (let i = huffmanLenIndex[codeLen]; (i < huffmanTree.length) && (huffmanTree[i].codeLen === codeLen); ++i) {
if (huffmanTree[i].code == code) { if (huffmanTree[i].code === code) {
// we've found the code, so it is a leaf node // we've found the code, so it is a leaf node
var value = huffmanTree[i].value; const value = huffmanTree[i].value;
if (value == HUFFMAN_EOF) { if (value == HUFFMAN_EOF) {
eof = true; eof = true;
@ -57,4 +56,4 @@ function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenInd
} }
return new Uint8Array(outBuf); return new Uint8Array(outBuf);
} }

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
// generate mixer // generate mixer
var mixerList = [ const mixerList = [
{name: 'Tricopter', pos: 3, model: 'tricopter', image: 'tri'}, {name: 'Tricopter', pos: 3, model: 'tricopter', image: 'tri'},
{name: 'Quad +', pos: 2, model: 'quad_x', image: 'quad_p'}, {name: 'Quad +', pos: 2, model: 'quad_x', image: 'quad_p'},
{name: 'Quad X', pos: 0, model: 'quad_x', image: 'quad_x'}, {name: 'Quad X', pos: 0, model: 'quad_x', image: 'quad_x'},
@ -31,8 +31,8 @@ var mixerList = [
]; ];
// 3D model // 3D model
var Model = function (wrapper, canvas) { const Model = function (wrapper, canvas) {
var useWebGLRenderer = this.canUseWebGLRenderer(); const useWebGLRenderer = this.canUseWebGLRenderer();
this.wrapper = wrapper; this.wrapper = wrapper;
this.canvas = canvas; this.canvas = canvas;
@ -47,7 +47,7 @@ var Model = function (wrapper, canvas) {
this.renderer.setSize(this.wrapper.width() * 2, this.wrapper.height() * 2); this.renderer.setSize(this.wrapper.width() * 2, this.wrapper.height() * 2);
// load the model including materials // load the model including materials
var model_file = useWebGLRenderer ? mixerList[FC.MIXER_CONFIG.mixer - 1].model : 'fallback'; let model_file = useWebGLRenderer ? mixerList[FC.MIXER_CONFIG.mixer - 1].model : 'fallback';
// Temporary workaround for 'custom' model until akfreak's custom model is merged. // Temporary workaround for 'custom' model until akfreak's custom model is merged.
if (model_file == 'custom') { model_file = 'fallback'; } if (model_file == 'custom') { model_file = 'fallback'; }
@ -65,8 +65,8 @@ var Model = function (wrapper, canvas) {
this.camera.position.z = 125; this.camera.position.z = 125;
// some light // some light
var light = new THREE.AmbientLight(0x404040); const light = new THREE.AmbientLight(0x404040);
var light2 = new THREE.DirectionalLight(new THREE.Color(1, 1, 1), 1.5); const light2 = new THREE.DirectionalLight(new THREE.Color(1, 1, 1), 1.5);
light2.position.set(0, 1, 0); light2.position.set(0, 1, 0);
// add camera, model, light to the foreground scene // add camera, model, light to the foreground scene
@ -103,7 +103,7 @@ Model.prototype.canUseWebGLRenderer = function () {
// webgl capability detector // webgl capability detector
// it would seem the webgl "enabling" through advanced settings will be ignored in the future // it would seem the webgl "enabling" through advanced settings will be ignored in the future
// and webgl will be supported if gpu supports it by default (canary 40.0.2175.0), keep an eye on this one // and webgl will be supported if gpu supports it by default (canary 40.0.2175.0), keep an eye on this one
var detector_canvas = document.createElement('canvas'); const detector_canvas = document.createElement('canvas');
return window.WebGLRenderingContext && (detector_canvas.getContext('webgl') || detector_canvas.getContext('experimental-webgl')); return window.WebGLRenderingContext && (detector_canvas.getContext('webgl') || detector_canvas.getContext('experimental-webgl'));
}; };

View file

@ -2,8 +2,8 @@
// return true if user has choose a special peripheral // return true if user has choose a special peripheral
function isPeripheralSelected(peripheralName) { function isPeripheralSelected(peripheralName) {
for (var portIndex = 0; portIndex < FC.SERIAL_CONFIG.ports.length; portIndex++) { for (let portIndex = 0; portIndex < FC.SERIAL_CONFIG.ports.length; portIndex++) {
var serialPort = FC.SERIAL_CONFIG.ports[portIndex]; const serialPort = FC.SERIAL_CONFIG.ports[portIndex];
if (serialPort.functions.indexOf(peripheralName) >= 0) { if (serialPort.functions.indexOf(peripheralName) >= 0) {
return true; return true;
} }
@ -25,8 +25,8 @@ function adjustBoxNameIfPeripheralWithModeID(modeId, defaultName) {
default: default:
return defaultName; return defaultName;
} }
} }
return defaultName; return defaultName;
} }

View file

@ -2,7 +2,7 @@
var ReleaseChecker = function (releaseName, releaseUrl) { var ReleaseChecker = function (releaseName, releaseUrl) {
var self = this; var self = this;
self._releaseName = releaseName; self._releaseName = releaseName;
self._releaseDataTag = `${self._releaseName}ReleaseData`; self._releaseDataTag = `${self._releaseName}ReleaseData`;
self._releaseLastUpdateTag = `${self._releaseName}ReleaseLastUpdate` self._releaseLastUpdateTag = `${self._releaseName}ReleaseLastUpdate`
@ -10,28 +10,28 @@ var ReleaseChecker = function (releaseName, releaseUrl) {
} }
ReleaseChecker.prototype.loadReleaseData = function (processFunction) { ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
var self = this; const self = this;
chrome.storage.local.get([self._releaseLastUpdateTag, self._releaseDataTag], function (result) { chrome.storage.local.get([self._releaseLastUpdateTag, self._releaseDataTag], function (result) {
var releaseDataTimestamp = $.now(); const releaseDataTimestamp = $.now();
var cacheReleaseData = result[self._releaseDataTag]; const cacheReleaseData = result[self._releaseDataTag];
var cachedReleaseLastUpdate = result[self._releaseLastUpdateTag]; const cachedReleaseLastUpdate = result[self._releaseLastUpdateTag];
if (!cacheReleaseData || !cachedReleaseLastUpdate || releaseDataTimestamp - cachedReleaseLastUpdate > 3600 * 1000) { if (!cacheReleaseData || !cachedReleaseLastUpdate || releaseDataTimestamp - cachedReleaseLastUpdate > 3600 * 1000) {
$.get(self._releaseUrl, function (releaseData) { $.get(self._releaseUrl, function (releaseData) {
GUI.log(i18n.getMessage('releaseCheckLoaded',[self._releaseName])); GUI.log(i18n.getMessage('releaseCheckLoaded',[self._releaseName]));
var data = {}; const data = {};
data[self._releaseDataTag] = releaseData data[self._releaseDataTag] = releaseData;
data[self._releaseLastUpdateTag] = releaseDataTimestamp data[self._releaseLastUpdateTag] = releaseDataTimestamp;
chrome.storage.local.set(data, function () {}); chrome.storage.local.set(data, function () {});
self._processReleaseData(releaseData, processFunction); self._processReleaseData(releaseData, processFunction);
}).fail(function (data) { }).fail(function (data) {
var message = ''; let message = '';
if (data['responseJSON']) { if (data['responseJSON']) {
message = data['responseJSON'].message; message = data['responseJSON'].message;
} }
GUI.log(i18n.getMessage('releaseCheckFailed',[self._releaseName,message])); GUI.log(i18n.getMessage('releaseCheckFailed',[self._releaseName,message]));
self._processReleaseData(cacheReleaseData, processFunction); self._processReleaseData(cacheReleaseData, processFunction);
}); });
} else { } else {
@ -43,7 +43,7 @@ ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
} }
}); });
} }
ReleaseChecker.prototype._processReleaseData = function (releaseData, processFunction) { ReleaseChecker.prototype._processReleaseData = function (releaseData, processFunction) {
if (releaseData) { if (releaseData) {