Skip to content

Implement Provider Pattern for Changelog Viewers and Split WebView2 Package #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ bld/
[Oo]bj/
[Ll]og/

build/
# Keep nuspec files in build directories
!**/build/*.nuspec

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
36 changes: 36 additions & 0 deletions AutoUpdater.NET.Markdown/AutoUpdater.NET.Markdown.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net462;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>AutoUpdaterDotNET.Markdown</RootNamespace>
<AssemblyTitle>AutoUpdater.NET.Markdown</AssemblyTitle>
<Company>RBSoft</Company>
<Product>AutoUpdater.NET.Markdown</Product>
<Copyright>Copyright © 2012-2025 RBSoft</Copyright>
<Version>1.9.5.1</Version>
<!-- <SignAssembly>true</SignAssembly>-->
<!-- <AssemblyOriginatorKeyFile>..\AutoUpdater.NET\AutoUpdater.NET.snk</AssemblyOriginatorKeyFile>-->
<NeutralLanguage>en</NeutralLanguage>
<PackageId>Autoupdater.NET.Markdown</PackageId>
<IncludeSymbols>true</IncludeSymbols>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Title>AutoUpdater.NET Markdown Extension</Title>
<Authors>rbsoft</Authors>
<Description>Markdown extension for AutoUpdater.NET that provides markdown support.</Description>
<PackageProjectUrl>https://github.com/ravibpatel/AutoUpdater.NET</PackageProjectUrl>
<PackageTags>autoupdate updater markdown</PackageTags>
<PackageReleaseNotes>https://github.com/ravibpatel/AutoUpdater.NET/releases</PackageReleaseNotes>
<PackageOutputPath>build</PackageOutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.40.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AutoUpdater.NET\AutoUpdater.NET.csproj" />
</ItemGroup>
</Project>
154 changes: 154 additions & 0 deletions AutoUpdater.NET.Markdown/MarkdownViewer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System.Windows.Forms;
using AutoUpdaterDotNET.ChangelogViewers;
using Markdig;

namespace AutoUpdaterDotNET.Markdown;

/// <summary>
/// A changelog viewer that renders Markdown content using either a provided viewer or a WebBrowser control.
/// </summary>
public class MarkdownViewer : IChangelogViewer
{
private readonly IChangelogViewer _innerViewer;
private readonly bool _cleanup;
private const string DefaultStyle = @"
<style>
@font-face {
font-family: 'Segoe UI Emoji';
src: local('Segoe UI Emoji');
}
body {
font-family: 'Segoe UI Emoji', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
font-size: 10.5pt;
line-height: 1.4;
word-wrap: break-word;
padding: 12px;
margin: 0;
background-color: #F4F4F4;
color: #000000;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 16px;
margin-bottom: 8px;
font-weight: 600;
line-height: 1.25;
}
h1 { font-size: 20pt; }
h2 { font-size: 16pt; }
h3 { font-size: 14pt; }
h4 { font-size: 12pt; }
p { margin: 8px 0; }
code {
font-family: Consolas, 'Courier New', monospace;
padding: 2px 4px;
background-color: rgba(0, 0, 0, 0.03);
border-radius: 3px;
font-size: 10pt;
}
pre code {
display: block;
padding: 8px;
margin: 8px 0;
overflow: auto;
line-height: 1.45;
}
blockquote {
padding: 0 8px;
margin: 8px 0;
color: #666666;
border-left: 3px solid #CCCCCC;
}
ul, ol {
padding-left: 24px;
margin: 8px 0;
}
table {
border-spacing: 0;
border-collapse: collapse;
margin: 8px 0;
width: 100%;
}
table th, table td {
padding: 4px 8px;
border: 1px solid #CCCCCC;
}
table tr:nth-child(2n) {
background-color: rgba(0, 0, 0, 0.02);
}
hr {
height: 1px;
padding: 0;
margin: 16px 0;
background-color: #CCCCCC;
border: 0;
}
img {
max-width: 100%;
height: auto;
}
a {
color: #0066CC;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>";

/// <summary>
/// Initializes a new instance of the MarkdownViewer class.
/// </summary>
/// <param name="viewer">Optional viewer to use for rendering. If not provided, uses WebBrowser control.</param>
/// <param name="cleanup">Whether to clean up the inner viewer when this viewer is disposed.</param>
public MarkdownViewer(IChangelogViewer viewer = null, bool cleanup = true)
{
_innerViewer = viewer ?? new WebBrowserViewer();
_cleanup = cleanup || viewer == null;
}

/// <inheritdoc />
public Control Control => _innerViewer.Control;

/// <inheritdoc />
public bool SupportsUrl => true;

/// <inheritdoc />
public void LoadContent(string content)
{
if (_innerViewer is RichTextBoxViewer or MarkdownViewer)
{
_innerViewer.LoadContent(content);
return;
}

var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.Build();

var html = Markdig.Markdown.ToHtml(content, pipeline);
var fullHtml = $"<!DOCTYPE html><html><head>{DefaultStyle}</head><body>{html}</body></html>";

_innerViewer.LoadContent(fullHtml);
}

/// <inheritdoc />
public void LoadUrl(string url)
{
using var client = new System.Net.WebClient();
if (AutoUpdater.BasicAuthChangeLog != null)
{
var auth = (BasicAuthentication)AutoUpdater.BasicAuthChangeLog;
client.Credentials = new System.Net.NetworkCredential(auth.Username, auth.Password);
}

var content = client.DownloadString(url);
LoadContent(content);
}

/// <inheritdoc />
public void Cleanup()
{
if (_cleanup)
_innerViewer.Cleanup();
}
}
39 changes: 39 additions & 0 deletions AutoUpdater.NET.Markdown/MarkdownViewerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using AutoUpdaterDotNET.ChangelogViewers;

namespace AutoUpdaterDotNET.Markdown;

/// <summary>
/// Provides a Markdown viewer that uses a WebBrowser control or a user provided viewer to render Markdown content.
/// </summary>
public class MarkdownViewerProvider(int priority = 2) : IChangelogViewerProvider
{
private readonly IChangelogViewer _viewer;

/// <summary>
/// Creates a new instance of the <see cref="MarkdownViewerProvider"/> with default priority 2.
/// </summary>
public MarkdownViewerProvider() : this(2) { }

/// <summary>
/// Creates a new instance of the <see cref="MarkdownViewerProvider"/> with a specific viewer.
/// </summary>
/// <param name="viewer">The viewer to use for rendering Markdown content.</param>
/// <param name="priority">The priority of this provider.</param>
public MarkdownViewerProvider(IChangelogViewer viewer, int priority = 2) : this(priority)
{
_viewer = viewer;
}

/// <summary>
/// Gets whether this provider is available. Always returns true as it uses WebBrowser as fallback.
/// </summary>
public bool IsAvailable => true;

/// <inheritdoc />
public int Priority { get; } = priority;

/// <summary>
/// Creates a new instance of the <see cref="MarkdownViewer"/> class.
/// </summary>
public IChangelogViewer CreateViewer() => new MarkdownViewer(_viewer);
}
53 changes: 53 additions & 0 deletions AutoUpdater.NET.Markdown/build/Autoupdater.NET.Markdown.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Autoupdater.NET.Official.Markdown</id>
<version>1.9.5.1</version>
<title>AutoUpdater.NET Markdown Extension</title>
<authors>rbsoft</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<readme>docs\README.md</readme>
<licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
<projectUrl>https://github.com/ravibpatel/AutoUpdater.NET</projectUrl>
<description>Markdown extension for AutoUpdater.NET that provides Markdown rendering capabilities for changelogs.</description>
<releaseNotes>https://github.com/ravibpatel/AutoUpdater.NET/releases</releaseNotes>
<copyright>Copyright 2012-2025 RBSoft</copyright>
<tags>autoupdate updater markdown changelog</tags>
<dependencies>
<group targetFramework=".NETFramework4.6.2">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
<group targetFramework=".NETCoreApp3.1">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
<group targetFramework="net5.0-windows7.0">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
<group targetFramework="net6.0-windows7.0">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
<group targetFramework="net7.0-windows7.0">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
<group targetFramework="net8.0-windows7.0">
<dependency id="Autoupdater.NET.Official" version="1.9.5.1" exclude="Build,Analyzers"/>
<dependency id="Markdig" version="0.40.0" exclude="Build,Analyzers"/>
</group>
</dependencies>
</metadata>
<files>
<file src="..\..\README.md" target="docs\"/>
<file src="lib\net462\AutoUpdater.NET.Markdown.*" target="lib\net462" exclude="**\*.deps.json"/>
<file src="lib\netcoreapp3.1\AutoUpdater.NET.Markdown.*" target="lib\netcoreapp3.1" exclude="**\*.deps.json"/>
<file src="lib\net5.0-windows7.0\AutoUpdater.NET.Markdown.*" target="lib\net5.0-windows7.0" exclude="**\*.deps.json"/>
<file src="lib\net6.0-windows7.0\AutoUpdater.NET.Markdown.*" target="lib\net6.0-windows7.0" exclude="**\*.deps.json"/>
<file src="lib\net7.0-windows7.0\AutoUpdater.NET.Markdown.*" target="lib\net7.0-windows7.0" exclude="**\*.deps.json"/>
<file src="lib\net8.0-windows7.0\AutoUpdater.NET.Markdown.*" target="lib\net8.0-windows7.0" exclude="**\*.deps.json"/>
</files>
</package>
34 changes: 34 additions & 0 deletions AutoUpdater.NET.WebView2/AutoUpdater.NET.WebView2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net462;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>AutoUpdaterDotNET.WebView2</RootNamespace>
<AssemblyTitle>AutoUpdater.NET.WebView2</AssemblyTitle>
<Company>RBSoft</Company>
<Product>AutoUpdater.NET.WebView2</Product>
<Copyright>Copyright © 2012-2025 RBSoft</Copyright>
<Version>1.9.5.1</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\AutoUpdater.NET\AutoUpdater.NET.snk</AssemblyOriginatorKeyFile>
<NeutralLanguage>en</NeutralLanguage>
<PackageId>Autoupdater.NET.WebView2</PackageId>
<IncludeSymbols>true</IncludeSymbols>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Title>AutoUpdater.NET WebView2 Extension</Title>
<Authors>rbsoft</Authors>
<Description>WebView2 extension for AutoUpdater.NET that provides modern web rendering capabilities for changelogs.</Description>
<PackageProjectUrl>https://github.com/ravibpatel/AutoUpdater.NET</PackageProjectUrl>
<PackageTags>autoupdate updater webview2 edge</PackageTags>
<PackageReleaseNotes>https://github.com/ravibpatel/AutoUpdater.NET/releases</PackageReleaseNotes>
<PackageOutputPath>build</PackageOutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3065.39" />
<ProjectReference Include="..\AutoUpdater.NET\AutoUpdater.NET.csproj" />
</ItemGroup>
</Project>
Loading