Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Papercut.UI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,28 @@ await this.ShowMessageAsync("Update Not Available",
return;
}

// Get release notes from the update info
var releaseNotesHtml = this._updateInfo.TargetFullRelease.NotesHTML;
var currentVersion = this.GetVersion() ?? "Unknown";
var newVersion = this._updateInfo.TargetFullRelease.Version.ToString();

this._logger.Information("Showing upgrade dialog for version {NewVersion}", newVersion);

// Create upgrade dialog view model
var upgradeDialog = new UI.ViewModels.UpgradeDialogViewModel(currentVersion, newVersion, releaseNotesHtml);

// Show the dialog using the injected window manager
var dialogResult = await this._viewModelWindowManager.ShowDialogAsync(upgradeDialog);

// Check user's choice
if (upgradeDialog.UserChoice != UI.ViewModels.UpgradeChoice.Upgrade)
{
this._logger.Information("User chose to ignore upgrade to version {Version}", newVersion);
return;
}

this._logger.Information("User chose to upgrade to version {Version}", newVersion);

using var cancellationSource = new CancellationTokenSource();

var progressDialog = await this.ShowProgress("Updating", "Downloading Updates...", true,
Expand Down
86 changes: 86 additions & 0 deletions src/Papercut.UI/ViewModels/UpgradeDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Papercut
//
// Copyright © 2008 - 2012 Ken Robertson
// Copyright © 2013 - 2024 Jaben Cargman
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Papercut.UI.ViewModels;

using Caliburn.Micro;

public class UpgradeDialogViewModel : Screen
{
public UpgradeDialogViewModel(
string currentVersion,
string newVersion,
string? releaseNotesHtml)
{
this.CurrentVersion = currentVersion;
this.NewVersion = newVersion;

// Use provided HTML or fallback message
if (string.IsNullOrWhiteSpace(releaseNotesHtml))
{
this.ReleaseNotesHtml = @"
<html>
<head>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 20px;
background-color: white;
color: #666;
}
</style>
</head>
<body>
<p>No release notes available.</p>
</body>
</html>";
}
else
{
this.ReleaseNotesHtml = releaseNotesHtml;
}

this.UserChoice = UpgradeChoice.None;
}

public string CurrentVersion { get; }

public string NewVersion { get; }

public string ReleaseNotesHtml { get; }

public UpgradeChoice UserChoice { get; private set; }

public void Upgrade()
{
this.UserChoice = UpgradeChoice.Upgrade;
this.TryCloseAsync(true);
}

public void Ignore()
{
this.UserChoice = UpgradeChoice.Ignore;
this.TryCloseAsync(false);
}
}

public enum UpgradeChoice
{
None,
Upgrade,
Ignore
}
88 changes: 88 additions & 0 deletions src/Papercut.UI/Views/UpgradeDialogView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<mah:MetroWindow x:Class="Papercut.UI.Views.UpgradeDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
xmlns:viewModels="clr-namespace:Papercut.UI.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:UpgradeDialogViewModel}"
Title="Upgrade Available"
Width="700"
Height="600"
WindowStartupLocation="CenterOwner"
ResizeMode="CanResizeWithGrip"
ShowInTaskbar="False"
BorderThickness="1"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
BorderBrush="{DynamicResource MahApps.Brushes.Accent}">

<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<!-- Header -->
<StackPanel Grid.Row="0" Margin="0,0,0,20">
<TextBlock Text="Upgrade Available"
FontSize="24"
FontWeight="Bold"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}" />

<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="Current Version: "
FontSize="14"
Foreground="{DynamicResource MahApps.Brushes.Gray1}" />
<TextBlock Text="{Binding CurrentVersion}"
FontSize="14"
FontWeight="SemiBold"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}" />
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<TextBlock Text="New Version: "
FontSize="14"
Foreground="{DynamicResource MahApps.Brushes.Gray1}" />
<TextBlock Text="{Binding NewVersion}"
FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource MahApps.Brushes.Accent}" />
</StackPanel>
</StackPanel>

<!-- Separator -->
<Separator Grid.Row="1" Margin="0,0,0,15" />

<!-- Release Notes -->
<Border Grid.Row="2"
BorderThickness="1"
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}"
Background="{DynamicResource MahApps.Brushes.Control.Background}">
<wpf:WebView2 x:Name="ReleaseNotesWebView"
DefaultBackgroundColor="White" />
</Border>

<!-- Buttons -->
<StackPanel Grid.Row="3"
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="0,20,0,0">
<Button x:Name="Ignore"
Content="Ignore"
Width="100"
Height="35"
Margin="0,0,10,0"
Style="{DynamicResource MahApps.Styles.Button}" />

<Button x:Name="Upgrade"
Content="Upgrade"
Width="100"
Height="35"
Style="{DynamicResource MahApps.Styles.Button.Accent}" />
</StackPanel>
</Grid>
</mah:MetroWindow>
58 changes: 58 additions & 0 deletions src/Papercut.UI/Views/UpgradeDialogView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Papercut
//
// Copyright © 2008 - 2012 Ken Robertson
// Copyright © 2013 - 2024 Jaben Cargman
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Papercut.UI.Views;

using MahApps.Metro.Controls;
using Papercut.UI.ViewModels;

public partial class UpgradeDialogView : MetroWindow
{
public UpgradeDialogView()
{
this.InitializeComponent();
this.Loaded += this.OnLoaded;
}

private async void OnLoaded(object sender, RoutedEventArgs e)
{
if (this.DataContext is UpgradeDialogViewModel viewModel)
{
try
{
// Ensure WebView2 is initialized
await this.ReleaseNotesWebView.EnsureCoreWebView2Async();

// Navigate to the release notes HTML
this.ReleaseNotesWebView.NavigateToString(viewModel.ReleaseNotesHtml);
}
catch (Exception ex)
{
// Fallback: show error message in the WebView
var errorHtml = $@"
<html>
<body style='font-family: Segoe UI, sans-serif; padding: 20px;'>
<h3 style='color: #d32f2f;'>Unable to load release notes</h3>
<p>{System.Security.SecurityElement.Escape(ex.Message)}</p>
</body>
</html>";

this.ReleaseNotesWebView.NavigateToString(errorHtml);
}
}
}
}
Loading