Browse Source

Merge pull request #127 from ionite34/updater-features

pull/14/head
Ionite 1 year ago committed by GitHub
parent
commit
99edc9bf31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      StabilityMatrix/App.xaml.cs
  2. 1
      StabilityMatrix/Helper/EventManager.cs
  3. 6
      StabilityMatrix/Models/Configs/DebugOptions.cs
  4. 16
      StabilityMatrix/Models/UpdateInfo.cs
  5. 2
      StabilityMatrix/Updater/IUpdateHelper.cs
  6. 13
      StabilityMatrix/Updater/UpdateChannel.cs
  7. 15
      StabilityMatrix/Updater/UpdateHelper.cs
  8. 34
      StabilityMatrix/Updater/UpdateInfo.cs
  9. 11
      StabilityMatrix/Updater/UpdateType.cs
  10. 1
      StabilityMatrix/ViewModels/MainWindowViewModel.cs
  11. 1
      StabilityMatrix/ViewModels/UpdateWindowViewModel.cs

1
StabilityMatrix/App.xaml.cs

@ -35,6 +35,7 @@ using StabilityMatrix.Models.Configs;
using StabilityMatrix.Models.Packages;
using StabilityMatrix.Python;
using StabilityMatrix.Services;
using StabilityMatrix.Updater;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts;
using Wpf.Ui.Services;

1
StabilityMatrix/Helper/EventManager.cs

@ -1,5 +1,6 @@
using System;
using StabilityMatrix.Models;
using StabilityMatrix.Updater;
namespace StabilityMatrix.Helper;

6
StabilityMatrix/Models/Configs/DebugOptions.cs

@ -11,4 +11,10 @@ public class DebugOptions
/// Always show the one-click install page on launch
/// </summary>
public bool ShowOneClickInstall { get; set; }
/// <summary>
/// Override the default update manifest url
/// (https://cdn.lykos.ai/update.json)
/// </summary>
public string? UpdateManifestUrl { get; set; }
}

16
StabilityMatrix/Models/UpdateInfo.cs

@ -1,16 +0,0 @@
using System;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models;
public class UpdateInfo
{
[JsonPropertyName("version")]
public Version Version { get; set; }
[JsonPropertyName("url")]
public string DownloadUrl { get; set; }
[JsonPropertyName("changelog")]
public string ChangelogUrl { get; set; }
}

2
StabilityMatrix/Helper/IUpdateHelper.cs → StabilityMatrix/Updater/IUpdateHelper.cs

@ -2,7 +2,7 @@
using System.Threading.Tasks;
using StabilityMatrix.Models;
namespace StabilityMatrix.Helper;
namespace StabilityMatrix.Updater;
public interface IUpdateHelper
{

13
StabilityMatrix/Updater/UpdateChannel.cs

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
using StabilityMatrix.Converters.Json;
namespace StabilityMatrix.Updater;
[JsonConverter(typeof(DefaultUnknownEnumConverter<UpdateChannel>))]
public enum UpdateChannel
{
Unknown,
Stable,
Preview,
Development
}

15
StabilityMatrix/Helper/UpdateHelper.cs → StabilityMatrix/Updater/UpdateHelper.cs

@ -1,24 +1,30 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Configs;
using StabilityMatrix.Services;
namespace StabilityMatrix.Helper;
namespace StabilityMatrix.Updater;
public class UpdateHelper : IUpdateHelper
{
private readonly ILogger<UpdateHelper> logger;
private readonly IHttpClientFactory httpClientFactory;
private readonly IDownloadService downloadService;
private readonly DebugOptions debugOptions;
private readonly DispatcherTimer timer = new();
private string UpdateManifestUrl => debugOptions.UpdateManifestUrl ??
"https://cdn.lykos.ai/update.json";
private static readonly string UpdateFolder =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Update");
@ -26,11 +32,12 @@ public class UpdateHelper : IUpdateHelper
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Update", "StabilityMatrix.exe");
public UpdateHelper(ILogger<UpdateHelper> logger, IHttpClientFactory httpClientFactory,
IDownloadService downloadService)
IDownloadService downloadService, IOptions<DebugOptions> debugOptions)
{
this.logger = logger;
this.httpClientFactory = httpClientFactory;
this.downloadService = downloadService;
this.debugOptions = debugOptions.Value;
timer.Interval = TimeSpan.FromMinutes(5);
timer.Tick += async (_, _) => { await CheckForUpdate(); };
@ -60,7 +67,7 @@ public class UpdateHelper : IUpdateHelper
try
{
var httpClient = httpClientFactory.CreateClient("UpdateClient");
var response = await httpClient.GetAsync("https://cdn.lykos.ai/update.json");
var response = await httpClient.GetAsync(UpdateManifestUrl);
if (!response.IsSuccessStatusCode)
{
logger.LogError("Error while checking for update");

34
StabilityMatrix/Updater/UpdateInfo.cs

@ -0,0 +1,34 @@
using System;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Updater;
public record UpdateInfo(
[property: JsonPropertyName("version")]
Version Version,
[property: JsonPropertyName("releaseDate")]
DateTimeOffset ReleaseDate,
[property: JsonPropertyName("channel")]
UpdateChannel Channel,
[property: JsonPropertyName("type")]
UpdateType Type,
[property: JsonPropertyName("url")]
string DownloadUrl,
[property: JsonPropertyName("changelog")]
string ChangelogUrl,
// Blake3 hash of the file
[property: JsonPropertyName("hash_blake3")]
string HashBlake3,
// ED25519 signature of the semicolon seperated string:
// "version + releaseDate + channel + type + url + changelog + hash_blake3"
// verifiable using our stored public key
[property: JsonPropertyName("signature")]
string Signature
);

11
StabilityMatrix/Updater/UpdateType.cs

@ -0,0 +1,11 @@
using System;
namespace StabilityMatrix.Updater;
[Flags]
public enum UpdateType
{
Normal = 1 << 0,
Critical = 1 << 1,
Mandatory = 1 << 2,
}

1
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -14,6 +14,7 @@ using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Configs;
using StabilityMatrix.Services;
using StabilityMatrix.Updater;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls.ContentDialogControl;
using Wpf.Ui.Controls.Window;

1
StabilityMatrix/ViewModels/UpdateWindowViewModel.cs

@ -7,6 +7,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Updater;
using Wpf.Ui.Controls.Window;
namespace StabilityMatrix.ViewModels;

Loading…
Cancel
Save