Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure profileId is set when testing API token #77

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading