feature<*>: upgrade to .NET 5.0; use System.Text.Json instead of System.Xml; supports auto check update at startup

This commit is contained in:
leo 2020-12-01 10:31:46 +08:00
parent 1a46551a77
commit 4cde777b98
18 changed files with 300 additions and 80 deletions

View file

@ -1,5 +1,4 @@
<Window x:Class="SourceGit.UI.About"
x:Name="me"
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"
@ -67,7 +66,7 @@
</StackPanel>
<Label Grid.Row="1" Content="SourceGit - OPEN SOURCE GIT CLIENT" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" FontSize="18" FontWeight="Bold"/>
<Label Grid.Row="2" Content="{Binding ElementName=me, Path=Version}" HorizontalContentAlignment="Center" FontSize="11"/>
<Label Grid.Row="2" x:Name="version" HorizontalContentAlignment="Center" FontSize="11"/>
<Label Grid.Row="3" HorizontalContentAlignment="Center" FontSize="11">
<Hyperlink RequestNavigate="OpenSource" NavigateUri="https://gitee.com/sourcegit/SourceGit.git">

View file

@ -10,21 +10,14 @@ namespace SourceGit.UI {
/// </summary>
public partial class About : Window {
/// <summary>
/// Current app version
/// </summary>
public string Version {
get {
Assembly asm = Assembly.GetExecutingAssembly();
return "VERSION : " + asm.GetName().Version;
}
}
/// <summary>
/// Constructor
/// </summary>
public About() {
InitializeComponent();
var asm = Assembly.GetExecutingAssembly().GetName();
version.Content = $"VERSION : v{asm.Version.Major}.{asm.Version.Minor}";
}
/// <summary>
@ -33,7 +26,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenSource(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
Process.Start(new ProcessStartInfo("cmd", $"/c start {e.Uri.AbsoluteUri}") { CreateNoWindow = true });
e.Handled = true;
}

View file

@ -93,7 +93,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight,
new Typeface(blame.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0,
Brushes.Black);
Brushes.Black,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
var lineNumberWidth = formatted.Width + 16;
var minWidth = area.ActualWidth - lineNumberWidth;

View file

@ -473,7 +473,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0,
Brushes.Black);
Brushes.Black,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
return formatted.Width + 16;
}

View file

@ -42,8 +42,8 @@ namespace SourceGit.UI {
public static List<InteractiveRebaseModeInfo> Supported = new List<InteractiveRebaseModeInfo>() {
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Pick, "Pick", "Use this commit", Brushes.Green),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Reword, "Reword", "Edit the commit message", Brushes.Yellow),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Drop, "Drop", "Remove commit", Brushes.Red),
};
}

View file

@ -10,7 +10,7 @@
Title="Source Git"
Width="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowWidth, Mode=TwoWay}"
Height="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowHeight, Mode=TwoWay}"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterOwner">
<!-- Enable WindowChrome Feature -->
<WindowChrome.WindowChrome>

View file

@ -1,4 +1,10 @@
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -45,6 +51,8 @@ namespace SourceGit.UI {
InitializeComponent();
openedTabs.SelectedItem = Tabs[0];
if (App.Preference.CheckUpdate) Task.Run(CheckUpdate);
}
/// <summary>
@ -76,6 +84,33 @@ namespace SourceGit.UI {
openedTabs.SelectedItem = tab;
}
/// <summary>
/// Checking for update.
/// </summary>
public void CheckUpdate() {
try {
var web = new WebClient();
var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/SourceGit/releases/latest");
var ver = JsonSerializer.Deserialize<Git.Version>(raw);
var cur = Assembly.GetExecutingAssembly().GetName().Version;
var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*");
if (!matches.Success) return;
var major = int.Parse(matches.Groups[1].Value);
var minor = int.Parse(matches.Groups[2].Value);
if (major > cur.Major || (major == cur.Major && minor > cur.Minor)) {
Dispatcher.Invoke(() => {
var dialog = new UpdateAvailable(ver);
dialog.Owner = this;
dialog.Show();
});
}
} catch {
// IGNORE
}
}
#region LAYOUT_CONTENT
/// <summary>
/// Context menu for tab items.

View file

