Skip to content

Commit

Permalink
Fix "save downloaded firmware"
Browse files Browse the repository at this point in the history
  • Loading branch information
Scavanger committed Nov 20, 2024
1 parent 2c7f8d6 commit 324d700
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
4 changes: 2 additions & 2 deletions tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 16 additions & 39 deletions tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
});
});

Expand Down
6 changes: 3 additions & 3 deletions tabs/mission_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/////////////////////////////////////////////
Expand Down

0 comments on commit 324d700

Please sign in to comment.