diff --git a/TarkovMonitor/MainBlazorUI.cs b/TarkovMonitor/MainBlazorUI.cs index 811cf00..41a4733 100644 --- a/TarkovMonitor/MainBlazorUI.cs +++ b/TarkovMonitor/MainBlazorUI.cs @@ -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(); } @@ -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 { @@ -486,6 +491,7 @@ private async Task InitializeProgress() catch (Exception ex) { messageLog.AddMessage($"Error updating progress: {ex.Message}"); + return; } } diff --git a/TarkovMonitor/TarkovTracker.cs b/TarkovMonitor/TarkovTracker.cs index c96d344..0aa78b9 100644 --- a/TarkovMonitor/TarkovTracker.cs +++ b/TarkovMonitor/TarkovTracker.cs @@ -35,7 +35,7 @@ internal interface ITarkovTrackerAPI { AuthorizationHeaderValueGetter = (rq, cr) => { return Task.Run(() => { - return tokens[currentProfile]; + return GetToken(currentProfile); }); }, } @@ -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); @@ -77,6 +77,10 @@ public static void SetToken(string profileId, string token) public static async Task 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;