diff --git a/Needlework.Net.Desktop/GithubRelease.cs b/Needlework.Net.Desktop/GithubRelease.cs
new file mode 100644
index 0000000..4060c94
--- /dev/null
+++ b/Needlework.Net.Desktop/GithubRelease.cs
@@ -0,0 +1,12 @@
+using System.Text.Json.Serialization;
+
+namespace Needlework.Net.Desktop
+{
+ public class GithubRelease
+ {
+ [JsonPropertyName("tag_name")]
+ public string TagName { get; set; } = string.Empty;
+
+ public bool IsLatest(int version) => int.Parse(TagName.Replace(".", "")) > version;
+ }
+}
diff --git a/Needlework.Net.Desktop/Needlework.Net.Desktop.csproj b/Needlework.Net.Desktop/Needlework.Net.Desktop.csproj
index 75338ff..0fb3169 100644
--- a/Needlework.Net.Desktop/Needlework.Net.Desktop.csproj
+++ b/Needlework.Net.Desktop/Needlework.Net.Desktop.csproj
@@ -11,8 +11,8 @@
False
app.ico
NeedleworkDotNet
- 0.2.2.0
- 0.2.2.0
+ 0.3.0.0
+ 0.3.0.0
False
diff --git a/Needlework.Net.Desktop/ViewModels/MainWindowViewModel.cs b/Needlework.Net.Desktop/ViewModels/MainWindowViewModel.cs
index 91cd820..504fce2 100644
--- a/Needlework.Net.Desktop/ViewModels/MainWindowViewModel.cs
+++ b/Needlework.Net.Desktop/ViewModels/MainWindowViewModel.cs
@@ -12,7 +12,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
+using System.Net.Http.Json;
using System.Reflection;
+using System.Threading;
using System.Threading.Tasks;
namespace Needlework.Net.Desktop.ViewModels
@@ -28,6 +30,7 @@ namespace Needlework.Net.Desktop.ViewModels
public OpenApiDocument? HostDocument { get; set; }
[ObservableProperty] private bool _isBusy = true;
+ [ObservableProperty] private bool _isUpdateShown = false;
public MainWindowViewModel(IEnumerable pages, HttpClient httpClient, WindowService windowService)
{
@@ -36,7 +39,44 @@ namespace Needlework.Net.Desktop.ViewModels
WindowService = windowService;
WeakReferenceMessenger.Default.RegisterAll(this);
+
Task.Run(FetchDataAsync);
+ new Thread(ProcessEvents) { IsBackground = true }.Start();
+ }
+
+ private void ProcessEvents(object? obj)
+ {
+ while (true)
+ {
+ Task.Run(CheckLatestVersionAsync);
+
+ Thread.Sleep(TimeSpan.FromSeconds(2));
+ }
+ }
+
+ private async Task CheckLatestVersionAsync()
+ {
+ try
+ {
+ var request = new HttpRequestMessage(HttpMethod.Get, "https://api.github.com/repos/BlossomiShymae/Needlework.Net/releases/latest");
+ request.Headers.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("Needlework.Net", Version));
+
+ var response = await HttpClient.SendAsync(request);
+ var release = await response.Content.ReadFromJsonAsync();
+ if (release == null) return;
+
+ var currentVersion = int.Parse(Version.Replace(".", ""));
+
+ if (release.IsLatest(currentVersion) && !IsUpdateShown)
+ {
+ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(async () =>
+ {
+ await SukiHost.ShowToast("Needlework.Net Update", $"There is a new version available: {release.TagName}.", SukiUI.Enums.NotificationType.Info, TimeSpan.FromSeconds(10), () => OpenUrl("https://github.com/BlossomiShymae/Needlework.Net/releases"));
+ IsUpdateShown = true;
+ });
+ }
+ }
+ catch (Exception) { }
}
private async Task FetchDataAsync()
@@ -74,12 +114,6 @@ namespace Needlework.Net.Desktop.ViewModels
process.Start();
}
- [RelayCommand]
- private void OpenConsole()
- {
-
- }
-
public void Receive(OopsiesWindowRequestedMessage message)
{
WindowService.ShowOopsiesWindow(message.Value);