Skip to content

Commit 73dfca0

Browse files
author
Alexandru Macocian
committed
Include updater in main application.
1 parent cdc9b6b commit 73dfca0

15 files changed

+411
-186
lines changed

Daybreak.Updater/Daybreak.Updater.csproj

-8
This file was deleted.

Daybreak.Updater/Program.cs

-27
This file was deleted.

Daybreak.Updater/Properties/launchSettings.json

-8
This file was deleted.

Daybreak.Updater/ReleaseClient.cs

-130
This file was deleted.

Daybreak.sln

-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.31005.135
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Daybreak", "Daybreak\Daybreak.csproj", "{AA45C2B1-8BD0-466C-9271-699F168905AF}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daybreak.Updater", "Daybreak.Updater\Daybreak.Updater.csproj", "{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}"
9-
EndProject
108
Global
119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1210
Debug|Any CPU = Debug|Any CPU
@@ -23,14 +21,6 @@ Global
2321
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|Any CPU.Build.0 = Release|Any CPU
2422
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.ActiveCfg = Release|x64
2523
{AA45C2B1-8BD0-466C-9271-699F168905AF}.Release|x64.Build.0 = Release|x64
26-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
28-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Debug|x64.ActiveCfg = Debug|Any CPU
29-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Debug|x64.Build.0 = Debug|Any CPU
30-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Release|x64.ActiveCfg = Release|Any CPU
33-
{4D17EF2F-2094-40BC-AB6C-85F57BBA40E1}.Release|x64.Build.0 = Release|Any CPU
3424
EndGlobalSection
3525
GlobalSection(SolutionProperties) = preSolution
3626
HideSolutionNode = FALSE

Daybreak/Configuration/ProjectConfiguration.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Daybreak.Services.Credentials;
66
using Daybreak.Services.Logging;
77
using Daybreak.Services.Screenshots;
8+
using Daybreak.Services.Updater;
89
using Daybreak.Services.ViewManagement;
910
using Daybreak.Views;
1011
using Microsoft.Web.WebView2.Core;
@@ -29,6 +30,7 @@ public static void RegisterServices(IServiceProducer serviceProducer)
2930
serviceProducer.RegisterSingleton<IScreenshotProvider, ScreenshotProvider>();
3031
serviceProducer.RegisterSingleton<IConfigurationManager, ConfigurationManager>();
3132
serviceProducer.RegisterSingleton<IBloogumClient, BloogumClient>();
33+
serviceProducer.RegisterSingleton<IApplicationUpdater, ApplicationUpdater>();
3234
serviceProducer.RegisterSingleton<CoreWebView2Environment, CoreWebView2Environment>((sp) => TaskExtensions.RunSync(() => CoreWebView2Environment.CreateAsync(null, "BrowserData", null)));
3335
}
3436
public static void RegisterLifetimeServices(IApplicationLifetimeProducer applicationLifetimeProducer)
@@ -44,6 +46,8 @@ public static void RegisterViews(IViewProducer viewProducer)
4446

4547
viewProducer.RegisterView<MainView>();
4648
viewProducer.RegisterView<SettingsView>();
49+
viewProducer.RegisterView<AskUpdateView>();
50+
viewProducer.RegisterView<UpdateView>();
4751
}
4852
}
4953
}

Daybreak/Daybreak.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
1010
<LangVersion>preview</LangVersion>
1111
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
12-
<Version>0.1.3</Version>
12+
<Version>0.1.4</Version>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

Daybreak/Launch/MainWindow.xaml.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Daybreak.Services.Bloogum;
22
using Daybreak.Services.Screenshots;
3+
using Daybreak.Services.Updater;
34
using Daybreak.Services.ViewManagement;
45
using Daybreak.Views;
56
using Pepa.Wpf.Utilities;
@@ -26,6 +27,7 @@ public partial class MainWindow : Window
2627
private readonly IViewManager viewManager;
2728
private readonly IScreenshotProvider screenshotProvider;
2829
private readonly IBloogumClient bloogumClient;
30+
private readonly IApplicationUpdater applicationUpdater;
2931
private readonly CancellationTokenSource cancellationToken = new();
3032

3133
public string CreditText
@@ -37,18 +39,20 @@ public string CreditText
3739
public MainWindow(
3840
IViewManager viewManager,
3941
IScreenshotProvider screenshotProvider,
40-
IBloogumClient bloogumClient)
42+
IBloogumClient bloogumClient,
43+
IApplicationUpdater applicationUpdater)
4144
{
4245
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
4346
this.screenshotProvider = screenshotProvider.ThrowIfNull(nameof(screenshotProvider));
4447
this.bloogumClient = bloogumClient.ThrowIfNull(nameof(bloogumClient));
48+
this.applicationUpdater = applicationUpdater.ThrowIfNull(nameof(applicationUpdater));
4549
InitializeComponent();
4650
}
4751

4852
private void Window_Loaded(object sender, RoutedEventArgs e)
4953
{
50-
this.viewManager.ShowView<MainView>();
5154
this.SetupImageCycle();
55+
this.CheckForUpdates();
5256
}
5357

5458
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@@ -145,6 +149,19 @@ private void SetImage(ImageSource imageSource)
145149
}
146150
}
147151

152+
private async void CheckForUpdates()
153+
{
154+
var updateAvailable = await this.applicationUpdater.UpdateAvailable().ConfigureAwait(true);
155+
if (updateAvailable)
156+
{
157+
this.viewManager.ShowView<AskUpdateView>();
158+
}
159+
else
160+
{
161+
this.viewManager.ShowView<MainView>();
162+
}
163+
}
164+
148165
private static Color GetAverageColor(BitmapSource bitmap)
149166
{
150167
var format = bitmap.Format;

Daybreak/Models/UpdateStatus.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.ComponentModel;
2+
3+
namespace Daybreak.Models
4+
{
5+
public sealed class UpdateStatus : INotifyPropertyChanged
6+
{
7+
public static readonly UpdateStep StartingStep = new("Starting");
8+
public static readonly UpdateStep CheckingLatestVersion = new("Checking latest version");
9+
public static UpdateStep Downloading(double progress) => new DownloadUpdateStep("Downloading", progress);
10+
public static readonly UpdateStep DownloadFinished = new("Download finished. Application will restart in order to apply the update.");
11+
12+
private UpdateStep currentStep = StartingStep;
13+
14+
public event PropertyChangedEventHandler PropertyChanged;
15+
16+
public UpdateStep CurrentStep
17+
{
18+
get => this.currentStep;
19+
set
20+
{
21+
this.currentStep = value;
22+
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentStep)));
23+
}
24+
}
25+
26+
public class UpdateStep
27+
{
28+
public string Name { get; }
29+
internal UpdateStep(string name)
30+
{
31+
this.Name = name;
32+
}
33+
}
34+
public class DownloadUpdateStep : UpdateStep
35+
{
36+
internal DownloadUpdateStep(string name, double progress) : base(name)
37+
{
38+
this.Progress = progress;
39+
}
40+
41+
public double Progress { get; }
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)