mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:20:06 +00:00 
			
		
		
		
	Update map provider setting based on API key availability
This commit is contained in:
		
							parent
							
								
									9c5de8e9ee
								
							
						
					
					
						commit
						6c5ec2d996
					
				
					 1 changed files with 41 additions and 0 deletions
				
			
		|  | @ -23,6 +23,7 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| static boost::json::value ConvertSettingsToJson(); | ||||
| static void               GenerateDefaultSettings(); | ||||
| static bool               LoadSettings(const boost::json::object& settingsJson); | ||||
| static void               ValidateSettings(); | ||||
| 
 | ||||
| static bool        initialized_ {false}; | ||||
| static std::string settingsPath_ {}; | ||||
|  | @ -46,6 +47,7 @@ void Initialize() | |||
|    initialized_  = true; | ||||
| 
 | ||||
|    ReadSettings(settingsPath_); | ||||
|    ValidateSettings(); | ||||
| } | ||||
| 
 | ||||
| void ReadSettings(const std::string& settingsPath) | ||||
|  | @ -137,6 +139,45 @@ static bool LoadSettings(const boost::json::object& settingsJson) | |||
|    return jsonDirty; | ||||
| } | ||||
| 
 | ||||
| static void ValidateSettings() | ||||
| { | ||||
|    logger_->debug("Validating settings"); | ||||
| 
 | ||||
|    bool settingsChanged = false; | ||||
| 
 | ||||
|    auto& generalSettings = general_settings(); | ||||
| 
 | ||||
|    // Validate map provider
 | ||||
|    std::string mapProvider    = generalSettings.map_provider().GetValue(); | ||||
|    std::string mapboxApiKey   = generalSettings.mapbox_api_key().GetValue(); | ||||
|    std::string maptilerApiKey = generalSettings.maptiler_api_key().GetValue(); | ||||
| 
 | ||||
|    if (mapProvider == "maptiler" && //
 | ||||
|        mapboxApiKey.size() > 1 &&   //
 | ||||
|        maptilerApiKey == "?") | ||||
|    { | ||||
|       logger_->info("Setting Map Provider to Mapbox based on API key settings"); | ||||
| 
 | ||||
|       generalSettings.map_provider().SetValue("mapbox"); | ||||
|       settingsChanged = true; | ||||
|    } | ||||
|    else if (mapProvider == "mapbox" &&   //
 | ||||
|             maptilerApiKey.size() > 1 && //
 | ||||
|             mapboxApiKey == "?") | ||||
|    { | ||||
|       logger_->info( | ||||
|          "Setting Map Provider to MapTiler based on API key settings"); | ||||
| 
 | ||||
|       generalSettings.map_provider().SetValue("maptiler"); | ||||
|       settingsChanged = true; | ||||
|    } | ||||
| 
 | ||||
|    if (settingsChanged) | ||||
|    { | ||||
|       SaveSettings(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| } // namespace SettingsManager
 | ||||
| } // namespace manager
 | ||||
| } // namespace qt
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat