Conversation
…le keeping the macOS .app bundle download step intact.
…me to reference it from the embedded manifest resource stream This commit adds `js-yaml.min.js` as an embedded resource in the project file with the logical name `MermaidPad.Assets.js-yaml.min.js`. It also removes the previous entries for `js-yaml.min.js` that were listed as a `None` type and as an `EmbeddedResource`, indicating that the file is no longer treated as a resource in the project. #38
Removed the `ExtractAssetsOnce` method from `ServiceConfiguration.cs` and replaced it with a call to `EmbeddedResourceHelper.ExtractAssets` for centralized asset extraction. Updated logging messages and removed constants for asset filenames. Introduced a new `ExtractAssets` method in `EmbeddedResourceHelper.cs` to handle embedded asset extraction with improved logging and validation. Consolidated individual asset extraction into a loop for better maintainability. Updated asset validation logic to utilize a list of required assets, enhancing clarity and extensibility of the code.
Updated the MermaidRenderer class to include support for the js-yaml.min.js file. Defined constants for the file name and request path, added existence checks during content preparation, and implemented asynchronous reading of the file. Modified HTTP request handling to serve the js-yaml file when requested.
Updated `ValidateAssets` method for clarity and functionality. Changed parameter name to `assetsDirectory` and modified logic to collect missing files in a list. Enhanced error handling with detailed messages for missing assets.
Updated the method of finding the first newline character in the exception's StackTrace. The change replaces the hardcoded `'\n'` with `Environment.NewLine` to ensure platform independence and correct newline handling across different environments.
This commit introduces a new asynchronous method, `GetEmbeddedResourceAsync`, in `EmbeddedResourceHelper.cs` that retrieves the content of an embedded resource as a byte array. The method is documented with XML comments detailing its functionality, parameters, return values, and potential exceptions. Additionally, a `using` directive for `System.Text` has been added to facilitate string encoding operations.
- Updated `ServiceConfiguration` to use `AssetHelper` for asset extraction. - Renamed `EmbeddedResourceHelper` to `AssetHelper` and improved documentation. - Introduced constants for asset file names to enhance maintainability. - Added `GetAssetFromDiskAsync` method for asynchronous asset retrieval with error handling. - Changed encoding handling to use a static readonly field for consistency. - Updated stream reading to utilize the new encoding field.
- Removed asset directory parameters and introduced AssetHelper for better asset management. - Transitioned from string-based content to byte arrays for enhanced performance and safety. - Updated method names and improved logging for better insights during asset preparation.
Updated `<script>` tags for `mermaid.min.js` and `js-yaml.min.js` to include the `defer` attribute. This change allows the scripts to execute after the document has been parsed, improving page load performance by preventing blocking of page rendering.
Refactor code to ensure `mermaid` and `jsyaml` are accessed as global objects via the `window` object. This change improves compatibility across different contexts. Specifically, the `retries` variable is now defined using `window._mermaidRetries`, and both libraries are initialized and rendered with the `window.` prefix.
Added and modified several code style settings for C# development in the `.editorconfig` file, including: - Inferred names for tuples and anonymous types - Compound assignment operator suggestions - Simplified string interpolation - Collection initializers for loosely matched types - Namespace structure matching folder structure - Resharper setting to disable highlighting for evident type object creation
Closed
Updated the `retries` variable from `const` to `let` to allow reassignment. This change is necessary for the retry logic to function correctly when rendering Mermaid diagrams, while the overall logic remains unchanged.
Refactor the handling of exception stack traces in the `SimpleLogger` class by introducing a `ReadOnlySpan<char>` to store the stack trace. This change reduces redundant access to `ex.StackTrace`, improving efficiency and readability when extracting the first line of the stack trace.
Added a new "Downloads" section in `build-and-release.yml` for macOS, detailing installation steps for a Universal DMG. Updated previous macOS installation notes and included new download options for Windows and Linux, featuring zip files for x64 and ARM64 architectures. These changes improve clarity and usability for users across different platforms.
…es" instead of "characters." Added a new log message to report the length of the prepared YAML content in bytes.
Removed unused Encoding references and optimized stream reading. The new implementation directly reads bytes from the stream, enhancing performance by eliminating unnecessary string conversions.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the asset management system and adds YAML configuration support for Mermaid diagrams. The changes consolidate asset handling logic into a new AssetHelper class and integrate js-yaml.min.js for parsing YAML configuration blocks.
- Refactored asset management from
ServiceConfigurationandEmbeddedResourceHelperinto centralizedAssetHelper - Added support for YAML configuration blocks in Mermaid diagrams with js-yaml integration
- Updated initialization methods to use the new asset helper and removed parameter dependencies
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Views/MainWindow.axaml.cs | Updated WebView initialization to use parameterless method and simplified asset handling |
| ViewModels/MainViewModel.cs | Removed default values from observable properties |
| Services/SimpleLogger.cs | Improved stack trace parsing using Environment.NewLine |
| Services/Platforms/EmbeddedResourceHelper.cs | Deleted - functionality moved to AssetHelper |
| Services/Platforms/AssetHelper.cs | New centralized asset management class with extraction, validation, and retrieval |
| Services/MermaidRenderer.cs | Updated to use AssetHelper for asset retrieval and added js-yaml support |
| MermaidSamples.txt | Added example showing YAML configuration usage |
| MermaidPad.csproj | Added js-yaml.min.js as embedded resource |
| Infrastructure/ServiceConfiguration.cs | Simplified by delegating asset extraction to AssetHelper |
| Assets/index.html | Added js-yaml script and YAML configuration parsing logic |
| .github/workflows/build-and-release.yml | Updated release documentation and download instructions |
| .editorconfig | Added Resharper code style configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Classification
Code cleanup and new feature implementation #38
PR Summary
This pull request refactors the asset management system and enhances the Mermaid diagram rendering capabilities by integrating YAML parsing. Key changes include:
ServiceConfiguration.cs: Refactored to useAssetHelperfor asset extraction and validation.MermaidRenderer.cs: Updated to utilizeAssetHelperfor retrieving assets, simplifying initialization.index.html: Added support for YAML configuration blocks and included the newjs-yaml.min.jsscript.AssetHelper.cs: Introduced to manage asset extraction and retrieval, consolidating previous logic..editorconfig: Updated with new code style preferences and Resharper settings.