From 583b1b9f160a92df7b1ea9d39ddc46bf28a7949b Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Mon, 29 Aug 2022 17:09:15 -0700 Subject: [PATCH] (#494) Refresh the sources from file each time Sometimes (it looks like maybe when the Chocolatey Licensed Extension is in play) we don't get the sources currently in the configuration file. If instead of reusing the configuration settings service we instantiate a new one each time, then it will ensure the configuration file is read again. This resolves the issue of settings not applying in GUI if they're made while GUI is running. --- .../Services/ChocolateyService.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs b/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs index 39397d53c..fb28b0e7b 100644 --- a/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs +++ b/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs @@ -37,7 +37,6 @@ public class ChocolateyService : IChocolateyService private static readonly AsyncReaderWriterLock Lock = new AsyncReaderWriterLock(); private readonly IMapper _mapper; private readonly IProgressService _progressService; - private readonly IChocolateyConfigSettingsService _configSettingsService; private readonly IXmlService _xmlService; private readonly IFileSystem _fileSystem; private readonly IConfigService _configService; @@ -46,11 +45,10 @@ public class ChocolateyService : IChocolateyService #pragma warning disable SA1401 // Fields must be private #pragma warning restore SA1401 // Fields must be private - public ChocolateyService(IMapper mapper, IProgressService progressService, IChocolateyConfigSettingsService configSettingsService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService) + public ChocolateyService(IMapper mapper, IProgressService progressService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService) { _mapper = mapper; _progressService = progressService; - _configSettingsService = configSettingsService; _xmlService = xmlService; _fileSystem = fileSystem; _configService = configService; @@ -497,8 +495,8 @@ public async Task GetSources() // we need to read all information from the config file, i.e. the username and password var config = await GetConfigFile(); var allSources = config.Sources.Select(_mapper.Map).ToArray(); - - var filteredSourceIds = _configSettingsService.source_list(_choco.GetConfiguration()).Select(s => s.Id).ToArray(); + var configSettingsService = new ChocolateyConfigSettingsService(_xmlService); + var filteredSourceIds = configSettingsService.source_list(_choco.GetConfiguration()).Select(s => s.Id).ToArray(); var mappedSources = allSources.Where(s => filteredSourceIds.Contains(s.Id)).ToArray(); return mappedSources;