Skip to content

Commit

Permalink
fix exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Dec 22, 2024
1 parent 752215d commit 95d40cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
5 changes: 3 additions & 2 deletions Totoro.Core/DefaultExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void OnError(Exception error)

public void OnNext(Exception value)
{

}
this.Log().Error(value, "Unhandled Exception");
_viewService.UnhandledException(value);
}
}
}
4 changes: 2 additions & 2 deletions Totoro.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private void OnExit(object sender, EventArgs e)

private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
NativeMethods.AllowSleep();
this.Log().Fatal(e.Exception, e.Message);
RxApp.DefaultExceptionHandler.OnError(e.Exception);
e.Handled = true;
}

protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
Expand Down
24 changes: 16 additions & 8 deletions Totoro.WinUI/Helpers/Converters.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.UI;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using MonoTorrent.Client;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Totoro.Core.Services;
using Totoro.Plugins;
using Totoro.Plugins.Anime.Contracts;
Expand Down Expand Up @@ -249,13 +249,21 @@ public static ImageSource StreamToImage(Stream stream)

public static ImageSource StringToImage(string uri)
{
if(string.IsNullOrEmpty(uri))
if (string.IsNullOrEmpty(uri))
{
return null;
}

return new BitmapImage(new Uri(uri));
}
try
{
return new BitmapImage(new Uri(uri));
}
catch
{

return null;
}
}


public static string ToOneBasedIndex(int number) => (number + 1).ToString();
Expand Down
27 changes: 14 additions & 13 deletions Totoro.WinUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,54 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:help="using:Totoro.WinUI.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:Totoro.WinUI.Views"
xmlns:winex="using:WinUIEx" xmlns:help="using:Totoro.WinUI.Helpers"
xmlns:winex="using:WinUIEx"
mc:Ignorable="d">
<winex:WindowEx.SystemBackdrop>
<MicaBackdrop Kind="BaseAlt" />
</winex:WindowEx.SystemBackdrop>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TitleBar
x:Name="TitleBar"
Title="Totoro"
Grid.Row="0"
BackRequested="TitleBar_BackRequested"
IsBackButtonVisible="True"
IsBackEnabled="{x:Bind Shell.ViewModel.IsBackEnabled, Mode=OneWay}"
IsPaneToggleButtonVisible="True"
PaneToggleRequested="TitleBar_PaneToggleRequested"
BackRequested="TitleBar_BackRequested"
Subtitle="{x:Bind Shell.Version}"
Grid.Row="0">
Subtitle="{x:Bind Shell.Version}">
<TitleBar.IconSource>
<ImageIconSource ImageSource="/Assets/WindowIcon.png"/>
<ImageIconSource ImageSource="/Assets/WindowIcon.png" />
</TitleBar.IconSource>
<TitleBar.Footer>
<Button
Width="32"
Height="32"
Padding="0"
BorderBrush="{ThemeResource CircleElevationBorderBrush}"
HorizontalAlignment="Right"
BorderBrush="{ThemeResource CircleElevationBorderBrush}"
CornerRadius="16"
ToolTipService.ToolTip="{x:Bind Shell.ViewModel.User.Name, Mode=OneWay}"
Visibility="{x:Bind help:Converters.BooleanToVisibility(Shell.ViewModel.IsAuthenticated), Mode=OneWay}">
<PersonPicture
Width="32"
Height="32"
DisplayName="{x:Bind Shell.ViewModel.User.Name, Mode=OneWay}"
ProfilePicture="{x:Bind help:Converters.StringToImage(Shell.ViewModel.User.Name)}"/>
DisplayName="{x:Bind Shell.ViewModel.User.Name, Mode=OneWay}"
ProfilePicture="{x:Bind help:Converters.StringToImage(Shell.ViewModel.User.Image), Mode=OneWay}" />
</Button>
</TitleBar.Footer>
</TitleBar>
<views:ShellPage Grid.Row="1" x:Name="Shell"/>

<views:ShellPage x:Name="Shell" Grid.Row="1" />

</Grid>
</winex:WindowEx>

0 comments on commit 95d40cd

Please sign in to comment.