@@ -52,6 +52,7 @@ def __init__(self, iface: QgisInterface) -> None:
5252 """
5353 self .dialog = ORStoolsDialog .ORStoolsDialogMain (iface )
5454 self .provider = provider .ORStoolsProvider ()
55+ self .settings_keys = ["ENV_VARS" , "base_url" , "key" , "name" , "endpoints" , "profiles" ]
5556
5657 # initialize plugin directory
5758 self .plugin_dir = os .path .dirname (__file__ )
@@ -74,10 +75,7 @@ def __init__(self, iface: QgisInterface) -> None:
7475 except TypeError :
7576 pass
7677
77- try :
78- configmanager .read_config ()["providers" ]
79- except (TypeError , KeyError ):
80- self .add_default_provider_to_settings ()
78+ self .update_settings ()
8179
8280 def initGui (self ) -> None :
8381 """Create the menu entries and toolbar icons inside the QGIS GUI."""
@@ -90,24 +88,21 @@ def unload(self) -> None:
9088 QgsApplication .processingRegistry ().removeProvider (self .provider )
9189 self .dialog .unload ()
9290
93- def add_default_provider_to_settings (self ):
94- s = QgsSettings ()
95- settings = s .value ("ORStools/config" )
91+ def update_settings (self ):
92+ settings = configmanager .read_config ()
9693
97- settings_keys = ["ENV_VARS" , "base_url" , "key" , "name" , "endpoints" , "profiles" ]
94+ if settings is not None and settings != {}:
95+ endpoints = settings .get ("endpoints" , ENDPOINTS )
96+ profiles = settings .get ("profiles" , PROFILES )
9897
99- # Add any new settings here for backwards compatibility
100- if settings :
10198 changed = False
10299 for i , prov in enumerate (settings ["providers" ]):
103- if any ([i not in prov for i in settings_keys ]):
100+ if any ([key not in prov for key in self . settings_keys ]):
104101 changed = True
105- # Add here, like the endpoints
106- prov ["endpoints" ] = ENDPOINTS
107- settings ["providers" ][i ] = prov
108- prov ["profiles" ] = PROFILES
102+ prov ["endpoints" ] = endpoints
103+ prov ["profiles" ] = profiles
109104 settings ["providers" ][i ] = prov
110105 if changed :
111- s . setValue ( "ORStools/config" , settings )
106+ configmanager . write_config ( settings )
112107 else :
113- s . setValue ( "ORStools/config" , DEFAULT_SETTINGS )
108+ configmanager . write_config ( DEFAULT_SETTINGS )
0 commit comments