Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Failsafe for empty Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ElryMoe committed Sep 17, 2024
1 parent dafe45e commit 3a957a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
2 changes: 2 additions & 0 deletions AnilistListConverter.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc7da56581ee7b20208f09e80b735961e4d5d7b9e5562bfdec94a75c57b391_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
27 changes: 0 additions & 27 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ namespace AnilistListConverter;
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

// Add a global exception handler
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
Exception ex = (Exception)args.ExceptionObject;
ShowErrorAndShutdown(ex);
};

// Also catch UI thread exceptions
DispatcherUnhandledException += (sender, args) =>
{
Exception ex = args.Exception;
args.Handled = true;
ShowErrorAndShutdown(ex);
};
}

private void ShowErrorAndShutdown(Exception ex)
{
// Display the error in a message box
MessageBox.Show($"An unexpected error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

// Close the app after the user clicks OK
Environment.Exit(1);
}
}

10 changes: 9 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ private async void MoveLists(bool direction)
var pagination = new AniPaginationOptions(page, 500);

var mediaEntryCollection = await aniClient.GetUserEntryCollectionAsync(user.Id, originalType, pagination);

if (mediaEntryCollection.Lists.Length <= 0)
{
Confirm.Width = 500;
Confirm.Content = "No Entries found.";
Confirm.Background = new SolidColorBrush(Colors.Coral);
return;
}

List<MediaEntry> entries = new List<MediaEntry>();

Expand All @@ -143,7 +151,7 @@ private async void MoveLists(bool direction)
if (entries.Count <= 0)
{
Confirm.Width = 500;
Confirm.Content = "Could not find User Lists.";
Confirm.Content = "No Entries found.";
Confirm.Background = new SolidColorBrush(Colors.Coral);
return;
}
Expand Down

0 comments on commit 3a957a7

Please sign in to comment.