1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-20 14:55:14 +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,39 +185,26 @@ 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);
nwdialog.setContext(document);
nwdialog.openFileDialog('.hex', function(filename) {
const fs = require('fs');
$('div.git_info').slideUp();
console.log('Loading file from: ' + filename);
fs.readFile(filename, (err, data) => {
if (err) {
console.log("Error loading local file", err);
return; return;
} }
// hide github info (if it exists)
$('div.git_info').slideUp();
chrome.fileSystem.getDisplayPath(fileEntry, function (path) {
console.log('Loading file from: ' + path);
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onprogress = function (e) {
if (e.total > 104857600) { // 100 MB
// dont allow reading files bigger then 100 MB
console.log('File limit (100 MB) exceeded, aborting');
reader.abort();
}
};
reader.onloadend = function(e) {
if (e.total != 0 && e.total == e.loaded) {
console.log('File loaded'); console.log('File loaded');
intel_hex = e.target.result; parse_hex(data.toString(), function (data) {
parse_hex(intel_hex, function (data) {
parsed_hex = data; parsed_hex = data;
if (parsed_hex) { if (parsed_hex) {
@ -228,13 +216,10 @@ TABS.firmware_flasher.initialize = function (callback) {
$('span.progressLabel').text(chrome.i18n.getMessage('firmwareFlasherHexCorrupted')); $('span.progressLabel').text(chrome.i18n.getMessage('firmwareFlasherHexCorrupted'));
} }
}); });
} });
};
reader.readAsText(file);
});
});
}); });
}); });
/** /**