Skip to content

Commit

Permalink
Enable erase_chip by default (betaflight#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis authored and chmelevskij committed Apr 27, 2024
1 parent 1130fe8 commit d7710f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/js/ConfigStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {string | string[]} key string or array of strings
* @returns {object}
*/
export function get(key) {
export function get(key, defaultValue = null) {
let result = {};
if (Array.isArray(key)) {
key.forEach(function (element) {
Expand All @@ -24,6 +24,12 @@ export function get(key) {
}
}

// if default value is set and key is not found in localStorage, set default value
if (!Object.keys(result).length && defaultValue !== null) {
console.log('setting default value for', key, defaultValue);
result[key] = defaultValue;
}

return result;
}

Expand Down
4 changes: 3 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function readConfiguratorVersionMetadata() {
}

function cleanupLocalStorage() {

// storage quota is 5MB, we need to clean up some stuff (more info see PR #2937)
const cleanupLocalStorageList = [
'cache',
'firmware',
Expand All @@ -83,6 +83,8 @@ function cleanupLocalStorage() {
}
}
}

setConfig({'erase_chip': true}); // force erase chip on first run
}

function appReady() {
Expand Down
6 changes: 1 addition & 5 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ firmware_flasher.initialize = function (callback) {
}

let result = getConfig('erase_chip');
if (result.erase_chip) {
$('input.erase_chip').prop('checked', true);
} else {
$('input.erase_chip').prop('checked', false);
}
$('input.erase_chip').prop('checked', result.erase_chip); // users can override this during the session

$('input.erase_chip').change(function () {
setConfig({'erase_chip': $(this).is(':checked')});
Expand Down

0 comments on commit d7710f6

Please sign in to comment.