Ionite
1 year ago
16 changed files with 291 additions and 17 deletions
@ -0,0 +1,6 @@
|
||||
namespace StabilityMatrix.Helper; |
||||
|
||||
public interface IUpdateHelper |
||||
{ |
||||
void StartCheckingForUpdates(); |
||||
} |
@ -0,0 +1,51 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Windows.Threading; |
||||
using AutoUpdaterDotNET; |
||||
using Microsoft.Extensions.Logging; |
||||
|
||||
namespace StabilityMatrix.Helper; |
||||
|
||||
public class UpdateHelper : IUpdateHelper |
||||
{ |
||||
private readonly ILogger<UpdateHelper> logger; |
||||
private readonly DispatcherTimer timer = new(); |
||||
|
||||
public UpdateHelper(ILogger<UpdateHelper> logger) |
||||
{ |
||||
this.logger = logger; |
||||
timer.Interval = TimeSpan.FromMinutes(5); |
||||
timer.Tick += (_, _) => |
||||
{ |
||||
CheckForUpdate(); |
||||
}; |
||||
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent; |
||||
} |
||||
|
||||
public void StartCheckingForUpdates() |
||||
{ |
||||
timer.IsEnabled = true; |
||||
timer.Start(); |
||||
CheckForUpdate(); |
||||
} |
||||
|
||||
private void CheckForUpdate() |
||||
{ |
||||
AutoUpdater.DownloadPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Update"); |
||||
AutoUpdater.ExecutablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Update", "StabilityMatrix.exe"); |
||||
// TODO: make this github url? |
||||
AutoUpdater.Start("https://update.danksite.xyz/update.xml"); |
||||
} |
||||
|
||||
private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args) |
||||
{ |
||||
if (args.Error == null && args.IsUpdateAvailable) |
||||
{ |
||||
EventManager.Instance.OnUpdateAvailable(args); |
||||
} |
||||
else |
||||
{ |
||||
logger.LogError(args.Error, "Error while checking for update"); |
||||
} |
||||
} |
||||
} |
@ -1,4 +1,4 @@
|
||||
namespace StabilityMatrix.Models; |
||||
namespace StabilityMatrix.Models.Settings; |
||||
|
||||
public class GlobalSettings |
||||
{ |
@ -1,4 +1,4 @@
|
||||
namespace StabilityMatrix.Models; |
||||
namespace StabilityMatrix.Models.Settings; |
||||
|
||||
public class LibrarySettings |
||||
{ |
@ -0,0 +1,7 @@
|
||||
namespace StabilityMatrix.Models.Settings; |
||||
|
||||
public class WindowSettings |
||||
{ |
||||
public double Width { get; set; } |
||||
public double Height { get; set; } |
||||
} |
@ -0,0 +1,111 @@
|
||||
<ui:FluentWindow |
||||
ExtendsContentIntoTitleBar="True" |
||||
Height="700" |
||||
Icon="pack://application:,,,/Assets/Icon.ico" |
||||
Loaded="UpdateWindow_OnLoaded" |
||||
Title="Stability Matrix - Update" |
||||
Width="700" |
||||
WindowBackdropType="{Binding WindowBackdropType}" |
||||
WindowStartupLocation="CenterOwner" |
||||
d:DataContext="{d:DesignInstance Type=viewModels:UpdateWindowViewModel, |
||||
IsDesignTimeCreatable=True}" |
||||
d:DesignHeight="700" |
||||
d:DesignWidth="700" |
||||
mc:Ignorable="d" |
||||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" |
||||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" |
||||
x:Class="StabilityMatrix.UpdateWindow" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:converters="clr-namespace:StabilityMatrix.Converters" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:system="clr-namespace:System;assembly=System.Runtime" |
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" |
||||
xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:xaml="clr-namespace:MdXaml;assembly=MdXaml"> |
||||
|
||||
<ui:FluentWindow.Resources> |
||||
<converters:ValueConverterGroup x:Key="InvertAndVisibilitate"> |
||||
<converters:BoolNegationConverter /> |
||||
<BooleanToVisibilityConverter /> |
||||
</converters:ValueConverterGroup> |
||||
|
||||
<converters:BoolNegationConverter x:Key="BoolNegationConverter" /> |
||||
<BooleanToVisibilityConverter x:Key="BoolToVisConverter" /> |
||||
<converters:UriToBitmapConverter x:Key="UriToBitmapConverter" /> |
||||
|
||||
<xaml:Markdown |
||||
AssetPathRoot="{x:Static system:Environment.CurrentDirectory}" |
||||
DocumentStyle="{StaticResource DocumentStyle}" |
||||
Heading1Style="{StaticResource H1Style}" |
||||
Heading2Style="{StaticResource H2Style}" |
||||
Heading3Style="{StaticResource H3Style}" |
||||
Heading4Style="{StaticResource H4Style}" |
||||
ImageStyle="{StaticResource ImageStyle}" |
||||
LinkStyle="{StaticResource LinkStyle}" |
||||
SeparatorStyle="{StaticResource SeparatorStyle}" |
||||
x:Key="Markdown" /> |
||||
<xaml:TextToFlowDocumentConverter Markdown="{StaticResource Markdown}" x:Key="TextToFlowDocumentConverter" /> |
||||
</ui:FluentWindow.Resources> |
||||
|
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="*" /> |
||||
<RowDefinition Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
|
||||
<ui:TitleBar Background="{ui:ThemeResource ApplicationBackgroundBrush}"> |
||||
<ui:TitleBar.Header> |
||||
<TextBlock Margin="16,8" Text="Stability Matrix - Update Available" /> |
||||
</ui:TitleBar.Header> |
||||
</ui:TitleBar> |
||||
|
||||
<TextBlock Grid.Row="1" |
||||
Text="A new version of Stability Matrix is available!" |
||||
HorizontalAlignment="Center" |
||||
FontWeight="Thin" |
||||
Margin="0,16,0,0" |
||||
FontSize="28"/> |
||||
|
||||
<TextBlock Grid.Row="2" |
||||
HorizontalAlignment="Center" |
||||
FontSize="18" |
||||
TextWrapping="Wrap" |
||||
TextAlignment="Center" |
||||
Margin="16,32,16,0"> |
||||
<Run Text="Stability Matrix"/> |
||||
<Run Text="v"/><Run Text="{Binding UpdateInfo.CurrentVersion, FallbackValue=0.0.0.0}"/> |
||||
<Run Text="is now available. You have version"/> |
||||
<Run Text="v"/><Run Text="{Binding UpdateInfo.InstalledVersion, FallbackValue=0.0.0.0}"/> |
||||
<Run Text="installed. Would you like to download it now?"/> |
||||
</TextBlock> |
||||
|
||||
<Border Grid.Row="3" |
||||
Margin="32, 16" |
||||
CornerRadius="16" |
||||
Background="#66000000"/> |
||||
<FlowDocumentScrollViewer |
||||
Grid.Row="3" |
||||
Margin="32,16" |
||||
Document="{Binding ReleaseNotes, Converter={StaticResource TextToFlowDocumentConverter}}" |
||||
HorizontalAlignment="Stretch" |
||||
VerticalAlignment="Stretch" /> |
||||
|
||||
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,16"> |
||||
<ui:Button Content="Remind Me Later" |
||||
Margin="0,0,8,0" |
||||
FontSize="18" |
||||
Appearance="Info"/> |
||||
|
||||
<ui:Button Content="Install Now" |
||||
Margin="8,0,0,0" |
||||
FontSize="18" |
||||
Appearance="Success"/> |
||||
</StackPanel> |
||||
|
||||
</Grid> |
||||
</ui:FluentWindow> |
@ -0,0 +1,22 @@
|
||||
using System.Windows; |
||||
using StabilityMatrix.ViewModels; |
||||
using Wpf.Ui.Controls.Window; |
||||
|
||||
namespace StabilityMatrix; |
||||
|
||||
public partial class UpdateWindow : FluentWindow |
||||
{ |
||||
private readonly UpdateWindowViewModel viewModel; |
||||
|
||||
public UpdateWindow(UpdateWindowViewModel viewModel) |
||||
{ |
||||
this.viewModel = viewModel; |
||||
InitializeComponent(); |
||||
DataContext = viewModel; |
||||
} |
||||
|
||||
private async void UpdateWindow_OnLoaded(object sender, RoutedEventArgs e) |
||||
{ |
||||
await viewModel.OnLoaded(); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
using System.Net; |
||||
using System.Net.Http; |
||||
using System.Threading.Tasks; |
||||
using AutoUpdaterDotNET; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
using StabilityMatrix.Helper; |
||||
using Wpf.Ui.Controls.Window; |
||||
|
||||
namespace StabilityMatrix.ViewModels; |
||||
|
||||
public partial class UpdateWindowViewModel : ObservableObject |
||||
{ |
||||
private readonly ISettingsManager settingsManager; |
||||
private readonly IHttpClientFactory httpClientFactory; |
||||
|
||||
public UpdateWindowViewModel(ISettingsManager settingsManager, IHttpClientFactory httpClientFactory) |
||||
{ |
||||
this.settingsManager = settingsManager; |
||||
this.httpClientFactory = httpClientFactory; |
||||
} |
||||
|
||||
[ObservableProperty] private string? releaseNotes; |
||||
|
||||
public UpdateInfoEventArgs? UpdateInfo { get; set; } |
||||
public WindowBackdropType WindowBackdropType => settingsManager.Settings.WindowBackdropType ?? |
||||
WindowBackdropType.Mica; |
||||
|
||||
public async Task OnLoaded() |
||||
{ |
||||
using var client = httpClientFactory.CreateClient(); |
||||
var response = await client.GetAsync(UpdateInfo?.ChangelogURL); |
||||
if (response.IsSuccessStatusCode) |
||||
{ |
||||
ReleaseNotes = await response.Content.ReadAsStringAsync(); |
||||
} |
||||
else |
||||
{ |
||||
ReleaseNotes = "## Unable to load release notes"; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue