Skip to content

Commit 8e6d00a

Browse files
authored
Add assistance for OSD selection (#4385)
* Add assistance for OSD selection * cleanup * improve * refactor
1 parent eb825c5 commit 8e6d00a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

locales/en/messages.json

+12
Original file line numberDiff line numberDiff line change
@@ -7584,6 +7584,18 @@
75847584
"firmwareFlasherBuildCustomDefines": {
75857585
"message": "Custom Defines"
75867586
},
7587+
"firmwareFlasherOSDProtocolNotSelected": {
7588+
"message": "OSD protocol not selected"
7589+
},
7590+
"firmwareFlasherOSDProtocolNotSelectedDescription": {
7591+
"message": "You must select an OSD protocol to build a firmware."
7592+
},
7593+
"firmwareFlasherOSDProtocolSelect": {
7594+
"message": "Select OSD protocol"
7595+
},
7596+
"firmwareFlasherOSDProtocolNotSelectedContinue": {
7597+
"message": "Continue without OSD protocol"
7598+
},
75877599
"coreBuild": {
75887600
"message": "Core Only"
75897601
},

src/js/tabs/firmware_flasher.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ firmware_flasher.initialize = function (callback) {
241241
}
242242
}
243243

244+
function updateOsdProtocolColor() {
245+
const osdProtocol = $('select[name="osdProtocols"] option:selected').val();
246+
$('select[name="osdProtocols"]')
247+
.next(".select2-container")
248+
.find(".select2-selection__rendered")
249+
.attr("style", osdProtocol === "" ? "color: red !important" : "");
250+
}
251+
244252
function buildOptions(data) {
245253
if (!ispConnected()) {
246254
return;
@@ -267,6 +275,12 @@ firmware_flasher.initialize = function (callback) {
267275
buildOptionsList($('select[name="options"]'), data.generalOptions);
268276
buildOptionsList($('select[name="motorProtocols"]'), data.motorProtocols);
269277

278+
// Using setTimeout to ensure this runs after Select2 has finished initializing/rendering
279+
setTimeout(updateOsdProtocolColor, 0);
280+
281+
// Add change handler to update color when selection changes
282+
$('select[name="osdProtocols"]').on("change", updateOsdProtocolColor);
283+
270284
if (!self.validateBuildKey()) {
271285
preselectRadioProtocolFromStorage();
272286
}
@@ -838,11 +852,35 @@ firmware_flasher.initialize = function (callback) {
838852
self.cancelBuild = true;
839853
});
840854

841-
$("a.load_remote_file").on("click", function (evt) {
855+
async function enforceOSDSelection() {
856+
if ($('select[name="osdProtocols"] option:selected').val() === "") {
857+
return new Promise((resolve) => {
858+
GUI.showYesNoDialog({
859+
title: i18n.getMessage("firmwareFlasherOSDProtocolNotSelected"),
860+
text: i18n.getMessage("firmwareFlasherOSDProtocolNotSelectedDescription"),
861+
buttonYesText: i18n.getMessage("firmwareFlasherOSDProtocolNotSelectedContinue"),
862+
buttonNoText: i18n.getMessage("firmwareFlasherOSDProtocolSelect"),
863+
buttonYesCallback: () => resolve(true),
864+
buttonNoCallback: () => resolve(false),
865+
});
866+
});
867+
} else {
868+
return true; // No issue with OSD selection
869+
}
870+
}
871+
872+
$("a.load_remote_file").on("click", async function (evt) {
842873
if (!self.selectedBoard) {
843874
return;
844875
}
845876

877+
// Ensure the user has selected an OSD protocol
878+
const shouldContinue = await enforceOSDSelection();
879+
880+
if (!shouldContinue) {
881+
return;
882+
}
883+
846884
// Reset button when loading a new firmware
847885
self.enableFlashButton(false);
848886
self.enableLoadRemoteFileButton(false);

0 commit comments

Comments
 (0)