Skip to content

Commit

Permalink
Alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Feb 26, 2025
1 parent 22b4896 commit ccb7ce9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 21 deletions.
25 changes: 25 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3824,6 +3824,31 @@
"unstableFirmwareAcknowledgementFlash": {
"message": "Flash"
},
"firmwareFlasherRemindBackupTitle": {
"message": "Wipe out settings",
"description": "Warning message title before actual flashing takes place"
},
"firmwareFlasherRemindBackup": {
"message": "Flashing new firmware will wipe out all settings. We strongly recommend to save a backup before continuing.",
"description": "Warning message before actual flashing takes place"
},
"firmwareFlasherBackup": {
"message": "Create Backup",
"description": "Create a backup before actual flashing takes place"
},
"firmwareFlasherBackupIgnore": {
"message": "Ignore the risk",
"description": "Ignore creating a backup before actual flashing takes place"
},
"firmwareBackupEnabled": {
"message": "Backup enabled"
},
"firmwareBackupDisabled": {
"message": "Backup disabled"
},
"firmwareBackupAsk": {
"message": "Ask before backup"
},
"ledStripHelp": {
"message": "The flight controller can control colors and effects of individual LEDs on a strip.<br />Configure LEDs on the grid, configure wiring order then attach LEDs on your aircraft according to grid positions. LEDs without wire ordering number will not be saved.<br />Double-click on a color to edit the HSV values."
},
Expand Down
4 changes: 3 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ function cleanupLocalStorage() {
}

setConfig({ erase_chip: true }); // force erase chip on first run
setConfig({ backupOnFlash: true }); // force backup on flash on first run
if (getConfig("backupOnFlash") === undefined) {
setConfig({ backupOnFlash: "1" }); // force backup on flash on first run
}
}

function appReady() {
Expand Down
61 changes: 50 additions & 11 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,15 +1090,20 @@ firmware_flasher.initialize = function (callback) {
});

$("a.flash_firmware").on("click", function () {
if (GUI.connect_lock) {
return;
}

self.isFlashing = true;
GUI.interval_pause("sponsor");
const isFlashOnConnect = $("input.flash_on_connect").is(":checked");

self.enableFlashButton(false);
self.enableDfuExitButton(false);
self.enableLoadRemoteFileButton(false);
self.enableLoadFileButton(false);

const isFlashOnConnect = $("input.flash_on_connect").is(":checked");

function initiateFlashing() {
if (self.developmentFirmwareLoaded && !isFlashOnConnect) {
checkShowAcknowledgementDialog();
Expand All @@ -1107,18 +1112,52 @@ firmware_flasher.initialize = function (callback) {
}
}

// Backup not available in DFU, manual, virtual mode or when using flash on connect const backupOnFlash = getConfig("backupOnFlash");
const noPortOrLock = !PortHandler.portAvailable && !GUI.connect_lock;
const backupOnFlash = getConfig("backupOnFlash").backupOnFlash;
if (isFlashOnConnect || !backupOnFlash || noPortOrLock) {
// Backup not available in DFU, manual, virtual mode or when using flash on connect

if (isFlashOnConnect || !PortHandler.portAvailable) {
initiateFlashing();
} else {
// prevent connection while backup is in progress
GUI.connect_lock = true;
AutoBackup.execute(() => {
GUI.connect_lock = false;
initiateFlashing();
});
// backupOnFlash:
// 0: disabled
// 1: backup without dialog
// 2: backup with dialog

const backupOnFlash = getConfig("backupOnFlash").backupOnFlash;

switch (backupOnFlash) {
case 0:
initiateFlashing();
break;
case 1:
// prevent connection while backup is in progress
GUI.connect_lock = true;
AutoBackup.execute(() => {
GUI.connect_lock = false;
initiateFlashing();
});
break;
case 2:
GUI.showYesNoDialog({
title: i18n.getMessage("firmwareFlasherRemindBackupTitle"),
text: i18n.getMessage("firmwareFlasherRemindBackup"),
buttonYesText: i18n.getMessage("firmwareFlasherBackup"),
buttonNoText: i18n.getMessage("firmwareFlasherBackupIgnore"),
buttonYesCallback: () => {
// prevent connection while backup is in progress
GUI.connect_lock = true;
AutoBackup.execute(() => {
GUI.connect_lock = false;
initiateFlashing();
});
},

buttonNoCallback: initiateFlashing,
});
break;
default:
initiateFlashing();
break;
}
}
});

Expand Down
9 changes: 6 additions & 3 deletions src/js/tabs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,13 @@ options.initMeteredConnection = function () {

options.initBackupOnFlash = function () {
const result = getConfig("backupOnFlash");
$("div.backupOnFlash input")
.prop("checked", !!result.backupOnFlash)
console.log(result.backupOnFlash);
$("#backupOnFlashSelect")
.val(result.backupOnFlash)
.on("change", function () {
setConfig({ backupOnFlash: $(this).is(":checked") });
const value = parseInt($(this).val());

setConfig({ backupOnFlash: value });
})
.trigger("change");
};
Expand Down
14 changes: 8 additions & 6 deletions src/tabs/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
</div>
<span class="freelabel" i18n="cliAutoComplete"></span>
</div>
<div class="backupOnFlash margin-bottom">
<div>
<input type="checkbox" class="toggle" />
</div>
<span class="freelabel" i18n="firmwareBackupOnFlash"></span>
</div>
<div class="showAllSerialDevices margin-bottom">
<div>
<input type="checkbox" class="toggle" />
Expand Down Expand Up @@ -94,6 +88,14 @@
</div>
<span class="freelabel" i18n="showNotifications"></span>
</div>
<div class="backupOnFlash margin-bottom">
<select id="backupOnFlashSelect">
<option value="0" i18n="firmwareBackupDisabled"></option>
<option value="1" i18n="firmwareBackupEnabled"></option>
<option value="2" i18n="firmwareBackupAsk"></option>
</select>
<span class="freelabel" i18n="firmwareBackupOnFlash"></span>
</div>
<div class="userLanguage">
<span class="dropdown">
<select class="dropdown-select" id="userLanguage"
Expand Down

0 comments on commit ccb7ce9

Please sign in to comment.