Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable erase_chip by default #3701

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -575,11 +575,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);
blckmn marked this conversation as resolved.
Show resolved Hide resolved
}
$('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