Skip to content

Commit 4da4d8b

Browse files
Add flyout to show no updates are available
1 parent 667b366 commit 4da4d8b

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

src/UI/ViewModels/SettingsViewModel.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public partial class SettingsViewModel(ILogger<SettingsViewModel> logger,
2424
private readonly UpdaterConfig _updaterConfig = updaterConfig ?? throw new ArgumentNullException(nameof(updaterConfig));
2525
private readonly AppConfig _appConfig = appConfig ?? throw new ArgumentNullException(nameof(appConfig));
2626
private readonly IDeploymentService _deploymentService = deploymentService ?? throw new ArgumentNullException(nameof(deploymentService));
27-
private bool _hasCheckedForUpdates = false;
27+
28+
[ObservableProperty]
29+
private bool _isNotificationOpen;
30+
31+
[ObservableProperty]
32+
private string _notificationMessage;
2833

2934
[ObservableProperty]
3035
private string _versionDescription;
@@ -89,11 +94,6 @@ private void OpenReportBug()
8994
[RelayCommand]
9095
private void CheckUpdates()
9196
{
92-
if (_hasCheckedForUpdates)
93-
{
94-
return;
95-
}
96-
9797
try
9898
{
9999
Uri iconUri = new Uri(_updaterConfig.IconUri, UriKind.Absolute);
@@ -114,15 +114,41 @@ private void CheckUpdates()
114114
try
115115
{
116116
var url = _deploymentService.IsRunningAsInstalled() ? _updaterConfig.UpdateUrlInstaller : _updaterConfig.UpdateUrlSingle;
117+
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
117118
AutoUpdater.Start(url);
118-
_hasCheckedForUpdates = true;
119119
}
120120
catch (Exception ex)
121121
{
122122
_logger.LogError(ex, "Check for updates failed.");
123123
}
124124
}
125125

126+
private async void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
127+
{
128+
if (args == null)
129+
{
130+
_logger.LogWarning("Unable to check for updates at this time.");
131+
return;
132+
}
133+
134+
if (args.IsUpdateAvailable)
135+
{
136+
AutoUpdater.ShowUpdateForm(args);
137+
}
138+
else
139+
{
140+
await ShowNotificationAsync("No updates available.", TimeSpan.FromSeconds(3));
141+
}
142+
}
143+
144+
private async Task ShowNotificationAsync(string msg, TimeSpan delay)
145+
{
146+
NotificationMessage = msg;
147+
IsNotificationOpen = true;
148+
await Task.Delay(delay);
149+
IsNotificationOpen = false;
150+
}
151+
126152
partial void OnThemeChanged(AppTheme value)
127153
{
128154
_userSettingsService.SetTheme(value);

src/UI/Views/SettingsPage.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
88
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
99
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
10+
xmlns:mui="http://metro.mahapps.com/winfx/xaml/controls"
1011
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1112
xmlns:models="clr-namespace:CleanMyPosts.UI.Models"
1213
xmlns:properties="clr-namespace:CleanMyPosts.UI.Properties"
@@ -26,6 +27,24 @@
2627
<RowDefinition Height="*" />
2728
</Grid.RowDefinitions>
2829

30+
<mui:Flyout
31+
x:Name="Notification"
32+
Width="300"
33+
Height="50"
34+
Margin="0"
35+
Padding="10"
36+
HorizontalAlignment="Center"
37+
VerticalAlignment="Top"
38+
AnimateOpacity="True"
39+
Background="{DynamicResource MahApps.Brushes.Control.Background}"
40+
CloseButtonVisibility="Hidden"
41+
Header="{Binding NotificationMessage}"
42+
IsModal="False"
43+
IsOpen="{Binding IsNotificationOpen}"
44+
Opacity="0.9"
45+
Position="Top"
46+
Theme="Inverse" />
47+
2948
<TextBlock Style="{StaticResource PageTitleStyle}" Text="{x:Static properties:Resources.SettingsPageTitle}" />
3049

3150
<StackPanel

0 commit comments

Comments
 (0)