1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-20 06:45:11 +03:00

Fix local firmware loader after NW version increase

This commit is contained in:
Pawel Spychalski (DzikuVx) 2021-04-26 09:44:42 +02:00
parent 4fcef09216
commit 05af37a8af

View file

@ -1,3 +1,4 @@
/*global $,nwdialog*/
'use strict'; 'use strict';
TABS.firmware_flasher = {}; TABS.firmware_flasher = {};
@ -184,57 +185,41 @@ TABS.firmware_flasher.initialize = function (callback) {
$('select[name="release"]').empty().append('<option value="0">Offline</option>'); $('select[name="release"]').empty().append('<option value="0">Offline</option>');
}); });
// UI Hooks $('a.load_file').on('click', function () {
$('a.load_file').click(function () {
chrome.fileSystem.chooseEntry({type: 'openFile', accepts: [{extensions: ['hex']}]}, function (fileEntry) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return; nwdialog.setContext(document);
} nwdialog.openFileDialog('.hex', function(filename) {
const fs = require('fs');
// hide github info (if it exists)
$('div.git_info').slideUp(); $('div.git_info').slideUp();
chrome.fileSystem.getDisplayPath(fileEntry, function (path) { console.log('Loading file from: ' + filename);
console.log('Loading file from: ' + path);
fileEntry.file(function (file) { fs.readFile(filename, (err, data) => {
var reader = new FileReader();
reader.onprogress = function (e) { if (err) {
if (e.total > 104857600) { // 100 MB console.log("Error loading local file", err);
// dont allow reading files bigger then 100 MB return;
console.log('File limit (100 MB) exceeded, aborting'); }
reader.abort();
}
};
reader.onloadend = function(e) { console.log('File loaded');
if (e.total != 0 && e.total == e.loaded) {
console.log('File loaded');
intel_hex = e.target.result; parse_hex(data.toString(), function (data) {
parsed_hex = data;
parse_hex(intel_hex, function (data) { if (parsed_hex) {
parsed_hex = data; googleAnalytics.sendEvent('Flashing', 'Firmware', 'local');
$('a.flash_firmware').removeClass('disabled');
if (parsed_hex) { $('span.progressLabel').text('Loaded Local Firmware: (' + parsed_hex.bytes_total + ' bytes)');
googleAnalytics.sendEvent('Flashing', 'Firmware', 'local'); } else {
$('a.flash_firmware').removeClass('disabled'); $('span.progressLabel').text(chrome.i18n.getMessage('firmwareFlasherHexCorrupted'));
}
$('span.progressLabel').text('Loaded Local Firmware: (' + parsed_hex.bytes_total + ' bytes)');
} else {
$('span.progressLabel').text(chrome.i18n.getMessage('firmwareFlasherHexCorrupted'));
}
});
}
};
reader.readAsText(file);
}); });
}); });
}); });
}); });
/** /**