Skip to content

Commit

Permalink
Only try to set EDSM credentials when they are actually needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkael committed Jan 1, 2023
1 parent 0f9d397 commit da0800c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion EDSMResponder/ConfigurationWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Utilities;

namespace EddiEdsmResponder
{
Expand Down Expand Up @@ -75,7 +76,7 @@ private async void edsmObtainLogClicked(object sender, RoutedEventArgs e)
edsmFetchLogsButton.Content = Properties.EDSMResources.log_button_fetching;

var progress = new Progress<string>(s => edsmFetchLogsButton.Content = s);
IEdsmService edsmService = new StarMapService();
IEdsmService edsmService = new StarMapService(null, true);
await Task.Factory.StartNew(() => obtainEdsmLogs(edsmService, progress), TaskCreationOptions.LongRunning);

starMapConfiguration.lastFlightLogSync = DateTime.UtcNow;
Expand Down Expand Up @@ -107,6 +108,7 @@ public static void obtainEdsmLogs(IEdsmService edsmService, IProgress<string> pr
catch (EDSMException edsme)
{
progress.Report(Properties.EDSMResources.log_button_error_received + edsme.Message);
Logging.Warn(Properties.EDSMResources.log_button_error_received + edsme.Message, edsme);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion EDSMResponder/EDSMResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string ResponderDescription()
return Properties.EDSMResources.desc;
}

public EDSMResponder() : this(new StarMapService())
public EDSMResponder() : this(new StarMapService(null, true))
{ }

public EDSMResponder(IEdsmService edsmService)
Expand Down
2 changes: 1 addition & 1 deletion NavigationMonitor/NavigationMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ private async void GetBookmarkExtras<T>(ObservableCollection<T> bookmarks) where
}).ToList();
var visitedBookmarkSystems = await Task.Run(() =>
{
return new DataProviderService(new StarMapService())
return new DataProviderService(new StarMapService(null, true))
.syncFromStarMapService(bookmarkSystems)
.Where(s => s.visits > 0);
}).ConfigureAwait(false);
Expand Down
9 changes: 6 additions & 3 deletions StarMapService/StarMapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ IRestResponse<T> IEdsmRestClient.Execute<T>(IRestRequest request)
}
}

public StarMapService(IEdsmRestClient restClient = null)
public StarMapService(IEdsmRestClient restClient = null, bool needsCredentials = false)
{
this.restClient = restClient ?? new EdsmRestClient(baseUrl);

// Set up EDSM API credentials
SetEdsmCredentials();
if (needsCredentials)
{
// Set up EDSM API credentials
SetEdsmCredentials();
}
}

public void SetEdsmCredentials()
Expand Down
2 changes: 1 addition & 1 deletion VoiceAttackResponder/VoiceAttackPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ public static void InvokeStarMapSystemComment(ref dynamic vaProxy)
StarSystemSqLiteRepository.Instance.SaveStarSystem(currentSystem);

// Store in EDSM
IEdsmService edsmService = new StarMapService();
IEdsmService edsmService = new StarMapService(null, true);
edsmService.sendStarMapComment(currentSystemName, comment);
}
}
Expand Down

0 comments on commit da0800c

Please sign in to comment.