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

Auto merged - #2513 at Sat, 19 Jun 2021 20:25:05 GMT

Rebase of firmware_flasher.js
This commit is contained in:
J Blackman 2021-06-20 06:25:06 +10:00 committed by GitHub
commit 2273b36fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,9 +15,9 @@ const firmware_flasher = {
}; };
firmware_flasher.initialize = function (callback) { firmware_flasher.initialize = function (callback) {
var self = this; const self = this;
if (GUI.active_tab != 'firmware_flasher') { if (GUI.active_tab !== 'firmware_flasher') {
GUI.active_tab = 'firmware_flasher'; GUI.active_tab = 'firmware_flasher';
} }
@ -27,7 +27,7 @@ firmware_flasher.initialize = function (callback) {
self.intel_hex = undefined; self.intel_hex = undefined;
self.parsed_hex = undefined; self.parsed_hex = undefined;
var unifiedSource = 'https://api.github.com/repos/betaflight/unified-targets/contents/configs/default'; const unifiedSource = 'https://api.github.com/repos/betaflight/unified-targets/contents/configs/default';
function onFirmwareCacheUpdate(release) { function onFirmwareCacheUpdate(release) {
$('select[name="firmware_version"] option').each(function () { $('select[name="firmware_version"] option').each(function () {
@ -46,7 +46,7 @@ firmware_flasher.initialize = function (callback) {
function parse_hex(str, callback) { function parse_hex(str, callback) {
// parsing hex in different thread // parsing hex in different thread
var worker = new Worker('./js/workers/hex_parser.js'); const worker = new Worker('./js/workers/hex_parser.js');
// "callback" // "callback"
worker.onmessage = function (event) { worker.onmessage = function (event) {
@ -59,7 +59,7 @@ firmware_flasher.initialize = function (callback) {
function show_loaded_hex(summary) { function show_loaded_hex(summary) {
self.flashingMessage('<a class="save_firmware" href="#" title="Save Firmware">' + i18n.getMessage('firmwareFlasherFirmwareOnlineLoaded', self.parsed_hex.bytes_total) + '</a>', self.flashingMessage('<a class="save_firmware" href="#" title="Save Firmware">' + i18n.getMessage('firmwareFlasherFirmwareOnlineLoaded', self.parsed_hex.bytes_total) + '</a>',
self.FLASH_MESSAGE_TYPES.NEUTRAL); self.FLASH_MESSAGE_TYPES.NEUTRAL);
self.enableFlashing(true); self.enableFlashing(true);
@ -82,7 +82,7 @@ firmware_flasher.initialize = function (callback) {
$('div.release_info #unifiedTargetInfo').hide(); $('div.release_info #unifiedTargetInfo').hide();
} }
var formattedNotes = summary.notes.replace(/#(\d+)/g, '[#$1](https://github.com/betaflight/betaflight/pull/$1)'); let formattedNotes = summary.notes.replace(/#(\d+)/g, '[#$1](https://github.com/betaflight/betaflight/pull/$1)');
formattedNotes = marked(formattedNotes); formattedNotes = marked(formattedNotes);
$('div.release_info .notes').html(formattedNotes); $('div.release_info .notes').html(formattedNotes);
$('div.release_info .notes').find('a').each(function() { $('div.release_info .notes').find('a').each(function() {
@ -123,7 +123,7 @@ firmware_flasher.initialize = function (callback) {
process_hex(data, summary); process_hex(data, summary);
$("a.load_remote_file").removeClass('disabled'); $("a.load_remote_file").removeClass('disabled');
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline')); $("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline'));
}; }
function populateBoardOptions(builds) { function populateBoardOptions(builds) {
if (!builds) { if (!builds) {
@ -133,26 +133,24 @@ firmware_flasher.initialize = function (callback) {
return; return;
} }
var boards_e = $('select[name="board"]'); const boards_e = $('select[name="board"]');
boards_e.empty(); boards_e.empty();
boards_e.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectBoard")}</option>`)); boards_e.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectBoard")}</option>`));
var versions_e = $('select[name="firmware_version"]'); const versions_e = $('select[name="firmware_version"]');
versions_e.empty(); versions_e.empty();
versions_e.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectFirmwareVersion")}</option>`)); versions_e.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectFirmwareVersion")}</option>`));
var selectTargets = []; const selectTargets = [];
Object.keys(builds) Object.keys(builds)
.sort() .sort()
.forEach(function(target, i) { .forEach(function(target, i) {
var descriptors = builds[target]; const descriptors = builds[target];
descriptors.forEach(function(descriptor){ descriptors.forEach(function(descriptor){
if($.inArray(target, selectTargets) == -1) { if ($.inArray(target, selectTargets) === -1) {
selectTargets.push(target); selectTargets.push(target);
var select_e = $( const select_e = $(`<option value='${descriptor.target}'>${descriptor.target}</option>`) ;
`<option value='${descriptor.target}'>${descriptor.target}</option>`,
);
boards_e.append(select_e); boards_e.append(select_e);
} }
}); });
@ -162,25 +160,25 @@ firmware_flasher.initialize = function (callback) {
ConfigStorage.get('selected_board', function (result) { ConfigStorage.get('selected_board', function (result) {
if (result.selected_board) { if (result.selected_board) {
var boardBuilds = builds[result.selected_board]; const boardBuilds = builds[result.selected_board];
$('select[name="board"]').val(boardBuilds ? result.selected_board : 0).trigger('change'); $('select[name="board"]').val(boardBuilds ? result.selected_board : 0).trigger('change');
} }
}); });
} }
function processBoardOptions(releaseData, showDevReleases) { function processBoardOptions(releaseData, showDevReleases) {
var releases = {}; const releases = {};
var sortedTargets = []; let sortedTargets = [];
var unsortedTargets = []; const unsortedTargets = [];
releaseData.forEach(function(release) { releaseData.forEach(function(release) {
release.assets.forEach(function(asset) { release.assets.forEach(function(asset) {
var targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/; const targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/;
var match = targetFromFilenameExpression.exec(asset.name); const match = targetFromFilenameExpression.exec(asset.name);
if ((!showDevReleases && release.prerelease) || !match) { if ((!showDevReleases && release.prerelease) || !match) {
return; return;
} }
var target = match[2]; const target = match[2];
if($.inArray(target, unsortedTargets) == -1) { if ($.inArray(target, unsortedTargets) === -1) {
unsortedTargets.push(target); unsortedTargets.push(target);
} }
}); });
@ -190,23 +188,23 @@ firmware_flasher.initialize = function (callback) {
releases[release] = []; releases[release] = [];
}); });
releaseData.forEach(function(release) { releaseData.forEach(function(release) {
var versionFromTagExpression = /v?(.*)/; const versionFromTagExpression = /v?(.*)/;
var matchVersionFromTag = versionFromTagExpression.exec(release.tag_name); const matchVersionFromTag = versionFromTagExpression.exec(release.tag_name);
var version = matchVersionFromTag[1]; const version = matchVersionFromTag[1];
release.assets.forEach(function(asset) { release.assets.forEach(function(asset) {
var targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/; const targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/;
var match = targetFromFilenameExpression.exec(asset.name); const match = targetFromFilenameExpression.exec(asset.name);
if ((!showDevReleases && release.prerelease) || !match) { if ((!showDevReleases && release.prerelease) || !match) {
return; return;
} }
var target = match[2]; const target = match[2];
var format = match[4]; const format = match[4];
if (format != 'hex') { if (format !== 'hex') {
return; return;
} }
var date = new Date(release.published_at); const date = new Date(release.published_at);
var formattedDate = ("0" + date.getDate()).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2); const formattedDate = ("0" + date.getDate()).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2);
var descriptor = { const descriptor = {
"releaseUrl": release.html_url, "releaseUrl": release.html_url,
"name" : version, "name" : version,
"version" : version, "version" : version,
@ -220,7 +218,7 @@ firmware_flasher.initialize = function (callback) {
}); });
}); });
loadUnifiedBuilds(releases); loadUnifiedBuilds(releases);
}; }
function supportsUnifiedTargets(version) { function supportsUnifiedTargets(version) {
return semver.gte(version.split(' ')[0], '4.1.0-RC1'); return semver.gte(version.split(' ')[0], '4.1.0-RC1');
@ -236,14 +234,14 @@ firmware_flasher.initialize = function (callback) {
} }
function loadUnifiedBuilds(builds) { function loadUnifiedBuilds(builds) {
var expirationPeriod = 3600 * 2; // Two of your earth hours. const expirationPeriod = 3600 * 2; // Two of your earth hours.
var checkTime = Math.floor(Date.now() / 1000); // Lets deal in seconds. const checkTime = Math.floor(Date.now() / 1000); // Lets deal in seconds.
if (builds && hasUnifiedTargetBuild(builds)) { if (builds && hasUnifiedTargetBuild(builds)) {
console.log('loaded some builds for later'); console.log('loaded some builds for later');
const storageTag = 'unifiedSourceCache'; const storageTag = 'unifiedSourceCache';
chrome.storage.local.get(storageTag, function (result) { chrome.storage.local.get(storageTag, function (result) {
let storageObj = result[storageTag]; let storageObj = result[storageTag];
if(!storageObj || !storageObj.lastUpdate || checkTime - storageObj.lastUpdate > expirationPeriod) { if (!storageObj || !storageObj.lastUpdate || checkTime - storageObj.lastUpdate > expirationPeriod) {
console.log('go get', unifiedSource); console.log('go get', unifiedSource);
$.get(unifiedSource, function(data, textStatus, jqXHR) { $.get(unifiedSource, function(data, textStatus, jqXHR) {
// Cache the information for later use. // Cache the information for later use.
@ -295,19 +293,16 @@ firmware_flasher.initialize = function (callback) {
unifiedConfigs[targetName] = (unifiedConfigs[targetName] || {}); unifiedConfigs[targetName] = (unifiedConfigs[targetName] || {});
unifiedConfigs[targetName][manufacturerId] = target; unifiedConfigs[targetName][manufacturerId] = target;
}); });
var boards_e = $('select[name="board"]'); const boards_e = $('select[name="board"]');
var versions_e = $('select[name="firmware_version"]'); const versions_e = $('select[name="firmware_version"]');
boards_e.empty() boards_e.empty()
.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectBoard")}</option>`)); .append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectBoard")}</option>`));
versions_e.empty() versions_e.empty()
.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectFirmwareVersion")}</option>`)); .append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLabelSelectFirmwareVersion")}</option>`));
var selectTargets = [];
Object.keys(items) Object.keys(items)
.sort() .sort()
.forEach(function(target, i) { .forEach(function(target) {
let item = items[target];
const select_e = $(`<option value='${target}'>${target}</option>"`); const select_e = $(`<option value='${target}'>${target}</option>"`);
boards_e.append(select_e); boards_e.append(select_e);
}); });
@ -316,14 +311,14 @@ firmware_flasher.initialize = function (callback) {
ConfigStorage.get('selected_board', function (result) { ConfigStorage.get('selected_board', function (result) {
if (result.selected_board) { if (result.selected_board) {
var boardReleases = TABS.firmware_flasher.unifiedConfigs[result.selected_board] const boardReleases = TABS.firmware_flasher.unifiedConfigs[result.selected_board]
|| TABS.firmware_flasher.releases[result.selected_board]; || TABS.firmware_flasher.releases[result.selected_board];
$('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change'); $('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change');
} }
}); });
} }
var buildTypes = [ const buildTypes = [
{ {
tag: 'firmwareFlasherOptionLabelBuildTypeRelease', tag: 'firmwareFlasherOptionLabelBuildTypeRelease',
loader: () => self.releaseChecker.loadReleaseData(releaseData => processBoardOptions(releaseData, false)) loader: () => self.releaseChecker.loadReleaseData(releaseData => processBoardOptions(releaseData, false))
@ -334,7 +329,7 @@ firmware_flasher.initialize = function (callback) {
} }
]; ];
var ciBuildsTypes = self.jenkinsLoader._jobs.map(job => { const ciBuildsTypes = self.jenkinsLoader._jobs.map(job => {
if (job.title === "Development") { if (job.title === "Development") {
return { return {
tag: "firmwareFlasherOptionLabelBuildTypeDevelopment", tag: "firmwareFlasherOptionLabelBuildTypeDevelopment",
@ -346,9 +341,9 @@ firmware_flasher.initialize = function (callback) {
loader: () => self.jenkinsLoader.loadBuilds(job.name, loadUnifiedBuilds) loader: () => self.jenkinsLoader.loadBuilds(job.name, loadUnifiedBuilds)
}; };
}); });
var buildTypesToShow; let buildTypesToShow;
var buildType_e = $('select[name="build_type"]'); const buildType_e = $('select[name="build_type"]');
function buildBuildTypeOptionsList() { function buildBuildTypeOptionsList() {
buildType_e.empty(); buildType_e.empty();
buildTypesToShow.forEach(({ tag, title }, index) => { buildTypesToShow.forEach(({ tag, title }, index) => {
@ -364,7 +359,7 @@ firmware_flasher.initialize = function (callback) {
} }
function showOrHideBuildTypes() { function showOrHideBuildTypes() {
var showExtraReleases = $(this).is(':checked'); const showExtraReleases = $(this).is(':checked');
if (showExtraReleases) { if (showExtraReleases) {
$('tr.build_type').show(); $('tr.build_type').show();
@ -376,9 +371,9 @@ firmware_flasher.initialize = function (callback) {
} }
} }
var globalExpertMode_e = $('input[name="expertModeCheckbox"]'); const globalExpertMode_e = $('input[name="expertModeCheckbox"]');
function showOrHideBuildTypeSelect() { function showOrHideBuildTypeSelect() {
var expertModeChecked = $(this).is(':checked'); const expertModeChecked = $(this).is(':checked');
globalExpertMode_e.prop('checked', expertModeChecked); globalExpertMode_e.prop('checked', expertModeChecked);
if (expertModeChecked) { if (expertModeChecked) {
@ -391,7 +386,7 @@ firmware_flasher.initialize = function (callback) {
} }
} }
var expertMode_e = $('.tab-firmware_flasher input.expert_mode'); const expertMode_e = $('.tab-firmware_flasher input.expert_mode');
expertMode_e.prop('checked', globalExpertMode_e.is(':checked')); expertMode_e.prop('checked', globalExpertMode_e.is(':checked'));
$('input.show_development_releases').change(showOrHideBuildTypes).change(); $('input.show_development_releases').change(showOrHideBuildTypes).change();
expertMode_e.change(showOrHideBuildTypeSelect).change(); expertMode_e.change(showOrHideBuildTypeSelect).change();
@ -403,7 +398,7 @@ firmware_flasher.initialize = function (callback) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_CHANNEL, $('option:selected', this).text()); analytics.setFirmwareData(analytics.DATA.FIRMWARE_CHANNEL, $('option:selected', this).text());
$("a.load_remote_file").addClass('disabled'); $("a.load_remote_file").addClass('disabled');
var build_type = $(this).val(); const build_type = $(this).val();
$('select[name="board"]').empty() $('select[name="board"]').empty()
.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLoading")}</option>`)); .append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLoading")}</option>`));
@ -477,21 +472,19 @@ firmware_flasher.initialize = function (callback) {
let versionLabel; let versionLabel;
if (version.isLegacy && Object.values(builds).some(function (build) { if (version.isLegacy && Object.values(builds).some(function (build) {
return build.descriptor.version === version.descriptor.version && !build.isLegacy; return build.descriptor.version === version.descriptor.version && !build.isLegacy;
})) { })) {
versionLabel = i18n.getMessage("firmwareFlasherLegacyLabel", { target: version.descriptor.version }); versionLabel = i18n.getMessage("firmwareFlasherLegacyLabel", { target: version.descriptor.version });
} else if (!version.isLegacy && Object.values(builds).some(function (build) { } else if (!version.isLegacy && Object.values(builds).some(function (build) {
return build.descriptor.version === version.descriptor.version && build.manufacturerId !== version.manufacturerId && !build.isLegacy; return build.descriptor.version === version.descriptor.version && build.manufacturerId !== version.manufacturerId && !build.isLegacy;
})) { })) {
versionLabel = `${version.descriptor.version} (${version.manufacturerId})`; versionLabel = `${version.descriptor.version} (${version.manufacturerId})`;
} else { } else {
versionLabel = version.descriptor.version; versionLabel = version.descriptor.version;
} }
var select_e = $( const select_e = $(`<option value='${versionName}'>${version.descriptor.date} - ${versionLabel}</option>`);
`<option value='${versionName}'>${version.descriptor.date} - ${versionLabel}</option>`
);
if (FirmwareCache.has(version.descriptor)) { if (FirmwareCache.has(version.descriptor)) {
select_e.addClass("cached"); select_e.addClass("cached");
} }
@ -540,10 +533,10 @@ firmware_flasher.initialize = function (callback) {
$('select[name="board"]').change(function() { $('select[name="board"]').change(function() {
$("a.load_remote_file").addClass('disabled'); $("a.load_remote_file").addClass('disabled');
var target = $(this).val(); const target = $(this).val();
if (!GUI.connect_lock) { if (!GUI.connect_lock) {
if (TABS.firmware_flasher.selectedBoard != target) { if (TABS.firmware_flasher.selectedBoard !== target) {
// We're sure the board actually changed // We're sure the board actually changed
if (self.isConfigLocal) { if (self.isConfigLocal) {
console.log('Board changed, unloading local config'); console.log('Board changed, unloading local config');
@ -566,9 +559,9 @@ firmware_flasher.initialize = function (callback) {
self.enableFlashing(false); self.enableFlashing(false);
} }
var versions_e = $('select[name="firmware_version"]'); const versions_e = $('select[name="firmware_version"]');
if (target == 0) { if (target === 0) {
// target == 0 is the "Choose a Board" option. Throw out anything loaded // target is 0 is the "Choose a Board" option. Throw out anything loaded
clearBufferedFirmware(); clearBufferedFirmware();
versions_e.empty(); versions_e.empty();
@ -590,7 +583,6 @@ firmware_flasher.initialize = function (callback) {
) )
); );
let selecteBuild = buildTypesToShow[$('select[name="build_type"]').val()];
const builds = []; const builds = [];
const finishPopulatingBuilds = function () { const finishPopulatingBuilds = function () {
@ -604,8 +596,8 @@ firmware_flasher.initialize = function (callback) {
if (TABS.firmware_flasher.unifiedConfigs[target]) { if (TABS.firmware_flasher.unifiedConfigs[target]) {
const storageTag = 'unifiedConfigLast'; const storageTag = 'unifiedConfigLast';
var expirationPeriod = 3600; // One of your earth hours. const expirationPeriod = 3600; // One of your earth hours.
var checkTime = Math.floor(Date.now() / 1000); // Lets deal in seconds. const checkTime = Math.floor(Date.now() / 1000); // Lets deal in seconds.
chrome.storage.local.get(storageTag, function (result) { chrome.storage.local.get(storageTag, function (result) {
let storageObj = result[storageTag]; let storageObj = result[storageTag];
const unifiedConfigList = TABS.firmware_flasher.unifiedConfigs[target]; const unifiedConfigList = TABS.firmware_flasher.unifiedConfigs[target];
@ -713,10 +705,10 @@ firmware_flasher.initialize = function (callback) {
let output = []; let output = [];
let inComment = false; let inComment = false;
for (let i=0; i < input.length; i++) { for (let i=0; i < input.length; i++) {
if (input.charAt(i) == "\n" || input.charAt(i) == "\r") { if (input.charAt(i) === "\n" || input.charAt(i) === "\r") {
inComment = false; inComment = false;
} }
if (input.charAt(i) == "#") { if (input.charAt(i) === "#") {
inComment = true; inComment = true;
} }
if (!inComment && input.charCodeAt(i) > 255) { if (!inComment && input.charCodeAt(i) > 255) {
@ -735,9 +727,9 @@ firmware_flasher.initialize = function (callback) {
const portPickerElement = $('div#port-picker #port'); const portPickerElement = $('div#port-picker #port');
function flashFirmware(firmware) { function flashFirmware(firmware) {
var options = {}; const options = {};
var eraseAll = false; let eraseAll = false;
if ($('input.erase_chip').is(':checked')) { if ($('input.erase_chip').is(':checked')) {
options.erase_chip = true; options.erase_chip = true;
@ -810,7 +802,7 @@ firmware_flasher.initialize = function (callback) {
// bind UI hook so the status is saved on change // bind UI hook so the status is saved on change
$('input.updating').change(function() { $('input.updating').change(function() {
var status = $(this).is(':checked'); const status = $(this).is(':checked');
if (status) { if (status) {
$('.flash_on_connect_wrapper').show(); $('.flash_on_connect_wrapper').show();
@ -834,7 +826,7 @@ firmware_flasher.initialize = function (callback) {
// bind UI hook so the status is saved on change // bind UI hook so the status is saved on change
$('input.flash_manual_baud').change(function() { $('input.flash_manual_baud').change(function() {
var status = $(this).is(':checked'); const status = $(this).is(':checked');
ConfigStorage.set({'flash_manual_baud': status}); ConfigStorage.set({'flash_manual_baud': status});
}); });
@ -846,7 +838,7 @@ firmware_flasher.initialize = function (callback) {
// bind UI hook so the status is saved on change // bind UI hook so the status is saved on change
$('#flash_manual_baud_rate').change(function() { $('#flash_manual_baud_rate').change(function() {
var baud = parseInt($('#flash_manual_baud_rate').val()); const baud = parseInt($('#flash_manual_baud_rate').val());
ConfigStorage.set({'flash_manual_baud_rate': baud}); ConfigStorage.set({'flash_manual_baud_rate': baud});
}); });
@ -878,15 +870,15 @@ firmware_flasher.initialize = function (callback) {
$('div.git_info').slideUp(); $('div.git_info').slideUp();
chrome.fileSystem.getDisplayPath(fileEntry, function (path) { chrome.fileSystem.getDisplayPath(fileEntry, function (path) {
console.log('Loading file from: ' + path); console.log('Loading file from:', path);
fileEntry.file(function (file) { fileEntry.file(function (file) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, file.name); analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, file.name);
var reader = new FileReader(); const reader = new FileReader();
reader.onloadend = function(e) { reader.onloadend = function(e) {
if (e.total != 0 && e.total == e.loaded) { if (e.total !== 0 && e.total === e.loaded) {
console.log('File loaded (' + e.loaded + ')'); console.log(`File loaded (${e.loaded})`);
if (file.name.split('.').pop() === "hex") { if (file.name.split('.').pop() === "hex") {
self.intel_hex = e.target.result; self.intel_hex = e.target.result;
@ -933,7 +925,7 @@ firmware_flasher.initialize = function (callback) {
if (!self.localFirmwareLoaded) { if (!self.localFirmwareLoaded) {
self.enableFlashing(false); self.enableFlashing(false);
self.flashingMessage(i18n.getMessage('firmwareFlasherLoadFirmwareFile'), self.FLASH_MESSAGE_TYPES.NEUTRAL); self.flashingMessage(i18n.getMessage('firmwareFlasherLoadFirmwareFile'), self.FLASH_MESSAGE_TYPES.NEUTRAL);
if(self.parsed_hex && self.parsed_hex.bytes_total) { if (self.parsed_hex && self.parsed_hex.bytes_total) {
// Changing the board triggers a version change, so we need only dump it here. // Changing the board triggers a version change, so we need only dump it here.
console.log('throw out loaded hex'); console.log('throw out loaded hex');
self.intel_hex = undefined; self.intel_hex = undefined;
@ -949,7 +941,7 @@ firmware_flasher.initialize = function (callback) {
FirmwareCache.get(release, cached => { FirmwareCache.get(release, cached => {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, release.file); analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, release.file);
console.info("Release found in cache: " + release.file); console.info("Release found in cache:", release.file);
self.developmentFirmwareLoaded = buildTypesToShow[$('select[name="build_type"]').val()].tag === 'firmwareFlasherOptionLabelBuildTypeDevelopment'; self.developmentFirmwareLoaded = buildTypesToShow[$('select[name="build_type"]').val()].tag === 'firmwareFlasherOptionLabelBuildTypeDevelopment';
@ -970,7 +962,7 @@ firmware_flasher.initialize = function (callback) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'http'); analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'http');
if ($('select[name="firmware_version"]').val() == "0") { if ($('select[name="firmware_version"]').val() === "0") {
GUI.log(i18n.getMessage('firmwareFlasherNoFirmwareSelected')); GUI.log(i18n.getMessage('firmwareFlasherNoFirmwareSelected'));
return; return;
} }
@ -982,14 +974,14 @@ firmware_flasher.initialize = function (callback) {
i18n.localizePage(); i18n.localizePage();
} }
var summary = $('select[name="firmware_version"] option:selected').data('summary'); const summary = $('select[name="firmware_version"] option:selected').data('summary');
if (summary) { // undefined while list is loading or while running offline if (summary) { // undefined while list is loading or while running offline
if (self.isConfigLocal && FirmwareCache.has(summary)) { if (self.isConfigLocal && FirmwareCache.has(summary)) {
// Load the .hex from Cache if available when the user is providing their own config. // Load the .hex from Cache if available when the user is providing their own config.
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'cache'); analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'cache');
FirmwareCache.get(summary, cached => { FirmwareCache.get(summary, cached => {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, summary.file); analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, summary.file);
console.info("Release found in cache: " + summary.file); console.info("Release found in cache:", summary.file);
onLoadSuccess(cached.hexdata, summary); onLoadSuccess(cached.hexdata, summary);
}); });
return; return;
@ -1104,7 +1096,7 @@ firmware_flasher.initialize = function (callback) {
if (self.parsed_hex) { if (self.parsed_hex) {
try { try {
if (self.unifiedTarget.config && !self.parsed_hex.configInserted) { if (self.unifiedTarget.config && !self.parsed_hex.configInserted) {
var configInserter = new ConfigInserter(); const configInserter = new ConfigInserter();
if (configInserter.insertConfig(self.parsed_hex, self.unifiedTarget.config)) { if (configInserter.insertConfig(self.parsed_hex, self.unifiedTarget.config)) {
self.parsed_hex.configInserted = true; self.parsed_hex.configInserted = true;
@ -1127,22 +1119,22 @@ firmware_flasher.initialize = function (callback) {
} }
$('span.progressLabel a.save_firmware').click(function () { $('span.progressLabel a.save_firmware').click(function () {
var summary = $('select[name="firmware_version"] option:selected').data('summary'); const summary = $('select[name="firmware_version"] option:selected').data('summary');
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: summary.file, accepts: [{description: 'HEX files', extensions: ['hex']}]}, function (fileEntry) { chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: summary.file, accepts: [{description: 'HEX files', extensions: ['hex']}]}, function (fileEntry) {
if (checkChromeRuntimeError()) { if (checkChromeRuntimeError()) {
return; return;
} }
chrome.fileSystem.getDisplayPath(fileEntry, function (path) { chrome.fileSystem.getDisplayPath(fileEntry, function (path) {
console.log('Saving firmware to: ' + path); console.log('Saving firmware to:', path);
// check if file is writable // check if file is writable
chrome.fileSystem.isWritableEntry(fileEntry, function (isWritable) { chrome.fileSystem.isWritableEntry(fileEntry, function (isWritable) {
if (isWritable) { if (isWritable) {
var blob = new Blob([self.intel_hex], {type: 'text/plain'}); const blob = new Blob([self.intel_hex], {type: 'text/plain'});
fileEntry.createWriter(function (writer) { fileEntry.createWriter(function (writer) {
var truncated = false; let truncated = false;
writer.onerror = function (e) { writer.onerror = function (e) {
console.error(e); console.error(e);
@ -1174,16 +1166,16 @@ firmware_flasher.initialize = function (callback) {
}); });
$('input.flash_on_connect').change(function () { $('input.flash_on_connect').change(function () {
var status = $(this).is(':checked'); const status = $(this).is(':checked');
if (status) { if (status) {
var catch_new_port = function () { const catch_new_port = function () {
PortHandler.port_detected('flash_detected_device', function (result) { PortHandler.port_detected('flash_detected_device', function (result) {
var port = result[0]; const port = result[0];
if (!GUI.connect_lock) { if (!GUI.connect_lock) {
GUI.log(i18n.getMessage('firmwareFlasherFlashTrigger', [port])); GUI.log(i18n.getMessage('firmwareFlasherFlashTrigger', [port]));
console.log('Detected: ' + port + ' - triggering flash on connect'); console.log(`Detected: ${port} - triggering flash on connect`);
// Trigger regular Flashing sequence // Trigger regular Flashing sequence
GUI.timeout_add('initialization_timeout', function () { GUI.timeout_add('initialization_timeout', function () {
@ -1205,7 +1197,7 @@ firmware_flasher.initialize = function (callback) {
}).change(); }).change();
$(document).keypress(function (e) { $(document).keypress(function (e) {
if (e.which == 13) { // enter if (e.which === 13) { // enter
// Trigger regular Flashing sequence // Trigger regular Flashing sequence
$('a.flash_firmware').click(); $('a.flash_firmware').click();
} }
@ -1249,10 +1241,12 @@ firmware_flasher.enableFlashing = function (enabled) {
} }
}; };
firmware_flasher.FLASH_MESSAGE_TYPES = {NEUTRAL : 'NEUTRAL', firmware_flasher.FLASH_MESSAGE_TYPES = {
VALID : 'VALID', NEUTRAL : 'NEUTRAL',
INVALID : 'INVALID', VALID : 'VALID',
ACTION : 'ACTION'}; INVALID : 'INVALID',
ACTION : 'ACTION',
};
firmware_flasher.flashingMessage = function(message, type) { firmware_flasher.flashingMessage = function(message, type) {
let self = this; let self = this;
@ -1276,7 +1270,7 @@ firmware_flasher.flashingMessage = function(message, type) {
progressLabel_e.removeClass('valid invalid actionRequired'); progressLabel_e.removeClass('valid invalid actionRequired');
break; break;
} }
if (message != null) { if (message !== null) {
progressLabel_e.html(message); progressLabel_e.html(message);
} }