Skip to content

Commit

Permalink
Make backup on flash an option
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Feb 25, 2025
1 parent 80e5770 commit c3120c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
25 changes: 3 additions & 22 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"storageDeviceNotReady": {
"message": "The storage device is not ready. In the case of a microSD card, make sure it is properly recognised by your flight controller."
},
"options_title": {
"message": "Application Options"
},
"connect": {
"message": "Connect"
},
Expand Down Expand Up @@ -3827,25 +3824,6 @@
"unstableFirmwareAcknowledgementFlash": {
"message": "Flash"
},
"firmwareFlasherPreviousDevice": {
"message": "Detected: <strong>$1</strong> - previous device still flashing, please replug to try again"
},
"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"
},
"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 Expand Up @@ -7170,6 +7148,9 @@
"cliAutoComplete": {
"message": "Advanced CLI AutoComplete"
},
"firmwareBackupOnFlash": {
"message": "Create a backup before flashing new target"
},
"darkTheme": {
"message": "Enable dark theme"
},
Expand Down
27 changes: 9 additions & 18 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,26 +1107,17 @@ firmware_flasher.initialize = function (callback) {
}
}

// Backup not available in DFU, manual or virtual mode.
// When flash on connect is enabled, the backup dialog is not shown.
if (isFlashOnConnect || !(PortHandler.portAvailable || GUI.connect_lock)) {
// 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) {
initiateFlashing();
} else {
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,
// prevent connection while backup is in progress
GUI.connect_lock = true;
AutoBackup.execute(() => {
GUI.connect_lock = false;
initiateFlashing();
});
}
});
Expand Down
11 changes: 11 additions & 0 deletions src/js/tabs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ options.initialize = function (callback) {
TABS.options.initUserLanguage();
TABS.options.initShowWarnings();
TABS.options.initMeteredConnection();
TABS.options.initBackupOnFlash();

GUI.content_ready(callback);
});
Expand Down Expand Up @@ -256,6 +257,16 @@ options.initMeteredConnection = function () {
.trigger("change");
};

options.initBackupOnFlash = function () {
const result = getConfig("backupOnFlash", true);
$("div.backupOnFlash input")
.prop("checked", !!result.backupOnFlash)
.on("change", function () {
setConfig({ backupOnFlash: $(this).is(":checked") });
})
.trigger("change");
};

options.initUserLanguage = function () {
const userLanguage = i18n.selectedLanguage;
const userLanguageElement = $("#userLanguage");
Expand Down
6 changes: 6 additions & 0 deletions src/tabs/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
</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

0 comments on commit c3120c2

Please sign in to comment.