mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 03:19:54 +03:00
Fix "save downloaded firmware"
This commit is contained in:
parent
2c7f8d6cb2
commit
324d700afa
3 changed files with 21 additions and 44 deletions
|
@ -182,9 +182,9 @@ TABS.cli.initialize = function (callback) {
|
|||
if (err) {
|
||||
GUI.log(i18n.getMessage('ErrorWritingFile'));
|
||||
return console.error(err);
|
||||
}
|
||||
GUI.log(i18n.getMessage('FileSaved'));
|
||||
}
|
||||
});
|
||||
GUI.log(i18n.getMessage('FileSaved'));
|
||||
|
||||
}).catch (err => {
|
||||
console.log(err);
|
||||
|
|
|
@ -32,7 +32,8 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
|
||||
var intel_hex = false, // standard intel hex in string format
|
||||
parsed_hex = false; // parsed raw hex in array format
|
||||
parsed_hex = false, // parsed raw hex in array format
|
||||
fileName = "inav.hex";
|
||||
|
||||
GUI.load(path.join(__dirname, "firmware_flasher.html"), function () {
|
||||
// translate to user-selected language
|
||||
|
@ -474,6 +475,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
var summary = $('select[name="firmware_version"] option:selected').data('summary');
|
||||
if (summary) { // undefined while list is loading or while running offline
|
||||
fileName = summary.file;
|
||||
$(".load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoading')).addClass('disabled');
|
||||
$.get(summary.url, function (data) {
|
||||
enable_load_online_button();
|
||||
|
@ -539,47 +541,22 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
|
||||
$(document).on('click', 'span.progressLabel a.save_firmware', function () {
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'inav', accepts: [{extensions: ['hex']}]}, function (fileEntry) {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(chrome.runtime.lastError.message);
|
||||
var options = {
|
||||
defaultPath: fileName,
|
||||
filters: [ {name: "Intel-Hex", extensions: ['hex'] } ]
|
||||
};
|
||||
dialog.showSaveDialog(options).then(result => {
|
||||
if (result.canceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.fileSystem.getDisplayPath(fileEntry, function (path) {
|
||||
console.log('Saving firmware to: ' + path);
|
||||
|
||||
// check if file is writable
|
||||
chrome.fileSystem.isWritableEntry(fileEntry, function (isWritable) {
|
||||
if (isWritable) {
|
||||
var blob = new Blob([intel_hex], {type: 'text/plain'});
|
||||
|
||||
fileEntry.createWriter(function (writer) {
|
||||
var truncated = false;
|
||||
|
||||
writer.onerror = function (e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
writer.onwriteend = function() {
|
||||
if (!truncated) {
|
||||
// onwriteend will be fired again when truncation is finished
|
||||
truncated = true;
|
||||
writer.truncate(blob.size);
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
writer.write(blob);
|
||||
}, function (e) {
|
||||
console.error(e);
|
||||
});
|
||||
} else {
|
||||
console.log('You don\'t have write permissions for this file, sorry.');
|
||||
GUI.log(i18n.getMessage('writePermissionsForFile'));
|
||||
}
|
||||
});
|
||||
fs.writeFileSync(result.filePath, intel_hex, (err) => {
|
||||
if (err) {
|
||||
GUI.log(i18n.getMessage('ErrorWritingFile'));
|
||||
return console.error(err);
|
||||
}
|
||||
});
|
||||
let sFilename = String(result.filePath.split('\\').pop().split('/').pop());
|
||||
GUI.log(sFilename + i18n.getMessage('savedSuccessfully'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -4029,10 +4029,10 @@ TABS.mission_control.initialize = function (callback) {
|
|||
GUI.log(i18n.getMessage('ErrorWritingFile'));
|
||||
return console.error(err);
|
||||
}
|
||||
let sFilename = String(filename.split('\\').pop().split('/').pop());
|
||||
GUI.log(sFilename + i18n.getMessage('savedSuccessfully'));
|
||||
updateFilename(sFilename);
|
||||
});
|
||||
let sFilename = String(filename.split('\\').pop().split('/').pop());
|
||||
GUI.log(sFilename + i18n.getMessage('savedSuccessfully'));
|
||||
updateFilename(sFilename);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue