Skip to content

Commit fc26885

Browse files
committed
Add upgrade dialog with release notes display
When clicking the upgrade notification, shows a dialog with: - Current and new version information - Release notes from Velopack (NotesHTML) - Upgrade and Ignore buttons User can review release notes before deciding to upgrade. Closes #344
1 parent 0ad6265 commit fc26885

File tree

4 files changed

+255
-0
lines changed

4 files changed

+255
-0
lines changed

src/Papercut.UI/ViewModels/MainViewModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,29 @@ await this.ShowMessageAsync("Update Not Available",
489489
return;
490490
}
491491

492+
// Get release notes from the update info
493+
var releaseNotesHtml = this._updateInfo.TargetFullRelease.NotesHTML;
494+
var currentVersion = this.GetVersion() ?? "Unknown";
495+
var newVersion = this._updateInfo.TargetFullRelease.Version.ToString();
496+
497+
this._logger.Information("Showing upgrade dialog for version {NewVersion}", newVersion);
498+
499+
// Create upgrade dialog view model
500+
var upgradeDialog = new UI.ViewModels.UpgradeDialogViewModel(currentVersion, newVersion, releaseNotesHtml);
501+
502+
// Get the window manager from DI and show the dialog manually
503+
var windowManager = new Caliburn.Micro.WindowManager();
504+
var dialogResult = await windowManager.ShowDialogAsync(upgradeDialog);
505+
506+
// Check user's choice
507+
if (upgradeDialog.UserChoice != UI.ViewModels.UpgradeChoice.Upgrade)
508+
{
509+
this._logger.Information("User chose to ignore upgrade to version {Version}", newVersion);
510+
return;
511+
}
512+
513+
this._logger.Information("User chose to upgrade to version {Version}", newVersion);
514+
492515
using var cancellationSource = new CancellationTokenSource();
493516

