Skip to content

Commit 822452a

Browse files
committed
enhance: show inner exception message if possible when check update failed
Signed-off-by: leo <[email protected]>
1 parent 760e448 commit 822452a

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/App.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private void Check4Update(bool manually = false)
532532
catch (Exception e)
533533
{
534534
if (manually)
535-
ShowSelfUpdateResult(e);
535+
ShowSelfUpdateResult(new Models.SelfUpdateFailed(e));
536536
}
537537
});
538538
}

src/Models/Version.cs renamed to src/Models/SelfUpdate.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Reflection;
23
using System.Text.Json.Serialization;
34

45
namespace SourceGit.Models
@@ -32,5 +33,24 @@ public bool IsNewVersion
3233
}
3334
}
3435

35-
public class AlreadyUpToDate { }
36+
public class AlreadyUpToDate
37+
{
38+
}
39+
40+
public class SelfUpdateFailed
41+
{
42+
public string Reason
43+
{
44+
get;
45+
private set;
46+
}
47+
48+
public SelfUpdateFailed(Exception e)
49+
{
50+
if (e.InnerException is { } inner)
51+
Reason = inner.Message;
52+
else
53+
Reason = e.Message;
54+
}
55+
}
3656
}

src/Views/SelfUpdate.axaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xmlns:m="using:SourceGit.Models"
66
xmlns:vm="using:SourceGit.ViewModels"
77
xmlns:v="using:SourceGit.Views"
8-
xmlns:sys="clr-namespace:System;assembly=mscorlib"
98
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
109
x:Class="SourceGit.Views.SelfUpdate"
1110
x:DataType="vm:SelfUpdate"
@@ -87,15 +86,13 @@
8786
</StackPanel>
8887
</DataTemplate>
8988

90-
<DataTemplate DataType="sys:Exception">
89+
<DataTemplate DataType="m:AlreadyUpToDate">
9190
<StackPanel Orientation="Vertical" Margin="16,8">
92-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
93-
<Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
94-
<TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Error}"/>
91+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
92+
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
93+
<TextBlock Margin="8,0,0,0" Text="{DynamicResource Text.SelfUpdate.UpToDate}"/>
9594
</StackPanel>
9695

97-
<TextBlock Text="{Binding Message}" MaxWidth="500" TextWrapping="Wrap" Margin="0,8"/>
98-
9996
<Button Classes="flat primary"
10097
Height="30"
10198
Margin="4,0"
@@ -107,13 +104,15 @@
107104
</StackPanel>
108105
</DataTemplate>
109106

110-
<DataTemplate DataType="m:AlreadyUpToDate">
107+
<DataTemplate DataType="m:SelfUpdateFailed">
111108
<StackPanel Orientation="Vertical" Margin="16,8">
112-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
113-
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
114-
<TextBlock Margin="8,0,0,0" Text="{DynamicResource Text.SelfUpdate.UpToDate}"/>
109+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
110+
<Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
111+
<TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Error}"/>
115112
</StackPanel>
116113

114+
<TextBlock Text="{Binding Reason}" MaxWidth="500" TextWrapping="Wrap" Margin="0,8"/>
115+
117116
<Button Classes="flat primary"
118117
Height="30"
119118
Margin="4,0"

0 commit comments

Comments
 (0)