Skip to content

Commit

Permalink
Add error handling for LastSwitchedUsername setting
Browse files Browse the repository at this point in the history
Added a using directive for FastAccountSwitcher.CLI.Services in MainViewModel.cs.
Implemented a try-catch block in MainViewModel to handle exceptions when accessing Settings.Default.LastSwitchedUsername, logging errors and resetting settings if necessary.
Removed unused using directive for System.Windows.Threading in MainWindow.xaml.cs.
  • Loading branch information
patrickiel committed Oct 3, 2024
1 parent 83cd67f commit df2ec89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/FastAccountSwitcher.GUI/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows.Controls;

using FastAccountSwitcher.CLI.Services;
using FastAccountSwitcher.GUI.Properties;

namespace FastAccountSwitcher.GUI;
Expand Down Expand Up @@ -90,7 +91,32 @@ public void UltraFastSwitch()
return Accounts[0];
}

var lastSwitchedUsername = Settings.Default.LastSwitchedUsername;
string? lastSwitchedUsername = null;
try
{
lastSwitchedUsername = Settings.Default.LastSwitchedUsername;
}
catch (Exception ex)
{
LoggingService.LogException(ex);
LoggingService.LogInfo("Resetting settings");
Settings.Default.Reset();
Settings.Default.Save();

// probably need to delete "%localappdata%\Fast_Account_Switcher" folder?

try
{
lastSwitchedUsername = Settings.Default.LastSwitchedUsername;
}
catch (Exception ex2)
{
LoggingService.LogException(ex2);
LoggingService.LogInfo("Resetting settings failed");
return null;
}
}

if (string.IsNullOrEmpty(lastSwitchedUsername))
{
return null;
Expand Down
1 change: 0 additions & 1 deletion src/FastAccountSwitcher.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Threading;

using Hardcodet.Wpf.TaskbarNotification;

Expand Down

0 comments on commit df2ec89

Please sign in to comment.