mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature: simple self-update implementation (#29)
This commit is contained in:
parent
86a1148148
commit
92e065feba
15 changed files with 494 additions and 7 deletions
9
src/SourceGit/App.JsonCodeGen.cs
Normal file
9
src/SourceGit/App.JsonCodeGen.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SourceGit
|
||||
{
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
||||
[JsonSerializable(typeof(Models.Version))]
|
||||
[JsonSerializable(typeof(ViewModels.Preference))]
|
||||
internal partial class JsonCodeGen : JsonSerializerContext { }
|
||||
}
|
|
@ -2,8 +2,11 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
@ -13,6 +16,7 @@ using Avalonia.Markup.Xaml;
|
|||
using Avalonia.Media;
|
||||
using Avalonia.Media.Fonts;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace SourceGit
|
||||
{
|
||||
|
@ -162,6 +166,43 @@ namespace SourceGit
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void Check4Update(bool manually = false)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Fetch lastest release information.
|
||||
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(2) };
|
||||
var data = await client.GetStringAsync("https://api.github.com/repos/sourcegit-scm/sourcegit/releases/latest");
|
||||
|
||||
// Parse json into Models.Version.
|
||||
var ver = JsonSerializer.Deserialize(data, JsonCodeGen.Default.Version);
|
||||
if (ver == null) return;
|
||||
|
||||
// Check if already up-to-date.
|
||||
if (!ver.IsNewVersion)
|
||||
{
|
||||
if (manually) ShowSelfUpdateResult(new Models.AlreadyUpToDate());
|
||||
return;
|
||||
}
|
||||
|
||||
// Should not check ignored tag if this is called manually.
|
||||
if (!manually)
|
||||
{
|
||||
var pref = ViewModels.Preference.Instance;
|
||||
if (ver.TagName == pref.IgnoreUpdateTag) return;
|
||||
}
|
||||
|
||||
ShowSelfUpdateResult(ver);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (manually) ShowSelfUpdateResult(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void Quit()
|
||||
{
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
|
@ -190,11 +231,32 @@ namespace SourceGit
|
|||
var launcher = new Views.Launcher();
|
||||
_notificationReceiver = launcher;
|
||||
desktop.MainWindow = launcher;
|
||||
|
||||
if (ViewModels.Preference.Instance.Check4UpdatesOnStartup) Check4Update();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private static void ShowSelfUpdateResult(object data)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var dialog = new Views.SelfUpdate()
|
||||
{
|
||||
DataContext = new ViewModels.SelfUpdate
|
||||
{
|
||||
Data = data
|
||||
}
|
||||
};
|
||||
|
||||
dialog.Show(desktop.MainWindow);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ResourceDictionary _activeLocale = null;
|
||||
private Models.INotificationReceiver _notificationReceiver = null;
|
||||
}
|
||||
|
|
37
src/SourceGit/Models/Version.cs
Normal file
37
src/SourceGit/Models/Version.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public partial class Version
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("tag_name")]
|
||||
public string TagName { get; set; }
|
||||
|
||||
[JsonPropertyName("body")]
|
||||
public string Body { get; set; }
|
||||
|
||||
[GeneratedRegex(@"^v(\d+)\.(\d+)$")]
|
||||
private static partial Regex REG_VERSION_TAG();
|
||||
|
||||
public bool IsNewVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var match = REG_VERSION_TAG().Match(TagName);
|
||||
if (!match.Success) return false;
|
||||
|
||||
var major = int.Parse(match.Groups[1].Value);
|
||||
var minor = int.Parse(match.Groups[2].Value);
|
||||
var ver = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
return ver.Major < major || (ver.Major == major && ver.Minor < minor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AlreadyUpToDate { }
|
||||
}
|
|
@ -86,4 +86,5 @@
|
|||
<StreamGeometry x:Key="Icons.LayoutHorizontal">M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zM139 832V192c0-6 4-11 11-11h331v661H149c-6 0-11-4-11-11zm747 0c0 6-4 11-11 11H544v-661H875c6 0 11 4 11 11v640z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.LayoutVertical">M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zm-725 64h725c6 0 11 4 11 11v288h-747V192c0-6 4-11 11-11zm725 661H149c-6 0-11-4-11-11V544h747V832c0 6-4 11-11 11z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.SyntaxHighlight">M875 128h-725A107 107 0 0043 235v555A107 107 0 00149 896h725a107 107 0 00107-107v-555A107 107 0 00875 128zm-115 640h-183v-58l25-3c15 0 19-8 14-24l-22-61H419l-28 82 39 2V768h-166v-58l18-3c18-2 22-11 26-24l125-363-40-4V256h168l160 448 39 3zM506 340l-72 218h145l-71-218h-2z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.SoftwareUpdate">M900 287c40 69 60 144 60 225s-20 156-60 225c-40 69-94 123-163 163-69 40-144 60-225 60s-156-20-225-60c-69-40-123-94-163-163C84 668 64 593 64 512s20-156 60-225 94-123 163-163c69-40 144-60 225-60s156 20 225 60 123 94 163 163zM762 512c0-9-3-16-9-22L578 315l-44-44c-6-6-13-9-22-9s-16 3-22 9l-44 44-176 176c-6 6-9 13-9 22s3 16 9 22l44 44c6 6 13 9 22 9s16-3 22-9l92-92v269c0 9 3 16 9 22 6 6 13 9 22 9h62c8 0 16-3 22-9 6-6 9-13 9-22V486l92 92c6 6 13 9 22 9 8 0 16-3 22-9l44-44c6-6 9-13 9-22z</StreamGeometry>
|
||||
</ResourceDictionary>
|
||||
|
|
72
src/SourceGit/Resources/Locales.Designer.cs
generated
72
src/SourceGit/Resources/Locales.Designer.cs
generated
|
@ -2301,6 +2301,15 @@ namespace SourceGit.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Check for updates on startup.
|
||||
/// </summary>
|
||||
public static string Text_Preference_General_Check4UpdatesOnStartup {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.Preference.General.Check4UpdatesOnStartup", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Language.
|
||||
/// </summary>
|
||||
|
@ -3255,6 +3264,69 @@ namespace SourceGit.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Check for Updates ....
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to New version of this software is available: .
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_Available {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.Available", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Check for updates failed!.
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_Error {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.Error", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download.
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_GotoDownload {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.GotoDownload", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Skip This Version.
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_IgnoreThisVersion {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.IgnoreThisVersion", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Software Update.
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_Title {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.Title", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to There are currently no updates available..
|
||||
/// </summary>
|
||||
public static string Text_SelfUpdate_UpToDate {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SelfUpdate.UpToDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Squash HEAD Into Parent.
|
||||
/// </summary>
|
||||
|
|
|
@ -1302,4 +1302,28 @@
|
|||
<data name="Text.Preference.Appearance" xml:space="preserve">
|
||||
<value>APPEARANCE</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Title" xml:space="preserve">
|
||||
<value>Software Update</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Error" xml:space="preserve">
|
||||
<value>Check for updates failed!</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Available" xml:space="preserve">
|
||||
<value>New version of this software is available: </value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.GotoDownload" xml:space="preserve">
|
||||
<value>Download</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">
|
||||
<value>Skip This Version</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate" xml:space="preserve">
|
||||
<value>Check for Updates ...</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.UpToDate" xml:space="preserve">
|
||||
<value>There are currently no updates available.</value>
|
||||
</data>
|
||||
<data name="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">
|
||||
<value>Check for updates on startup</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1302,4 +1302,28 @@
|
|||
<data name="Text.Preference.Appearance" xml:space="preserve">
|
||||
<value>Appearance</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Title" xml:space="preserve">
|
||||
<value>Software Update</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Error" xml:space="preserve">
|
||||
<value>Check for updates failed!</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Available" xml:space="preserve">
|
||||
<value>New version of this software is available: </value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.GotoDownload" xml:space="preserve">
|
||||
<value>Download</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">
|
||||
<value>Skip This Version</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate" xml:space="preserve">
|
||||
<value>Check for Updates ...</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.UpToDate" xml:space="preserve">
|
||||
<value>There are currently no updates available.</value>
|
||||
</data>
|
||||
<data name="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">
|
||||
<value>Check for updates on startup</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1302,4 +1302,28 @@
|
|||
<data name="Text.Preference.Appearance" xml:space="preserve">
|
||||
<value>外观配置</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Title" xml:space="preserve">
|
||||
<value>软件更新</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Error" xml:space="preserve">
|
||||
<value>获取最新版本信息失败!</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.Available" xml:space="preserve">
|
||||
<value>检测到软件有版本更新: </value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.GotoDownload" xml:space="preserve">
|
||||
<value>下 载</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">
|
||||
<value>忽略此版本</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate" xml:space="preserve">
|
||||
<value>检测更新...</value>
|
||||
</data>
|
||||
<data name="Text.SelfUpdate.UpToDate" xml:space="preserve">
|
||||
<value>当前已是最新版本。</value>
|
||||
</data>
|
||||
<data name="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">
|
||||
<value>启动时检测软件更新</value>
|
||||
</data>
|
||||
</root>
|
|
@ -28,7 +28,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
try
|
||||
{
|
||||
_instance = JsonSerializer.Deserialize(File.ReadAllText(_savePath), JsonSerializationCodeGen.Default.Preference);
|
||||
_instance = JsonSerializer.Deserialize(File.ReadAllText(_savePath), JsonCodeGen.Default.Preference);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -133,6 +133,18 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _useFixedTabWidth, value);
|
||||
}
|
||||
|
||||
public bool Check4UpdatesOnStartup
|
||||
{
|
||||
get => _check4UpdatesOnStartup;
|
||||
set => SetProperty(ref _check4UpdatesOnStartup, value);
|
||||
}
|
||||
|
||||
public string IgnoreUpdateTag
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = string.Empty;
|
||||
|
||||
public bool UseTwoColumnsLayoutInHistories
|
||||
{
|
||||
get => _useTwoColumnsLayoutInHistories;
|
||||
|
@ -342,7 +354,7 @@ namespace SourceGit.ViewModels
|
|||
var dir = Path.GetDirectoryName(_savePath);
|
||||
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
||||
|
||||
var data = JsonSerializer.Serialize(_instance, JsonSerializationCodeGen.Default.Preference);
|
||||
var data = JsonSerializer.Serialize(_instance, JsonCodeGen.Default.Preference);
|
||||
File.WriteAllText(_savePath, data);
|
||||
}
|
||||
|
||||
|
@ -390,6 +402,7 @@ namespace SourceGit.ViewModels
|
|||
private int _maxHistoryCommits = 20000;
|
||||
private bool _restoreTabs = false;
|
||||
private bool _useFixedTabWidth = true;
|
||||
private bool _check4UpdatesOnStartup = true;
|
||||
private bool _useTwoColumnsLayoutInHistories = false;
|
||||
private bool _useSideBySideDiff = false;
|
||||
private bool _useSyntaxHighlighting = false;
|
||||
|
@ -421,8 +434,4 @@ namespace SourceGit.ViewModels
|
|||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
||||
[JsonSerializable(typeof(Preference))]
|
||||
internal partial class JsonSerializationCodeGen : JsonSerializerContext { }
|
||||
}
|
15
src/SourceGit/ViewModels/SelfUpdate.cs
Normal file
15
src/SourceGit/ViewModels/SelfUpdate.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class SelfUpdate : ObservableObject
|
||||
{
|
||||
public object Data
|
||||
{
|
||||
get => _data;
|
||||
set => SetProperty(ref _data, value);
|
||||
}
|
||||
|
||||
private object _data = null;
|
||||
}
|
||||
}
|
|
@ -65,6 +65,13 @@
|
|||
<Path Width="14" Height="14" Data="{StaticResource Icons.Hotkeys}"/>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="-"/>
|
||||
<MenuItem Header="{DynamicResource Text.SelfUpdate}" Click="Check4Update">
|
||||
<MenuItem.Icon>
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.SoftwareUpdate}"/>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="-"/>
|
||||
<MenuItem Header="{DynamicResource Text.About}" Click="OpenAboutDialog">
|
||||
<MenuItem.Icon>
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}"/>
|
||||
|
|
|
@ -317,6 +317,12 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void Check4Update(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Check4Update(true);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void OpenAboutDialog(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new About();
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<TabItem.Header>
|
||||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.General}"/>
|
||||
</TabItem.Header>
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32" ColumnDefinitions="Auto,*">
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32" ColumnDefinitions="Auto,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.General.Locale}"
|
||||
HorizontalAlignment="Right"
|
||||
|
@ -131,6 +131,11 @@
|
|||
Height="32"
|
||||
Content="{DynamicResource Text.Preference.General.UseFixedTabWidth}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Grid.Row="5" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preference.General.Check4UpdatesOnStartup}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=Check4UpdatesOnStartup, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
|
153
src/SourceGit/Views/SelfUpdate.axaml
Normal file
153
src/SourceGit/Views/SelfUpdate.axaml
Normal file
|
@ -0,0 +1,153 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
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"
|
||||
Title="{DynamicResource Text.SelfUpdate.Title}"
|
||||
Icon="/App.ico"
|
||||
Background="Transparent"
|
||||
SizeToContent="WidthAndHeight"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
ExtendClientAreaChromeHints="NoChrome"
|
||||
SystemDecorations="{OnPlatform Full, Linux=None}">
|
||||
<Grid RowDefinitions="Auto,*" Margin="{OnPlatform 0, Linux=6}">
|
||||
<!-- Custom window shadow for Linux -->
|
||||
<Border Grid.Row="0" Grid.RowSpan="2"
|
||||
Background="{DynamicResource Brush.Window}"
|
||||
Effect="drop-shadow(0 0 6 #A0000000)"
|
||||
IsVisible="{OnPlatform False, Linux=True}"/>
|
||||
|
||||
<!-- TitleBar -->
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30">
|
||||
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Background="{DynamicResource Brush.TitleBar}"
|
||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||
PointerPressed="BeginMoveWindow"/>
|
||||
|
||||
<Path Grid.Column="0"
|
||||
Width="14" Height="14"
|
||||
Margin="10,0,0,0"
|
||||
Data="{StaticResource Icons.SoftwareUpdate}"
|
||||
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||
|
||||
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}">
|
||||
<Button Classes="caption_button_macos" Click="CloseWindow">
|
||||
<Grid>
|
||||
<Ellipse Fill="{DynamicResource Brush.MacOS.Close}"/>
|
||||
<Path Height="6" Width="6" Stretch="Fill" Fill="#404040" Stroke="#404040" StrokeThickness="1" Data="{StaticResource Icons.Window.Close}"/>
|
||||
</Grid>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.SelfUpdate.Title}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Classes="caption_button"
|
||||
Click="CloseWindow"
|
||||
IsVisible="{OnPlatform True, macOS=False}">
|
||||
<Path Data="{StaticResource Icons.Window.Close}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<!-- Body -->
|
||||
<Grid Grid.Row="1" Background="{DynamicResource Brush.Window}">
|
||||
<ContentControl Content="{Binding Data}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="m:Version">
|
||||
<StackPanel Orientation="Vertical" Margin="16,8">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
|
||||
<TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Available}"/>
|
||||
<Border Margin="4,0,0,0" Height="20" CornerRadius="10" Background="{DynamicResource Brush.Accent1}" Effect="drop-shadow(0 0 6 #40000000)">
|
||||
<TextBlock Classes="monospace" Margin="8,0" Text="{Binding TagName}" FontSize="12" Foreground="White"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<TextBox IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
MaxWidth="500" MaxHeight="400"
|
||||
Margin="0,8" Padding="0"
|
||||
VerticalContentAlignment="Top"
|
||||
Text="{Binding Body}"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<Button Classes="flat primary"
|
||||
Height="30"
|
||||
Click="GotoDownload"
|
||||
HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Pull}"/>
|
||||
<TextBlock Text="{DynamicResource Text.SelfUpdate.GotoDownload}" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Classes="flat"
|
||||
Height="30"
|
||||
Margin="8,0,0,0"
|
||||
Click="IgnoreThisVersion"
|
||||
HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.File.Ignore}"/>
|
||||
<TextBlock Text="{DynamicResource Text.SelfUpdate.IgnoreThisVersion}" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</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">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
|
||||
<TextBlock Margin="8,0,0,0" Text="{DynamicResource Text.SelfUpdate.UpToDate}"/>
|
||||
</StackPanel>
|
||||
|
||||
<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>
|
||||
</Grid>
|
||||
</Window>
|
39
src/SourceGit/Views/SelfUpdate.axaml.cs
Normal file
39
src/SourceGit/Views/SelfUpdate.axaml.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class SelfUpdate : Window
|
||||
{
|
||||
public SelfUpdate()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void CloseWindow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void GotoDownload(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Native.OS.OpenBrowser("https://github.com/sourcegit-scm/sourcegit/releases/latest");
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void IgnoreThisVersion(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
var ver = button.DataContext as Models.Version;
|
||||
ViewModels.Preference.Instance.IgnoreUpdateTag = ver.TagName;
|
||||
Close();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue