optimize<Upgrade>: remove auto-upgrade feature

This commit is contained in:
leo 2022-10-18 15:30:24 +08:00
parent d827c1fbe1
commit b76bc96ee7
7 changed files with 0 additions and 238 deletions

View file

@ -73,12 +73,6 @@ namespace SourceGit {
// 主界面显示 // 主界面显示
MainWindow = launcher; MainWindow = launcher;
MainWindow.Show(); MainWindow.Show();
// 检测版本更新
Models.Version.Check(ver => Dispatcher.Invoke(() => {
var dialog = new Views.Upgrade(ver) { Owner = MainWindow };
dialog.ShowDialog();
}));
} }
/// <summary> /// <summary>

View file

@ -63,16 +63,6 @@ namespace SourceGit.Models {
/// </summary> /// </summary>
public bool UseDarkTheme { get; set; } = true; public bool UseDarkTheme { get; set; } = true;
/// <summary>
/// 启用更新检测
/// </summary>
public bool CheckForUpdate { get; set; } = true;
/// <summary>
/// 上一次检测的时间(用于控制每天仅第一次启动软件时,检测)
/// </summary>
public int LastCheckDay { get; set; } = 0;
/// <summary> /// <summary>
/// 起始页仓库列表排序规则 /// 起始页仓库列表排序规则
/// </summary> /// </summary>

View file

@ -1,69 +0,0 @@
using System;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Net.Http;
namespace SourceGit.Models {
/// <summary>
/// Github开放API中Release信息格式
/// </summary>
public class Version {
[JsonPropertyName("id")]
public ulong Id { get; set; }
[JsonPropertyName("tag_name")]
public string TagName { get; set; }
[JsonPropertyName("target_commitish")]
public string CommitSHA { get; set; }
[JsonPropertyName("prerelease")]
public bool PreRelease { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("body")]
public string Body { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
public string PublishTime {
get { return CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); }
}
public string IsPrerelease {
get { return PreRelease ? "YES" : "NO"; }
}
public static void Check(Action<Version> onUpgradable) {
if (!Preference.Instance.General.CheckForUpdate) return;
var curDayOfYear = DateTime.Now.DayOfYear;
var lastDayOfYear = Preference.Instance.General.LastCheckDay;
if (lastDayOfYear != curDayOfYear) {
Preference.Instance.General.LastCheckDay = curDayOfYear;
Task.Run(async () => {
try {
var req = new HttpClient();
var rsp = await req.GetAsync("https://api.github.com/repos/sourcegit-scm/sourcegit/releases/latest");
rsp.EnsureSuccessStatusCode();
var raw = await rsp.Content.ReadAsStringAsync();
var ver = JsonSerializer.Deserialize<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)) {
onUpgradable?.Invoke(ver);
}
} catch {
}
});
}
}
}
}

View file

@ -396,13 +396,6 @@
<sys:String x:Key="Text.TwoCommitsDiff">COMMIT : {0} -> {1}</sys:String> <sys:String x:Key="Text.TwoCommitsDiff">COMMIT : {0} -> {1}</sys:String>
<sys:String x:Key="Text.UpdateAvailable">UPDATE AVAILABLE</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Title">{0} is available!</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Time">Publish Time</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Based">Base On Commit</sys:String>
<sys:String x:Key="Text.UpdateAvailable.IsPreRelease">Is Pre-release</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Download" xml:space="preserve">DOWNLOAD</sys:String>
<sys:String x:Key="Text.WorkingCopy">Changes</sys:String> <sys:String x:Key="Text.WorkingCopy">Changes</sys:String>
<sys:String x:Key="Text.WorkingCopy.Unstaged">UNSTAGED</sys:String> <sys:String x:Key="Text.WorkingCopy.Unstaged">UNSTAGED</sys:String>
<sys:String x:Key="Text.WorkingCopy.Unstaged.Stage">STAGE</sys:String> <sys:String x:Key="Text.WorkingCopy.Unstaged.Stage">STAGE</sys:String>

View file

