Skip to content

Commit

Permalink
feat: 删除 WebView2 环境
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassianvale committed Jan 16, 2025
1 parent 226575e commit e9149ba
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 683 deletions.
12 changes: 0 additions & 12 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ private void Cleanup(CleanupLevel level = CleanupLevel.Normal)
{
_logger.Debug($"开始清理服务... 清理级别: {level}");

// 清理 WebView2 环境
try
{
var webView2Service = Services.WebView2Service.Instance;
webView2Service.Dispose();
_logger.Debug("WebView2 服务已清理");
}
catch (Exception ex)
{
_logger.Error("清理 WebView2 服务失败", ex);
}

// 确保所有服务都被释放
if (LyKeysDriver != null)
{
Expand Down
73 changes: 73 additions & 0 deletions Services/Cache/MarkdownCacheService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Windows.Documents;
using Markdig;
using Markdig.Syntax;

namespace WpfApp.Services.Cache
{
public class MarkdownCacheService
{
private static readonly Lazy<MarkdownCacheService> _instance =
new Lazy<MarkdownCacheService>(() => new MarkdownCacheService());

public static MarkdownCacheService Instance => _instance.Value;

private string _cachedMarkdown;
private MarkdownDocument _cachedDocument;
private readonly MarkdownPipeline _pipeline;
private readonly object _lock = new object();
private readonly SerilogManager _logger = SerilogManager.Instance;

private MarkdownCacheService()
{
_pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.Build();
}

public void SetMarkdownContent(string markdown)
{
lock (_lock)
{
try
{
_cachedMarkdown = markdown;
_cachedDocument = Markdown.Parse(markdown, _pipeline);
_logger.Debug("Markdown内容已缓存");
}
catch (Exception ex)
{
_logger.Error("缓存Markdown内容失败", ex);
throw;
}
}
}

public (string RawMarkdown, MarkdownDocument ParsedDocument) GetMarkdownContent()
{
lock (_lock)
{
return (_cachedMarkdown, _cachedDocument);
}
}

public bool HasContent()
{
lock (_lock)
{
return !string.IsNullOrEmpty(_cachedMarkdown) && _cachedDocument != null;
}
}

public void ClearCache()
{
lock (_lock)
{
_cachedMarkdown = null;
_cachedDocument = null;
_logger.Debug("Markdown缓存已清除");
}
}
}
}
132 changes: 0 additions & 132 deletions Services/Utils/WebView2Service.cs

This file was deleted.

Loading

0 comments on commit e9149ba

Please sign in to comment.