@@ -212,8 +212,7 @@ setup.initialize = function (callback) {
212212 build_date_e = $ ( ".build-date" ) ,
213213 build_type_e = $ ( ".build-type" ) ,
214214 build_info_e = $ ( ".build-info" ) ,
215- build_firmware_e = $ ( ".build-firmware" ) ,
216- build_options_e = $ ( ".build-options" ) ;
215+ build_firmware_e = $ ( ".build-firmware" ) ;
217216
218217 // DISARM FLAGS
219218 // We add all the arming/disarming flags available, and show/hide them if needed.
@@ -365,90 +364,104 @@ setup.initialize = function (callback) {
365364 }
366365 }
367366
367+ // Gets the build root base URI for build.betaflight.com
368+ const getBuildRootBaseUri = function ( ) {
369+ return `https://build.betaflight.com/api/builds/${ FC . CONFIG . buildKey } ` ;
370+ } ;
371+
372+ // Fills in the "Build info" part of the "Firmware info" box
368373 const showBuildInfo = function ( ) {
369- const supported = FC . CONFIG . buildKey . length === 32 ;
374+ const isIspConnected = ispConnected ( ) ;
375+ const buildKeyValid = FC . CONFIG . buildKey . length === 32 ;
370376
371- if ( supported && ispConnected ( ) ) {
372- const buildRoot = `https://build.betaflight.com/api/builds/ ${ FC . CONFIG . buildKey } ` ;
377+ if ( buildKeyValid && isIspConnected ) {
378+ const buildRoot = getBuildRootBaseUri ( ) ;
373379
380+ // Creates the "Config" button
374381 const buildConfig = `<span class="buildInfoBtn" title="${ i18n . getMessage (
375382 "initialSetupInfoBuildConfig" ,
376383 ) } : ${ buildRoot } /json">
377384 <a href="${ buildRoot } /json" target="_blank"><strong>${ i18n . getMessage (
378385 "initialSetupInfoBuildConfig" ,
379386) } </strong></a></span>`;
380387
388+ // Creates the "Log" button
381389 const buildLog = `<span class="buildInfoBtn" title="${ i18n . getMessage (
382390 "initialSetupInfoBuildLog" ,
383391 ) } : ${ buildRoot } /log">
384392 <a href="${ buildRoot } /log" target="_blank"><strong>${ i18n . getMessage (
385393 "initialSetupInfoBuildLog" ,
386394) } </strong></a></span>`;
387395
396+ // Shows the "Config" and "Log" buttons
388397 build_info_e . html ( `${ buildConfig } ${ buildLog } ` ) ;
389-
390- const buildDownload = `<span class="buildInfoBtn" title="${ i18n . getMessage (
391- "initialSetupInfoBuildDownload" ,
392- ) } : ${ buildRoot } /hex">
393- <a href="${ buildRoot } /hex" target="_blank"><strong>${ i18n . getMessage (
394- "initialSetupInfoBuildDownload" ,
395- ) } </strong></a></span>`;
396-
397- build_firmware_e . html ( buildDownload ) ;
398398 } else {
399399 build_info_e . html (
400- supported ? i18n . getMessage ( "initialSetupNotOnline" ) : i18n . getMessage ( "initialSetupNoBuildInfo" ) ,
401- ) ;
402-
403- build_firmware_e . html (
404- supported ? i18n . getMessage ( "initialSetupNotOnline" ) : i18n . getMessage ( "initialSetupNoBuildInfo" ) ,
400+ isIspConnected
401+ ? i18n . getMessage ( "initialSetupNoBuildInfo" )
402+ : i18n . getMessage ( "initialSetupNotOnline" ) ,
405403 ) ;
406404 }
407405 } ;
408406
409- const showBuildOptions = function ( ) {
410- const supported =
411- ( ( semver . eq ( FC . CONFIG . apiVersion , API_VERSION_1_45 ) && ispConnected ( ) ) ||
407+ // Fills in the "Firmware" part of the "Firmware info" box
408+ const showBuildFirmware = function ( ) {
409+ const isIspConnected = ispConnected ( ) ;
410+ const buildOptionsValid =
411+ ( ( semver . eq ( FC . CONFIG . apiVersion , API_VERSION_1_45 ) && isIspConnected ) ||
412412 semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_46 ) ) &&
413413 FC . CONFIG . buildOptions . length ;
414-
415- if ( supported ) {
416- let buildOptionList = `<div class="dialogBuildInfoGrid-container">` ;
417- for ( const buildOptionElement of FC . CONFIG . buildOptions ) {
418- buildOptionList += `<div class="dialogBuildInfoGrid-item">${ buildOptionElement } </div>` ;
419- }
420- buildOptionList += `</div>` ;
421-
422- build_options_e . html ( `<span class="buildInfoBtn" title="${ i18n . getMessage (
423- "initialSetupInfoBuildOptions" ,
424- ) } ">
425- <a class="buildOptions" href=#"><strong>${ i18n . getMessage (
426- "initialSetupInfoBuildOptionList" ,
427- ) } </strong></a></span>`) ;
428-
429- const buildOptions = `<span class="buildInfoBtn" title="${ i18n . getMessage (
430- "initialSetupInfoBuildOptionList" ,
431- ) } ">
432- <a class="buildOptions" href=#"><strong>${ i18n . getMessage (
414+ const buildKeyValid = FC . CONFIG . buildKey . length === 32 ;
415+ const buildRoot = getBuildRootBaseUri ( ) ;
416+
417+ if ( buildOptionsValid || buildKeyValid ) {
418+ // Creates the "Options" button (if possible)
419+ const buildOptions = buildOptionsValid
420+ ? `<span class="buildInfoBtn" title="${ i18n . getMessage ( "initialSetupInfoBuildOptionList" ) } ">
421+ <a class="buildOptions" href="#"><strong>${ i18n . getMessage (
433422 "initialSetupInfoBuildOptions" ,
434- ) } </strong></a></span>`;
423+ ) } </strong></a></span>`
424+ : "" ;
425+
426+ // Creates the "Download" button (if possible)
427+ const buildDownload = buildKeyValid
428+ ? `<span class="buildInfoBtn" title="${ i18n . getMessage (
429+ "initialSetupInfoBuildDownload" ,
430+ ) } : ${ buildRoot } /hex">
431+ <a href="${ buildRoot } /hex" target="_blank"><strong>${ i18n . getMessage (
432+ "initialSetupInfoBuildDownload" ,
433+ ) } </strong></a></span>`
434+ : "" ;
435435
436- build_options_e . html ( buildOptions ) ;
436+ // Shows the "Options" and/or "Download" buttons
437+ build_firmware_e . html ( `${ buildOptions } ${ buildDownload } ` ) ;
437438
438- $ ( "a.buildOptions" ) . on ( "click" , async function ( ) {
439- showDialogBuildInfo (
440- `<h3>${ i18n . getMessage ( "initialSetupInfoBuildOptionList" ) } </h3>` ,
441- buildOptionList ,
442- ) ;
443- } ) ;
439+ if ( buildOptionsValid ) {
440+ // Creates and attaches the "Options" dialog
441+ let buildOptionList = `<div class="dialogBuildInfoGrid-container">` ;
442+ for ( const buildOptionElement of FC . CONFIG . buildOptions ) {
443+ buildOptionList += `<div class="dialogBuildInfoGrid-item">${ buildOptionElement } </div>` ;
444+ }
445+ buildOptionList += `</div>` ;
446+
447+ $ ( "a.buildOptions" ) . on ( "click" , async function ( ) {
448+ showDialogBuildInfo (
449+ `<h3>${ i18n . getMessage ( "initialSetupInfoBuildOptionList" ) } </h3>` ,
450+ buildOptionList ,
451+ ) ;
452+ } ) ;
453+ }
444454 } else {
445- // should not happen, but just in case
446- build_options_e . html ( `${ i18n . getMessage ( "initialSetupNoBuildInfo" ) } ` ) ;
455+ build_firmware_e . html (
456+ isIspConnected
457+ ? i18n . getMessage ( "initialSetupNoBuildInfo" )
458+ : i18n . getMessage ( "initialSetupNotOnline" ) ,
459+ ) ;
447460 }
448461 } ;
449462
463+ // Fills in the "Firmware info" box
450464 function showFirmwareInfo ( ) {
451- // Firmware info
452465 msp_api_e . text ( FC . CONFIG . apiVersion ) ;
453466 build_date_e . text ( FC . CONFIG . buildInfo ) ;
454467
@@ -459,7 +472,7 @@ setup.initialize = function (callback) {
459472 : i18n . getMessage ( "initialSetupInfoBuildLocal" ) ,
460473 ) ;
461474 showBuildInfo ( ) ;
462- showBuildOptions ( ) ;
475+ showBuildFirmware ( ) ;
463476 }
464477 }
465478
0 commit comments