@@ -508,7 +508,7 @@ TABS.firmware_flasher.initialize = function (callback) {
508508
509509 function setUnifiedConfig ( target , bareBoard , targetConfig , manufacturerId , fileName , fileUrl , date ) {
510510 // a target might request a firmware with the same name, remove configuration in this case.
511- if ( bareBoard == target ) {
511+ if ( bareBoard === target ) {
512512 self . unifiedTarget = { } ;
513513 } else {
514514 self . unifiedTarget . config = targetConfig ;
@@ -610,31 +610,32 @@ TABS.firmware_flasher.initialize = function (callback) {
610610 $ . get ( unifiedConfig . download_url , function ( targetConfig ) {
611611 console . log ( 'got unified config' ) ;
612612
613- const bareBoard = grabBuildNameFromConfig ( targetConfig ) ;
614- TABS . firmware_flasher . bareBoard = bareBoard ;
613+ let config = cleanUnifiedConfigFile ( targetConfig ) ;
614+ if ( config !== null ) {
615+ const bareBoard = grabBuildNameFromConfig ( config ) ;
616+ TABS . firmware_flasher . bareBoard = bareBoard ;
615617
616- self . gitHubApi . getFileLastCommitInfo ( 'betaflight/unified-targets' , 'master' , unifiedConfig . path , function ( commitInfo ) {
617- targetConfig = self . injectTargetInfo ( targetConfig , target , manufacturerId , commitInfo ) ;
618+ self . gitHubApi . getFileLastCommitInfo ( 'betaflight/unified-targets' , 'master' , unifiedConfig . path , function ( commitInfo ) {
619+ config = self . injectTargetInfo ( config , target , manufacturerId , commitInfo ) ;
618620
619- setUnifiedConfig ( target , bareBoard , targetConfig , manufacturerId , unifiedConfig . name , unifiedConfig . download_url , commitInfo . date ) ;
621+ setUnifiedConfig ( target , bareBoard , config , manufacturerId , unifiedConfig . name , unifiedConfig . download_url , commitInfo . date ) ;
620622
621- // cache it for later
622- let newStorageObj = { } ;
623- newStorageObj [ storageTag ] = {
624- unifiedTarget : self . unifiedTarget ,
625- targetId : targetId ,
626- lastUpdate : checkTime ,
627- } ;
628- chrome . storage . local . set ( newStorageObj ) ;
623+ // cache it for later
624+ let newStorageObj = { } ;
625+ newStorageObj [ storageTag ] = {
626+ unifiedTarget : self . unifiedTarget ,
627+ targetId : targetId ,
628+ lastUpdate : checkTime ,
629+ } ;
630+ chrome . storage . local . set ( newStorageObj ) ;
629631
630- populateBuilds ( builds , target , manufacturerId , duplicateName , TABS . firmware_flasher . releases [ bareBoard ] , processNext ) ;
631- } ) ;
632+ populateBuilds ( builds , target , manufacturerId , duplicateName , TABS . firmware_flasher . releases [ bareBoard ] , processNext ) ;
633+ } ) ;
634+ } else {
635+ failLoading ( unifiedConfig . download_url ) ;
636+ }
632637 } ) . fail ( xhr => {
633- //TODO error, populate nothing?
634- self . unifiedTarget = { } ;
635- self . isConfigLocal = false ;
636- const baseFileName = unifiedConfig . download_url ;
637- GUI . log ( i18n . getMessage ( 'firmwareFlasherFailedToLoadUnifiedConfig' , { remote_file : baseFileName } ) ) ;
638+ failLoading ( unifiedConfig . download_url ) ;
638639 } ) ;
639640 } else {
640641 console . log ( 'We have the config cached for' , targetId ) ;
@@ -663,6 +664,14 @@ TABS.firmware_flasher.initialize = function (callback) {
663664 }
664665 } ) ;
665666
667+ function failLoading ( downloadUrl ) {
668+ //TODO error, populate nothing?
669+ self . unifiedTarget = { } ;
670+ self . isConfigLocal = false ;
671+
672+ GUI . log ( i18n . getMessage ( 'firmwareFlasherFailedToLoadUnifiedConfig' , { remote_file : downloadUrl } ) ) ;
673+ }
674+
666675 function flashingMessageLocal ( ) {
667676 // used by the a.load_file hook, evaluate the loaded information, and enable flashing if suitable
668677 if ( self . isConfigLocal && ! self . parsed_hex ) {
@@ -689,8 +698,9 @@ TABS.firmware_flasher.initialize = function (callback) {
689698 inComment = true ;
690699 }
691700 if ( ! inComment && input . charCodeAt ( i ) > 255 ) {
692- // Note: we're not showing this error in betaflight-configurator
693- throw new Error ( 'commands are limited to characters 0-255, comments have no limitation' ) ;
701+ self . flashingMessage ( i18n . getMessage ( 'firmwareFlasherConfigCorrupted' ) , self . FLASH_MESSAGE_TYPES . INVALID ) ;
702+ GUI . log ( i18n . getMessage ( 'firmwareFlasherConfigCorruptedLogMessage' ) ) ;
703+ return null ;
694704 }
695705 if ( input . charCodeAt ( i ) > 255 ) {
696706 output . push ( '_' ) ;
@@ -875,14 +885,14 @@ TABS.firmware_flasher.initialize = function (callback) {
875885 } ) ;
876886 } else {
877887 clearBufferedFirmware ( ) ;
878- try {
879- self . unifiedTarget . config = cleanUnifiedConfigFile ( e . target . result ) ;
888+
889+ let config = cleanUnifiedConfigFile ( e . target . result ) ;
890+ if ( config !== null ) {
891+ config = self . injectTargetInfo ( config , file . name , 'UNKN' , { commitHash : 'unknown' , date : file . lastModifiedDate . toISOString ( ) } ) ;
892+ self . unifiedTarget . config = config ;
880893 self . unifiedTarget . fileName = file . name ;
881894 self . isConfigLocal = true ;
882895 flashingMessageLocal ( ) ;
883- } catch ( err ) {
884- self . flashingMessage ( i18n . getMessage ( 'firmwareFlasherConfigCorrupted' ) , self . FLASH_MESSAGE_TYPES . INVALID ) ;
885- GUI . log ( i18n . getMessage ( 'firmwareFlasherConfigCorruptedLogMessage' ) ) ;
886896 }
887897 }
888898 }
0 commit comments