From 4a9251f1747b28058492cfc533e71ce46744811c Mon Sep 17 00:00:00 2001 From: Ivan Efimov Date: Sun, 21 May 2023 16:32:15 -0500 Subject: [PATCH] [10.9-maintenance] Simplify Expert Mode (#3301) (#3454) --- locales/en/messages.json | 5 +---- src/js/main.js | 18 +++++++++--------- src/js/serial_backend.js | 6 ++---- src/js/tabs/firmware_flasher.js | 29 ++++++++++++++++------------- src/js/tabs/options.js | 16 ---------------- src/tabs/firmware_flasher.html | 30 +++++++++++++++--------------- src/tabs/options.html | 6 ------ 7 files changed, 43 insertions(+), 67 deletions(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 53147684..2016c2a5 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -90,10 +90,7 @@ "message": "Enable Expert Mode" }, "expertModeDescription": { - "message": "Show development builds that are potentially unstable" - }, - "permanentExpertMode": { - "message": "Permanently enable Expert Mode" + "message": "Enable Expert Mode options" }, "warningSettings": { "message": "Show warnings" diff --git a/src/js/main.js b/src/js/main.js index 61f15078..d674b2ed 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -539,14 +539,14 @@ function startProcess() { $("#showlog").trigger('click'); } - result = getConfig('permanentExpertMode'); - const expertModeCheckbox = 'input[name="expertModeCheckbox"]'; - if (result.permanentExpertMode) { - $(expertModeCheckbox).prop('checked', true); - } + result = getConfig('expertMode').expertMode ?? false; + + const expertModeCheckbox = $('input[name="expertModeCheckbox"]'); + expertModeCheckbox.prop('checked', result).trigger('change'); + + expertModeCheckbox.on("change", () => { + const checked = expertModeCheckbox.is(':checked'); - $(expertModeCheckbox).on("change", () => { - const checked = $(expertModeCheckbox).is(':checked'); checkSetupAnalytics(function (analyticsService) { analyticsService.setDimension(analyticsService.DIMENSIONS.CONFIGURATOR_EXPERT_MODE, checked ? 'On' : 'Off'); }); @@ -558,9 +558,9 @@ function startProcess() { if (GUI.active_tab) { TABS[GUI.active_tab]?.expertModeChanged?.(checked); } - }); - $(expertModeCheckbox).trigger("change"); + setConfig({'expertMode': checked}); + }); result = getConfig('cliAutoComplete'); CliAutoComplete.setEnabled(typeof result.cliAutoComplete === "undefined" || result.cliAutoComplete); // On by default diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 621344e4..49053baa 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -259,10 +259,8 @@ function onOpen(openInfo) { } // reset expert mode - result = getConfig('permanentExpertMode'); - if (result.permanentExpertMode) { - $('input[name="expertModeCheckbox"]').prop('checked', result.permanentExpertMode).trigger('change'); - } + result = getConfig('expertMode')?.expertMode ?? false; + $('input[name="expertModeCheckbox"]').prop('checked', result).trigger('change'); serial.onReceive.addListener(read_serial); setConnectionTimeout(); diff --git a/src/js/tabs/firmware_flasher.js b/src/js/tabs/firmware_flasher.js index e08b3a91..dd72d0b7 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -221,35 +221,39 @@ firmware_flasher.initialize = function (callback) { if (showExtraReleases) { $('tr.build_type').show(); - $('tr.expert_mode').show(); } else { $('tr.build_type').hide(); - $('tr.expert_mode').hide(); buildType_e.val(0).trigger('change'); } } - const globalExpertMode_e = $('input[name="expertModeCheckbox"]'); function showOrHideExpertMode() { const expertModeChecked = $(this).is(':checked'); - globalExpertMode_e.prop('checked', expertModeChecked).trigger('change'); if (expertModeChecked) { buildTypesToShow = buildTypes; } else { buildTypesToShow = buildTypes.slice(0,2); } + buildBuildTypeOptionsList(); buildType_e.val(0).trigger('change'); - setConfig({'selected_expert_mode': expertModeChecked}); + setTimeout(() => { + $('tr.expertOptions').toggle(expertModeChecked); + $('div.expertOptions').toggle(expertModeChecked); + }, 0); + + setConfig({'expertMode': expertModeChecked}); } const expertMode_e = $('.tab-firmware_flasher input.expert_mode'); - const expertMode = getConfig('selected_expert_mode'); - expertMode_e.prop('checked', expertMode.selected_expert_mode ?? false); + const expertMode = getConfig('expertMode').expertMode; + + expertMode_e.prop('checked', expertMode); + expertMode_e.on('change', showOrHideExpertMode).trigger('change'); + $('input.show_development_releases').change(showOrHideBuildTypes).change(); - expertMode_e.change(showOrHideExpertMode).change(); // translate to user-selected language i18n.localizePage(); @@ -302,8 +306,6 @@ firmware_flasher.initialize = function (callback) { const expertMode = $('.tab-firmware_flasher input.expert_mode').is(':checked'); if (expertMode) { - $('div.expertOptions').show(); - if (response.releaseType === 'Unstable') { self.releaseLoader.loadCommits(response.release, (commits) => { const select_e = $('select[name="commits"]'); @@ -317,9 +319,9 @@ firmware_flasher.initialize = function (callback) { } else { $('div.commitSelection').hide(); } - } else { - $('div.expertOptions').hide(); } + + $('div.expertOptions').toggle(expertMode); } if (response.configuration && !self.isConfigLocal) { @@ -472,11 +474,12 @@ firmware_flasher.initialize = function (callback) { } const portPickerElement = $('div#port-picker #port'); + function flashFirmware(firmware) { const options = {}; let eraseAll = false; - if ($('input.erase_chip').is(':checked')) { + if ($('input.erase_chip').is(':checked') || $('.tab-firmware_flasher input.expert_mode').not(':checked')) { options.erase_chip = true; eraseAll = true; diff --git a/src/js/tabs/options.js b/src/js/tabs/options.js index ff1bc7e0..a6ec2869 100644 --- a/src/js/tabs/options.js +++ b/src/js/tabs/options.js @@ -16,7 +16,6 @@ options.initialize = function (callback) { $('#content').load("./tabs/options.html", function () { i18n.localizePage(); - TABS.options.initPermanentExpertMode(); TABS.options.initRememberLastTab(); TABS.options.initCheckForConfiguratorUnstableVersions(); TABS.options.initAnalyticsOptOut(); @@ -50,21 +49,6 @@ options.initShowWarnings = function () { }).change(); }; -options.initPermanentExpertMode = function () { - const result = getConfig('permanentExpertMode'); - if (result.permanentExpertMode) { - $('div.permanentExpertMode input').prop('checked', true); - } - - $('div.permanentExpertMode input').change(function () { - const checked = $(this).is(':checked'); - - setConfig({'permanentExpertMode': checked}); - - $('input[name="expertModeCheckbox"]').prop('checked', checked).change(); - }).change(); -}; - options.initRememberLastTab = function () { const result = getConfig('rememberLastTab'); $('div.rememberLastTab input') diff --git a/src/tabs/firmware_flasher.html b/src/tabs/firmware_flasher.html index d70653db..6869f652 100644 --- a/src/tabs/firmware_flasher.html +++ b/src/tabs/firmware_flasher.html @@ -8,17 +8,6 @@
- - - - + + + + - + - + - + - +
- -
-
-
+ +
+
+