@ -395,13 +395,6 @@
<sys:String x:Key="Text.TwoCommitsDiff">对比提交 : {0} -> {1}</sys:String> <sys:String x:Key="Text.TwoCommitsDiff">对比提交 : {0} -> {1}</sys:String>
<sys:String x:Key="Text.UpdateAvailable">检测更新</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Title">{0}已发布!</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Time">发布时间</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Based">GIT版本</sys:String>
<sys:String x:Key="Text.UpdateAvailable.IsPreRelease">预览版</sys:String>
<sys:String x:Key="Text.UpdateAvailable.Download" xml:space="preserve">下 载</sys:String>
<sys:String x:Key="Text.WorkingCopy">本地更改</sys:String> <sys:String x:Key="Text.WorkingCopy">本地更改</sys:String>
<sys:String x:Key="Text.WorkingCopy.Unstaged">未暂存</sys:String> <sys:String x:Key="Text.WorkingCopy.Unstaged">未暂存</sys:String>
<sys:String x:Key="Text.WorkingCopy.Unstaged.Stage">暂存选中</sys:String> <sys:String x:Key="Text.WorkingCopy.Unstaged.Stage">暂存选中</sys:String>

View file

@ -1,111 +0,0 @@
<controls:Window
x:Class="SourceGit.Views.Upgrade"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
Title="{DynamicResource Text.UpdateAvailable}"
WindowStartupLocation="CenterOwner"
Height="400" Width="500"
ResizeMode="NoResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="1"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<!-- Title Bar -->
<Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Icon -->
<Path Grid.Column="0" Width="16" Height="16" Margin="6,0" Data="{StaticResource Icon.Fetch}"/>
<!-- Title -->
<TextBlock Grid.Column="1" Text="{DynamicResource Text.UpdateAvailable}"/>
<!-- Close -->
<controls:IconButton
Grid.Column="3"
Click="Quit"
Width="28" Padding="8"
Icon="{StaticResource Icon.Close}"
HoverBackground="Red"
WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
<Rectangle Grid.Row="1" Fill="{DynamicResource Brush.Border0}" HorizontalAlignment="Stretch" Height="1"/>
<!-- Body -->
<StackPanel Grid.Row="2" Orientation="Vertical" Margin="8,16,8,0">
<!-- Title -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="20" Height="20" Data="{StaticResource Icon.Git}" Fill="{DynamicResource Brush.Logo}"/>
<TextBlock x:Name="txtRelease" Margin="8,0,0,0" FontSize="18" FontWeight="Bold" Text="Release 1.0 Is Out!!!"/>
</StackPanel>
<!-- Release Info -->
<Grid Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{DynamicResource Text.UpdateAvailable.Time}" FontWeight="Bold"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding ElementName=me, Path=Version.PublishTime}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource Text.UpdateAvailable.Based}" FontWeight="Bold"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding ElementName=me, Path=Version.CommitSHA}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource Text.UpdateAvailable.IsPreRelease}" FontWeight="Bold"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding ElementName=me, Path=Version.IsPrerelease}"/>
</Grid>
</StackPanel>
<!-- CHANGELOG -->
<Border Grid.Row="3" Margin="8" Background="{DynamicResource Brush.Contents}" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock
FontSize="10pt"
Padding="8"
VerticalAlignment="Top"
Foreground="{DynamicResource Brush.FG2}"
Text="{Binding ElementName=me, Path=Version.Body}"/>
</ScrollViewer>
</Border>
<!-- Options -->
<StackPanel Grid.Row="4" HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal">
<Button
Click="Download"
Width="100" Height="24"
Content="{DynamicResource Text.UpdateAvailable.Download}"
Background="{DynamicResource Brush.Accent1}"
BorderBrush="{DynamicResource Brush.FG1}"
BorderThickness="1"/>
<Button
Click="Quit"
Width="100" Height="24"
Margin="8,0,0,0"
Content="{DynamicResource Text.Cancel}"/>
</StackPanel>
</Grid>
</controls:Window>

View file

@ -1,28 +0,0 @@
using System.Diagnostics;
using System.Windows;
namespace SourceGit.Views {
/// <summary>
/// 新版本提示窗口
/// </summary>
public partial class Upgrade : Controls.Window {
public Models.Version Version { get; set; } = new Models.Version();
public Upgrade(Models.Version ver) {
Version = ver;
InitializeComponent();
txtRelease.Text = App.Text("UpdateAvailable.Title", ver.Name);
}
private void Download(object sender, RoutedEventArgs e) {
var url = $"https://github.com/sourcegit-scm/sourcegit/releases/{Version.TagName}";
var info = new ProcessStartInfo("cmd", $"/c start {url}");
info.CreateNoWindow = true;
Process.Start(info);
}
private void Quit(object sender, RoutedEventArgs e) {
Close();
}
}
}