@ -8,7 +8,7 @@
xmlns:app="clr-namespace:SourceGit"
xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d"
Height="520" Width="500"
Height="548" Width="500"
Title="Preference"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
@ -61,6 +61,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="18"/>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
@ -78,24 +79,30 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition MinWidth="200" Width="*"/>
<ColumnDefinition Width="136"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 显示 -->
<Label Grid.Row="0" Grid.ColumnSpan="2" Content="APPEARANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<!-- 通用 -->
<Label Grid.Row="0" Grid.ColumnSpan="2" Content="GENERAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="1" Grid.Column="0" Content="Light Theme :" HorizontalAlignment="Right"/>
<CheckBox
Grid.Row="1"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UIUseLightTheme, Mode=TwoWay}"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UseLightTheme, Mode=TwoWay}"
Content="Restart required"
TextElement.FontStyle="Italic"/>
<Label Grid.Row="2" Grid.Column="0" Content="Check for Update :" HorizontalAlignment="Right"/>
<CheckBox
Grid.Row="2"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=CheckUpdate, Mode=TwoWay}"
TextElement.FontStyle="Italic"/>
<!-- GIT相关配置 -->
<Label Grid.Row="3" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="4" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="4" Grid.Column="1">
<Label Grid.Row="4" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="5" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="5" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -110,8 +117,8 @@
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<Label Grid.Row="5" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/>
<Grid Grid.Row="5" Grid.Column="1">
<Label Grid.Row="6" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/>
<Grid Grid.Row="6" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -128,13 +135,13 @@
</Grid>
<!-- Global User -->
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="10" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="10" Grid.Column="1"
<Label Grid.Row="8" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="9" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="10" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="10" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="11" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="11" Grid.Column="1"
x:Name="cmbAutoCRLF"
Height="24"
HorizontalAlignment="Stretch"
@ -151,9 +158,9 @@
</ComboBox>
<!-- 合并工具配置 -->
<Label Grid.Row="12" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="13" Grid.Column="0" Content="Merger :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="13" Grid.Column="1"
<Label Grid.Row="13" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="14" Grid.Column="0" Content="Merger :" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="14" Grid.Column="1"
Height="24"
Padding="2,0,0,0"
HorizontalContentAlignment="Left"
@ -162,8 +169,8 @@
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
DisplayMemberPath="Name"
SelectionChanged="ChangeMergeTool"/>
<Label Grid.Row="14" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="14" Grid.Column="1">
<Label Grid.Row="15" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid Grid.Row="15" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -178,8 +185,8 @@
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<Label Grid.Row="15" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="15" Grid.Column="1"
<Label Grid.Row="16" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="16" Grid.Column="1"
x:Name="txtMergeParam"
VerticalAlignment="Center"
Foreground="{StaticResource Brush.FG2}"/>

102
src/UI/UpdateAvailable.xaml Normal file
View file

@ -0,0 +1,102 @@
<Window x:Class="SourceGit.UI.UpdateAvailable"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="Consolas"
Height="400" Width="500">
<!-- Enable WindowChrome Feature -->
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="32"/>
</WindowChrome.WindowChrome>
<!-- Window Layout -->
<Border Background="{StaticResource Brush.BG1}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Titlebar -->
<Grid Grid.Row="0" Background="{StaticResource Brush.BG4}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- LOGO -->
<Path Width="20" Height="20" Margin="6,-1,2,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Fetch}"/>
<!-- Title -->
<Label Grid.Column="1" Content="UPDATE AVAILABLE" FontWeight="Light"/>
<!-- Close Button -->
<Button Click="Quit" Width="32" Grid.Column="3" WindowChrome.IsHitTestVisibleInChrome="True">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource Style.Button.HighlightHover}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Close}"/>
</Button>
</Grid>
<Grid Grid.Row="1" Margin="8">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="8"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="20" Height="20" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}" Fill="#FFF05133"/>
<Label x:Name="txtRelease" Content="Release 2.1 available!" FontSize="18" FontWeight="Bold"/>
</StackPanel>
<Label Grid.Row="2" Grid.Column="0" Content="Publish Time :" HorizontalAlignment="Right"/>
<Label Grid.Row="2" Grid.Column="1" x:Name="txtTime" Content="2020/11/30 00:00:00"/>
<Label Grid.Row="3" Grid.Column="0" Content="Base On Commit :" HorizontalAlignment="Right"/>
<Label Grid.Row="3" Grid.Column="1" x:Name="txtBasedOn" Content="724908ea"/>
<Label Grid.Row="4" Grid.Column="0" Content="Is Pre-release :" HorizontalAlignment="Right"/>
<Label Grid.Row="4" Grid.Column="1" x:Name="txtPrerelease" Content="NO"/>
<Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Margin="6,6,6,0" BorderBrush="{StaticResource Brush.BG4}" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock FontSize="10pt"
FontFamily="Consolas"
Padding="8"
Opacity="0.8"
Background="{StaticResource Brush.BG2}"
Foreground="{StaticResource Brush.FG}"
x:Name="txtChangeLog"/>
</ScrollViewer>
</Border>
<StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8,0,0">
<Button Width="80" Height="24" Style="{StaticResource Style.Button.AccentBordered}" Content="DOWNLOAD" Click="Download"/>
<Button Width="80" Margin="8,0,0,0" Height="24" Style="{StaticResource Style.Button.Bordered}" Content="CANCEL" Click="Quit"/>
</StackPanel>
</Grid>
</Grid>
</Border>
</Window>

View file

@ -0,0 +1,46 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Navigation;
namespace SourceGit.UI {
/// <summary>
/// Interaction logic for UpdateAvailable.xaml
/// </summary>
public partial class UpdateAvailable : Window {
private string tag = null;
/// <summary>
/// Constructor
/// </summary>
/// <param name="version"></param>
public UpdateAvailable(Git.Version version) {
InitializeComponent();
txtRelease.Content = $"{version.Name} is available!";
txtTime.Content = version.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
txtBasedOn.Content = version.CommitSHA.Substring(0, 10);
txtPrerelease.Content = version.PreRelease ? "YES" : "NO";
txtChangeLog.Text = version.Body;
tag = version.TagName;
}
/// <summary>
/// Open source code link
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Download(object sender, RoutedEventArgs e) {
Process.Start(new ProcessStartInfo("cmd", $"/c start https://gitee.com/sourcegit/SourceGit/releases/{tag}") { CreateNoWindow = true });
e.Handled = true;
}
/// <summary>
/// Close this dialog
/// </summary>
private void Quit(object sender, RoutedEventArgs e) {
Close();
}
}
}