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

Conversation

w4po
Copy link

@w4po w4po commented Feb 25, 2025

Overview

This PR introduces a flexible provider pattern for changelog viewers, splits the WebView2 functionality into a separate package, and adds a new Markdown package for enhanced changelog rendering. These changes improve the modularity, extensibility, and maintainability of the AutoUpdater.NET library.

Features

  • Multiple Viewer Options:

    • RichTextBox: Simple text display without HTML rendering
    • WebBrowser: Legacy IE-based browser (fallback option)
    • WebView2: Modern Edge WebView2 for full HTML/CSS support
    • Markdown: GitHub-style Markdown rendering with modern styling
  • Content Loading Options:

    • Load from URL (WebBrowser, WebView2, and Markdown)
    • Load direct text content (all viewers)
  • User Configuration:

    • Set preferred viewer via AutoUpdater.ChangelogViewerProvider
    • Automatic fallback if the preferred viewer is unavailable
    • Customizable viewer priority system
  • Extensibility:

    • Implement IChangelogViewer interface for custom viewers
    • Support for composite viewer pattern

Key Changes

1. Provider Pattern Implementation

  • Introduced IChangelogViewerProvider interface for implementing custom changelog viewers
  • Created ChangelogViewerFactory to manage and create viewer instances
  • Added support for priority-based viewer selection
  • Implemented automatic registration of providers through extension loading

2. Package Split

  • Moved WebView2-related code to a separate package (AutoUpdater.NET.Official.WebView2)
  • Created new Markdown package (AutoUpdater.NET.Official.Markdown)
  • Reduced core package dependencies by making WebView2 and Markdown optional
  • Added automatic registration of providers through module initialization

3. Markdown Support

  • Added GitHub-style Markdown rendering with modern CSS
  • Implemented emoji support through Segoe UI Emoji font
  • Created composite viewer pattern for flexible rendering options
  • Included proper cleanup handling for viewer resources

4. Configuration and Control

  • Added AutoLoadExtensions property to control automatic loading of viewer extensions
  • Introduced ChangelogViewerProvider property for explicit viewer selection
  • Improved error handling with descriptive messages

5. Default Viewers

  • Maintained RichTextBox and WebBrowser viewers as default options
  • Ensured backward compatibility with existing implementations
  • Added proper fallback mechanism when preferred viewers are unavailable

Benefits

  1. Modularity: Users can now choose which viewer implementations to include
  2. Extensibility: Custom viewers can be easily added through the provider pattern
  3. Flexibility: Priority system allows for smart fallback behavior
  4. Maintainability: Clear separation of concerns and improved code organization
  5. Performance: Optional dependencies reduce the core package size
  6. Enhanced Rendering: Modern Markdown support with GitHub-style formatting

Breaking Changes

None. All changes are backward compatible:

  • Existing code continues to work without modification
  • WebView2 and Markdown functionality available through new packages
  • Default viewers maintain their previous behavior

Usage Example

// Disable automatic extension loading if desired
AutoUpdater.AutoLoadExtensions = false;

// Use WebView2 viewer
AutoUpdater.ChangelogViewerProvider = new WebView2ViewerProvider();

// Or use Markdown viewer with default priority
AutoUpdater.ChangelogViewerProvider = new MarkdownViewerProvider();

// Use Markdown viewer with custom priority and viewer
var customViewer = new WebView2Viewer(); // or any IChangelogViewer
AutoUpdater.ChangelogViewerProvider = new MarkdownViewerProvider(customViewer, priority: 3);

// Or let the factory choose the best available viewer

Testing Notes

  • Tested with all default viewer implementations
  • Verified extension loading mechanism
  • Confirmed priority-based selection works as expected
  • Validated backward compatibility
  • Tested error handling and fallback behavior
  • Verified Markdown rendering with various content types

Future Considerations

  • Add more built-in viewer implementations

Related Issues

#470 #496 #73 #692

w4po added 2 commits February 24, 2025 05:28
Implements a flexible plugin system for displaying changelog content with multiple viewer options:
- Add IChangelogViewer interface for viewer implementations
- Add RichTextBox viewer for simple text display
- Add WebBrowser viewer for legacy IE-based browser
- Add WebView2 viewer for modern Edge WebView2
- Add ChangelogViewerFactory for viewer instantiation

Users can now:
- Choose their preferred viewer type via AutoUpdater.ChangelogViewerType
- Load content directly as text or from URL (where supported)
- Extend the system with custom viewer implementations

The system automatically handles viewer initialization, cleanup, and fallback behavior when preferred viewers are unavailable.
- Move WebView2 viewer into its own NuGet package to reduce core dependencies
- Implement extension-based architecture for changelog viewers
- Add auto-discovery of viewer extensions at runtime
- Update core package to dynamically load WebView2 when available
- Remove WebView2 dependency from core package
- Clean up project structure and dependencies

This change makes the WebView2 viewer optional, reducing the core package size
and dependencies. Users who want WebView2 support can install the additional
package, while the core functionality remains lightweight.
@w4po w4po force-pushed the split-core-webview2-markdown branch from f40dbeb to 4710dbd Compare February 28, 2025 03:32
…kage

Introduce a new package for rendering Markdown changelogs with enhanced styling and flexibility:

- Add AutoUpdater.NET.Official.Markdown package with modern CSS styling and emoji support
- Implement composite viewer pattern allowing to use and viewer like Webview2/WebBrowser/RichTextBox
- Improve documentation with XML comments and see tags
- Update build scripts to include Markdown package compilation
- Bump version to 1.9.5.1 across all packages
- Update copyright year to 2025

The new Markdown package provides:
- GitHub-style Markdown rendering
- Customizable viewer priority system
- Support for both WebView2 and WebBrowser rendering
- Proper cleanup handling for viewer resources
@w4po w4po force-pushed the split-core-webview2-markdown branch from 4710dbd to bedddef Compare February 28, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant