enhance: show inner exception message if possible when check update failed

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-18 15:55:32 +08:00
parent 760e44877b
commit 822452a20c
No known key found for this signature in database
3 changed files with 43 additions and 24 deletions

View file

@ -532,7 +532,7 @@ namespace SourceGit
catch (Exception e)
{
if (manually)
ShowSelfUpdateResult(e);
ShowSelfUpdateResult(new Models.SelfUpdateFailed(e));
}
});
}

View file

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
using System.Text.Json.Serialization;
namespace SourceGit.Models
@ -32,5 +33,24 @@ namespace SourceGit.Models
}
}
public class AlreadyUpToDate { }
public class AlreadyUpToDate
{
}
public class SelfUpdateFailed
{
public string Reason
{
get;
private set;
}
public SelfUpdateFailed(Exception e)
{
if (e.InnerException is { } inner)
Reason = inner.Message;
else
Reason = e.Message;
}
}
}

View file

@ -5,7 +5,6 @@
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.SelfUpdate"
x:DataType="vm:SelfUpdate"
@ -87,26 +86,6 @@
</StackPanel>
</DataTemplate>
<DataTemplate DataType="sys:Exception">
<StackPanel Orientation="Vertical" Margin="16,8">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
<TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Error}"/>
</StackPanel>
<TextBlock Text="{Binding Message}" MaxWidth="500" TextWrapping="Wrap" Margin="0,8"/>
<Button Classes="flat primary"
Height="30"
Margin="4,0"
Click="CloseWindow"
Content="{DynamicResource Text.Close}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="m:AlreadyUpToDate">
<StackPanel Orientation="Vertical" Margin="16,8">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
@ -124,6 +103,26 @@
VerticalContentAlignment="Center"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="m:SelfUpdateFailed">
<StackPanel Orientation="Vertical" Margin="16,8">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
<TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Error}"/>
</StackPanel>
<TextBlock Text="{Binding Reason}" MaxWidth="500" TextWrapping="Wrap" Margin="0,8"/>
<Button Classes="flat primary"
Height="30"
Margin="4,0"
Click="CloseWindow"
Content="{DynamicResource Text.Close}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</Grid>