494517
var progressDialog = await this.ShowProgress("Updating", "Downloading Updates...", true,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Papercut
2+
//
3+
// Copyright © 2008 - 2012 Ken Robertson
4+
// Copyright © 2013 - 2024 Jaben Cargman
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
namespace Papercut.UI.ViewModels;
19+
20+
using Caliburn.Micro;
21+
22+
public class UpgradeDialogViewModel : Screen
23+
{
24+
public UpgradeDialogViewModel(
25+
string currentVersion,
26+
string newVersion,
27+
string? releaseNotesHtml)
28+
{
29+
this.CurrentVersion = currentVersion;
30+
this.NewVersion = newVersion;
31+
32+
// Use provided HTML or fallback message
33+
if (string.IsNullOrWhiteSpace(releaseNotesHtml))
34+
{
35+
this.ReleaseNotesHtml = @"
36+
<html>
37+
<head>
38+
<style>
39+
body {
40+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
41+
padding: 20px;
42+
background-color: white;
43+
color: #666;
44+
}
45+
</style>
46+
</head>
47+
<body>
48+
<p>No release notes available.</p>
49+
</body>
50+
</html>";
51+
}
52+
else
53+
{
54+
this.ReleaseNotesHtml = releaseNotesHtml;
55+
}
56+
57+
this.UserChoice = UpgradeChoice.None;
58+
}
59+
60+
public string CurrentVersion { get; }
61+
62+
public string NewVersion { get; }
63+
64+
public string ReleaseNotesHtml { get; }
65+
66+
public UpgradeChoice UserChoice { get; private set; }
67+
68+
public void Upgrade()
69+
{
70+
this.UserChoice = UpgradeChoice.Upgrade;
71+
this.TryCloseAsync(true);
72+
}
73+
74+
public void Ignore()
75+
{
76+
this.UserChoice = UpgradeChoice.Ignore;
77+
this.TryCloseAsync(false);
78+
}
79+
}
80+
81+
public enum UpgradeChoice
82+
{
83+
None,
84+
Upgrade,
85+
Ignore
86+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<mah:MetroWindow x:Class="Papercut.UI.Views.UpgradeDialogView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
7+
xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
8+
xmlns:viewModels="clr-namespace:Papercut.UI.ViewModels"
9+
mc:Ignorable="d"
10+
d:DataContext="{d:DesignInstance Type=viewModels:UpgradeDialogViewModel}"
11+
Title="Upgrade Available"
12+
Width="700"
13+
Height="600"
14+
WindowStartupLocation="CenterOwner"
15+
ResizeMode="CanResizeWithGrip"
16+
ShowInTaskbar="False"
17+
BorderThickness="1"
18+
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
19+
BorderBrush="{DynamicResource MahApps.Brushes.Accent}">
20+
21+
<Grid Margin="20">
22+
<Grid.RowDefinitions>
23+
<RowDefinition Height="Auto" />
24+
<RowDefinition Height="Auto" />
25+
<RowDefinition Height="*" />
26+
<RowDefinition Height="Auto" />
27+
</Grid.RowDefinitions>
28+
29+
<!-- Header -->
30+
<StackPanel Grid.Row="0" Margin="0,0,0,20">
31+
<TextBlock Text="Upgrade Available"
32+
FontSize="24"
33+
FontWeight="Bold"
34+
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}" />
35+
36+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
37+
<TextBlock Text="Current Version: "
38+
FontSize="14"
39+
Foreground="{DynamicResource MahApps.Brushes.Gray1}" />
40+
<TextBlock Text="{Binding CurrentVersion}"
41+
FontSize="14"
42+
FontWeight="SemiBold"
43+
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}" />
44+
</StackPanel>
45+
46+
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
47+
<TextBlock Text="New Version: "
48+
FontSize="14"
49+
Foreground="{DynamicResource MahApps.Brushes.Gray1}" />
50+
<TextBlock Text="{Binding NewVersion}"
51+
FontSize="14"
52+
FontWeight="Bold"
53+
Foreground="{DynamicResource MahApps.Brushes.Accent}" />
54+
</StackPanel>
55+
</StackPanel>
56+
57+
<!-- Separator -->
58+
<Separator Grid.Row="1" Margin="0,0,0,15" />
59+
60+
<!-- Release Notes -->
61+
<Border Grid.Row="2"
62+
BorderThickness="1"
63+
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}"
64+
Background="{DynamicResource MahApps.Brushes.Control.Background}">
65+
<wpf:WebView2 x:Name="ReleaseNotesWebView"
66+
DefaultBackgroundColor="White" />
67+
</Border>
68+
69+
<!-- Buttons -->
70+
<StackPanel Grid.Row="3"
71+
Orientation="Horizontal"
72+
HorizontalAlignment="Right"
73+
Margin="0,20,0,0">
74+
<Button x:Name="Ignore"
75+
Content="Ignore"
76+
Width="100"
77+
Height="35"
78+
Margin="0,0,10,0"
79+
Style="{DynamicResource MahApps.Styles.Button}" />
80+
81+
<Button x:Name="Upgrade"
82+
Content="Upgrade"
83+
Width="100"
84+
Height="35"
85+
Style="{DynamicResource MahApps.Styles.Button.Accent}" />
86+
</StackPanel>
87+
</Grid>
88+
</mah:MetroWindow>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Papercut
2+
//
3+
// Copyright © 2008 - 2012 Ken Robertson
4+
// Copyright © 2013 - 2024 Jaben Cargman
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
namespace Papercut.UI.Views;
19+
20+
using MahApps.Metro.Controls;
21+
using Papercut.UI.ViewModels;
22+
23+
public partial class UpgradeDialogView : MetroWindow
24+
{
25+
public UpgradeDialogView()
26+
{
27+
this.InitializeComponent();
28+
this.Loaded += this.OnLoaded;
29+
}
30+
31+
private async void OnLoaded(object sender, RoutedEventArgs e)
32+
{
33+
if (this.DataContext is UpgradeDialogViewModel viewModel)
34+
{
35+
try
36+
{
37+
// Ensure WebView2 is initialized
38+
await this.ReleaseNotesWebView.EnsureCoreWebView2Async();
39+
40+
// Navigate to the release notes HTML
41+
this.ReleaseNotesWebView.NavigateToString(viewModel.ReleaseNotesHtml);
42+
}
43+
catch (Exception ex)
44+
{
45+
// Fallback: show error message in the WebView
46+
var errorHtml = $@"
47+
<html>
48+
<body style='font-family: Segoe UI, sans-serif; padding: 20px;'>
49+
<h3 style='color: #d32f2f;'>Unable to load release notes</h3>
50+
<p>{System.Security.SecurityElement.Escape(ex.Message)}</p>
51+
</body>
52+
</html>";
53+
54+
this.ReleaseNotesWebView.NavigateToString(errorHtml);
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)