Skip to content

Commit

Permalink
Merge pull request #77 from Owaan/fix-error-on-test-api-token
Browse files Browse the repository at this point in the history
Ensure profileId is set when testing API token
  • Loading branch information
Razzmatazzz authored May 29, 2024
2 parents 4aa40bd + 8d5b00c commit e6131e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
24 changes: 15 additions & 9 deletions TarkovMonitor/MainBlazorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public MainBlazorUI()
{
if (Properties.Settings.Default.tarkovTrackerToken != "")
{
TarkovTracker.SetToken(e.Profile.Id, Properties.Settings.Default.tarkovTrackerToken);
try {
TarkovTracker.SetToken(e.Profile.Id, Properties.Settings.Default.tarkovTrackerToken);
} catch (Exception ex) {
messageLog.AddMessage($"Error setting token from previously saved settings {ex.Message}", "exception");
}

Properties.Settings.Default.tarkovTrackerToken = "";
Properties.Settings.Default.Save();
}
Expand Down Expand Up @@ -460,20 +465,20 @@ private async Task UpdateHideoutStations()

private async Task InitializeProgress()
{
if (TarkovTracker.GetToken(eft.CurrentProfile.Id) == "")
{
messageLog.AddMessage("To automatically track task progress, set your Tarkov Tracker token in Settings");
return;
}
messageLog.AddMessage($"Using {eft.CurrentProfile.Type} profile");
try
{
await TarkovTracker.SetProfile(eft.CurrentProfile.Id);
return;
}
catch (Exception ex)
{
messageLog.AddMessage($"Error getting Tarkov Tracker progress: {ex.Message}");
messageLog.AddMessage($"Profile does not exist: {ex.Message}");
return;
}
messageLog.AddMessage($"Using {eft.CurrentProfile.Type} profile");
if (TarkovTracker.GetToken(eft.CurrentProfile.Id) == "")
{
messageLog.AddMessage("To automatically track task progress, set your Tarkov Tracker token in Settings");
return;
}
try
{
Expand All @@ -486,6 +491,7 @@ private async Task InitializeProgress()
catch (Exception ex)
{
messageLog.AddMessage($"Error updating progress: {ex.Message}");
return;
}
}

Expand Down
8 changes: 6 additions & 2 deletions TarkovMonitor/TarkovTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal interface ITarkovTrackerAPI
{
AuthorizationHeaderValueGetter = (rq, cr) => {
return Task.Run<string>(() => {
return tokens[currentProfile];
return GetToken(currentProfile);
});
},
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public static void SetToken(string profileId, string token)
{
if (profileId == "")
{
return;
throw new Exception("No PVP or PVE profile initialised, please launch Escape from Tarkov first");
}
tokens[profileId] = token;
Properties.Settings.Default.tarkovTrackerTokens = JsonSerializer.Serialize(tokens);
Expand All @@ -77,6 +77,10 @@ public static void SetToken(string profileId, string token)

public static async Task<ProgressResponse> SetProfile(string profileId)
{
if (profileId == "") {
throw new Exception("Can't set PVP or PVE profile, please launch Escape from Tarkov and then restart this application");
}

if (currentProfile == profileId)
{
return Progress;
Expand Down

0 comments on commit e6131e5

Please sign in to comment.