Skip to content

Commit

Permalink
Set erase_chip as default option when not set before
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Jan 2, 2024
1 parent 6577697 commit ba15112
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 6 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,11 @@ export function get(key) {
}
}

// if default value is set and key is not found in localStorage, set default value
if (!result[key] && defaultValue !== null) {
result[key] = defaultValue;
}

return result;
}

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

function cleanupLocalStorage() {

// storage quota is 5MB, we need to clean up some stuff (more info see PR #2937)
const cleanupLocalStorageList = [
'cache',
'firmware',
'https',
'selected_board',
'unifiedConfigLast',
'unifiedSourceCache',
'erase_chip',
];

for (const key in localStorage) {
Expand Down
8 changes: 2 additions & 6 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,8 @@ firmware_flasher.initialize = function (callback) {
self.isFlashing = false;
}

let result = getConfig('erase_chip');
if (result.erase_chip) {
$('input.erase_chip').prop('checked', true);
} else {
$('input.erase_chip').prop('checked', false);
}
let result = getConfig('erase_chip', true);
$('input.erase_chip').prop('checked', result.erase_chip);

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

0 comments on commit ba15112

Please sign in to comment.