-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
215 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
using System.Windows; | ||
using ChatPrisma.Options; | ||
using ChatPrisma.Services.Dialogs; | ||
using ChatPrisma.Services.ViewModels; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using Onova; | ||
|
||
namespace ChatPrisma.HostedServices; | ||
|
||
public class UpdaterHostedService(IUpdateManager updateManager, Application app, IHostEnvironment hostEnvironment) : BackgroundService | ||
public class UpdaterHostedService(IUpdateManager updateManager, IViewModelFactory viewModelFactory, IDialogService dialogService, IOptionsMonitor<UpdaterOptions> updaterOptions) : BackgroundService | ||
{ | ||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
if (hostEnvironment.IsProduction() is false) | ||
return; | ||
|
||
while (stoppingToken.IsCancellationRequested is false) | ||
{ | ||
var result = await updateManager.CheckForUpdatesAsync(stoppingToken); | ||
if (result is { CanUpdate: true, LastVersion: not null }) | ||
if (updaterOptions.CurrentValue.CheckForUpdatesInBackground) | ||
{ | ||
var updateResult = MessageBox.Show($"Update available {result.LastVersion.ToString(3)}!, Wanna update now?", "Title", MessageBoxButton.YesNo); | ||
if (updateResult == MessageBoxResult.Yes) | ||
var result = await updateManager.CheckForUpdatesAsync(stoppingToken); | ||
if (result is { CanUpdate: true, LastVersion: not null }) | ||
{ | ||
await updateManager.PrepareUpdateAsync(result.LastVersion, cancellationToken: stoppingToken); | ||
updateManager.LaunchUpdater(result.LastVersion); | ||
|
||
app.Shutdown(); | ||
var viewModel = viewModelFactory.CreateUpdateViewModel(result); | ||
await dialogService.ShowDialog(viewModel); | ||
} | ||
} | ||
|
||
await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken); | ||
await Task.Delay(TimeSpan.FromMinutes(updaterOptions.CurrentValue.MinutesBetweenUpdateChecks), stoppingToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<UserControl x:Class="ChatPrisma.Views.Update.UpdateView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:ChatPrisma.Views.Update" | ||
xmlns:dxmvvm="clr-namespace:DevExpress.Mvvm.UI;assembly=DevExpress.Mvvm.UI" | ||
|
||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" | ||
|
||
d:DesignWidth="800" | ||
d:DesignHeight="450" | ||
d:DataContext="{d:DesignInstance local:UpdateViewModel}"> | ||
<UserControl.Resources> | ||
<dxmvvm:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> | ||
<dxmvvm:BooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" Inverse="True" /> | ||
</UserControl.Resources> | ||
<Grid> | ||
<GroupBox Header="Update verfügbar!" | ||
Visibility="{Binding UpdateAvailable, Converter={StaticResource BooleanToVisibilityConverter}}"> | ||
<StackPanel> | ||
<TextBlock> | ||
<Run Text="Ein Update für "/><Run Text="{Binding ApplicationName}" /><Run Text=" steht zur verfügung!" /><LineBreak /> | ||
<LineBreak /> | ||
<Bold><Run Text="Ihre Version: " /></Bold><Run Text="{Binding CurrentVersion}" /><LineBreak /> | ||
<Bold><Run Text="Neue Version: " /></Bold><Run Text="{Binding UpdateVersion}" /><LineBreak /> | ||
</TextBlock> | ||
<Button Content="Herunterladen und installieren" | ||
Command="{Binding DownloadAndInstallUpdateCommand}" /> | ||
</StackPanel> | ||
</GroupBox> | ||
|
||
<GroupBox Header="Kein Update verfügbar!" | ||
Visibility="{Binding UpdateAvailable, Converter={StaticResource InverseBooleanToVisibilityConverter}}"> | ||
<TextBlock> | ||
<Run Text="Sie verwenden im Moment die aktuellste Version von "/><Run Text="{Binding ApplicationName}" /><Run Text="!" /><LineBreak /> | ||
<LineBreak /> | ||
<Bold><Run Text="Ihre Version: " /></Bold><Run Text="{Binding CurrentVersion}" /> | ||
</TextBlock> | ||
</GroupBox> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace ChatPrisma.Views.Update | ||
{ | ||
/// <summary> | ||
/// Interaction logic for UpdateView.xaml | ||
/// </summary> | ||
public partial class UpdateView : UserControl | ||
{ | ||
public UpdateView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using ChatPrisma.Options; | ||
using ChatPrisma.Services.Dialogs; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Microsoft.Extensions.Options; | ||
using Onova; | ||
using Onova.Models; | ||
|
||
namespace ChatPrisma.Views.Update | ||
{ | ||
public partial class UpdateViewModel : ObservableObject, IInitialize | ||
{ | ||
private readonly Application _app; | ||
private readonly IUpdateManager _updateManager; | ||
private CheckForUpdatesResult? _updatesResult; | ||
|
||
public UpdateViewModel(IOptionsMonitor<ApplicationOptions> applicationOptions, Application app, IUpdateManager updateManager) | ||
{ | ||
this._app = app; | ||
this._updateManager = updateManager; | ||
this.CurrentVersion = applicationOptions.CurrentValue.ApplicationVersion; | ||
this.ApplicationName = applicationOptions.CurrentValue.ApplicationName; | ||
} | ||
public UpdateViewModel(CheckForUpdatesResult? updatesResult, IOptionsMonitor<ApplicationOptions> applicationOptions, Application app, IUpdateManager updateManager) | ||
: this(applicationOptions, app, updateManager) | ||
{ | ||
this.UseUpdateResult(updatesResult); | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
if (this._updatesResult is null) | ||
{ | ||
var updateResult = await this._updateManager.CheckForUpdatesAsync(); | ||
this.UseUpdateResult(updateResult); | ||
} | ||
} | ||
|
||
[ObservableProperty] | ||
private string _currentVersion; | ||
|
||
[ObservableProperty] | ||
private string _applicationName; | ||
|
||
[ObservableProperty] | ||
private bool _updateAvailable = false; | ||
|
||
[ObservableProperty] | ||
private string? _updateVersion; | ||
|
||
|
||
[RelayCommand] | ||
private async Task DownloadAndInstallUpdate(CancellationToken cancellationToken) | ||
{ | ||
if (this._updatesResult?.LastVersion is null) | ||
return; | ||
|
||
await this._updateManager.PrepareUpdateAsync(this._updatesResult.LastVersion, cancellationToken: cancellationToken); | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
this._updateManager.LaunchUpdater(this._updatesResult.LastVersion!); | ||
this._app.Shutdown(); | ||
} | ||
|
||
private void UseUpdateResult(CheckForUpdatesResult? updatesResult) | ||
{ | ||
this._updatesResult = updatesResult; | ||
this.UpdateAvailable = updatesResult?.CanUpdate ?? false; | ||
this.UpdateVersion = updatesResult?.LastVersion?.ToString(3); | ||
} | ||
} | ||
} |
Oops, something went wrong.