Skip to content

Commit

Permalink
下放Ursa和Semi到PluginCore
Browse files Browse the repository at this point in the history
KitopiaEx新增 置顶截图
  • Loading branch information
MakesYT committed Feb 6, 2025
1 parent 459f475 commit 9538196
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 53 deletions.
9 changes: 2 additions & 7 deletions Core/SDKs/Services/Plugin/AssemblyLoadContextH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ protected override Assembly Load(AssemblyName assemblyName)
var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
{
log.Debug(assemblyPath);
if (assemblyPath.EndsWith("WinRT.Runtime.dll") || assemblyPath.EndsWith("Microsoft.Windows.SDK.NET.dll") ||
AppDomain.CurrentDomain.GetAssemblies().Any(x => x.GetName().FullName == assemblyName.FullName))

if (assemblyPath.EndsWith("WinRT.Runtime.dll") || assemblyPath.EndsWith("Microsoft.Windows.SDK.NET.dll")|| assemblyPath.EndsWith("PluginCore.dll")|| assemblyPath.EndsWith("Pinyin.NET.dll") )
{
if (assemblyPath.EndsWith("Microsoft.ML.OnnxRuntime.dll"))
{
return LoadFromAssemblyPath(assemblyPath);
}
return null;
}

Expand Down
83 changes: 45 additions & 38 deletions Core/SDKs/Services/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,54 +277,61 @@ public static void Load(bool init = false)
}


if (File.Exists($"{directoryInfo.FullName}{Path.DirectorySeparatorChar}manifest.json"))
try
{
var readAllText =
File.ReadAllText($"{directoryInfo.FullName}{Path.DirectorySeparatorChar}manifest.json");
var serialize = JsonSerializer.Deserialize<PluginInfo>(readAllText);
if (serialize != null)
if (File.Exists($"{directoryInfo.FullName}{Path.DirectorySeparatorChar}manifest.json"))
{
AllPluginInfos.Add(serialize);
serialize.FullPath = $"{directoryInfo.FullName}{Path.DirectorySeparatorChar}{serialize.Main}";
serialize.Path = $"{directoryInfo.FullName}{Path.DirectorySeparatorChar}";
serialize.IsEnabled = false;
var (item1, versionCheckResults) =
CheckDependencies(previewList, serialize.Dependencies,
ConfigManger.Config.EnabledPluginInfos.Any(e =>
e.ToPlgString() == serialize.ToPlgString()));
if (!item1)
var readAllText =
File.ReadAllText($"{directoryInfo.FullName}{Path.DirectorySeparatorChar}manifest.json");
var serialize = JsonSerializer.Deserialize<PluginInfo>(readAllText);
if (serialize != null)
{
var stringBuilder = new StringBuilder();
foreach (var (key, value) in versionCheckResults)
stringBuilder.AppendLine($"{key} {value.ToString()}");

Log.Error($"加载插件{serialize.Name}时插件错误,缺失依赖\n {stringBuilder}");
var dialog = new DialogContent()
AllPluginInfos.Add(serialize);
serialize.FullPath = $"{directoryInfo.FullName}{Path.DirectorySeparatorChar}{serialize.Main}";
serialize.Path = $"{directoryInfo.FullName}{Path.DirectorySeparatorChar}";
serialize.IsEnabled = false;
var (item1, versionCheckResults) =
CheckDependencies(previewList, serialize.Dependencies,
ConfigManger.Config.EnabledPluginInfos.Any(e =>
e.ToPlgString() == serialize.ToPlgString()));
if (!item1)
{
Title = $"加载插件{serialize.Name}时插件错误",
Content = stringBuilder,
CloseButtonText = "我知道了"
};
((IContentDialog)ServiceManager.Services!.GetService(typeof(IContentDialog))!).ShowDialogAsync(
null,
dialog);
continue;
}

if (serialize.UpdateTargetVersion == 0) serialize.UpdateTargetVersion = serialize.VersionId;
if (serialize.UpdateTargetVersion != serialize.VersionId) DownloadPluginOnline(serialize).Wait();
Log.Debug($"加载插件{serialize.Name}信息成功");
if (ConfigManger.Config.EnabledPluginInfos.Any(e => e.ToPlgString() == serialize.ToPlgString()))
{
serialize.IsEnabled = true;
if (!PluginManager.EnablePlugin.ContainsKey(serialize.ToPlgString())){
Task.Run(() => { Plugin.Load(serialize); }).Wait();
var stringBuilder = new StringBuilder();
foreach (var (key, value) in versionCheckResults)
stringBuilder.AppendLine($"{key} {value.ToString()}");

Log.Error($"加载插件{serialize.Name}时插件错误,缺失依赖\n {stringBuilder}");
var dialog = new DialogContent()
{
Title = $"加载插件{serialize.Name}时插件错误",
Content = stringBuilder,
CloseButtonText = "我知道了"
};
((IContentDialog)ServiceManager.Services!.GetService(typeof(IContentDialog))!).ShowDialogAsync(
null,
dialog);
continue;
}

if (serialize.UpdateTargetVersion == 0) serialize.UpdateTargetVersion = serialize.VersionId;
if (serialize.UpdateTargetVersion != serialize.VersionId) DownloadPluginOnline(serialize).Wait();
Log.Debug($"加载插件{serialize.Name}信息成功");
if (ConfigManger.Config.EnabledPluginInfos.Any(e => e.ToPlgString() == serialize.ToPlgString()))
{
serialize.IsEnabled = true;
if (!EnablePlugin.ContainsKey(serialize.ToPlgString())){
Task.Run(() => { Plugin.Load(serialize); }).Wait();
}


}
}
}
}
catch (Exception e)
{
Log.Error("错误", e);
}
}

Log.Debug($"加载插件信息完成共{AllPluginInfos.Count}插件被识别");
Expand Down
2 changes: 0 additions & 2 deletions KitopiaAvalonia/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
<Application.Styles>

<semi:SemiTheme Locale="zh-CN" />

<u-semi:SemiTheme Locale="zh-CN" />
<StyleInclude Source="avares://Semi.Avalonia/Themes/Index.axaml" />
<StyleInclude Source="avares://Semi.Avalonia.ColorPicker/Index.axaml" />
<StyleInclude Source="avares://Semi.Avalonia.DataGrid/Index.axaml" />
<StyleInclude Source="Styles/Styles.axaml" />
Expand Down
8 changes: 4 additions & 4 deletions KitopiaAvalonia/KitopiaAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0.4"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2"/>
<PackageReference Include="Irihi.Ursa" Version="1.6.2" />
<PackageReference Include="Irihi.Ursa.Themes.Semi" Version="1.6.2" />
<PackageReference Include="Irihi.Ursa" Version="1.8.0" />
<PackageReference Include="Irihi.Ursa.Themes.Semi" Version="1.8.0" />
<PackageReference Include="log4net" Version="2.0.17"/>
<PackageReference Include="Markdown.Avalonia" Version="11.0.3-a1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Semi.Avalonia" Version="11.2.1.2" />
<PackageReference Include="Semi.Avalonia.ColorPicker" Version="11.2.1.2" />
<PackageReference Include="Semi.Avalonia" Version="11.2.1.4" />
<PackageReference Include="Semi.Avalonia.ColorPicker" Version="11.2.1.4" />
<PackageReference Include="Semi.Avalonia.DataGrid" Version="11.2.1.4" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0-rc.2.24474.1"/>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions KitopiaAvalonia/Styles/FluentUiStyles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<FontWeight x:Key="ButtonDefaultFontWeight">Bold</FontWeight>
<FontWeight x:Key="ExpanderHeaderFontWeight">Bold</FontWeight>
<FontWeight x:Key="TextBlockTitleFontWeight">600</FontWeight>
<Thickness x:Key="ButtonDefaultPadding">12 6</Thickness>
<ControlTheme x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="Foreground" Value="{DynamicResource ToolTipForeground}" />
<Setter Property="Background" Value="{DynamicResource ToolTipBackground}" />
Expand Down
20 changes: 20 additions & 0 deletions KitopiaEx/ImagePin/ImagePin.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<u:UrsaWindow xmlns="https://github.com/avaloniaui"
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:u="https://irihi.tech/ursa"

mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="KitopiaEx.ImagePin.ImagePin"

Topmost="True"
IsManagedResizerVisible="False"
IsFullScreenButtonVisible="False"
IsMinimizeButtonVisible="False"
IsRestoreButtonVisible="False"
BorderBrush="Transparent"
Background="Transparent"
CanResize="False"
Title="ImagePin">
<Image x:Name="Image" PointerPressed="Image_OnPointerPressed"></Image>
</u:UrsaWindow>
34 changes: 34 additions & 0 deletions KitopiaEx/ImagePin/ImagePin.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Ursa.Controls;


namespace KitopiaEx.ImagePin;

public partial class ImagePin : UrsaWindow
{
public ImagePin()
{
InitializeComponent();
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (Image.Source is Bitmap bitmap)
{
bitmap.Dispose();
}
}

private void Image_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
BeginMoveDrag(e);
}


}
53 changes: 53 additions & 0 deletions KitopiaEx/ImagePin/ScreenCaptureEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using Avalonia;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Threading;
using PluginCore;
using PluginCore.Attribute;

namespace KitopiaEx.ImagePin;

public class ScreenCaptureEx
{
[Capture("置顶图片", 0xf602)]
public void Pin(ScreenCaptureResult dResult)
{
if (dResult.Bytes is null&& dResult.Source is null)
{
throw new Exception("无图像数据");
}

Dispatcher.UIThread.Invoke((() =>
{
if (dResult.Source is null)
{

var writeableBitmap = new WriteableBitmap(
new PixelSize(dResult.Info.Width, dResult.Info.Height),
new Vector(96, 96), PixelFormat.Bgra8888);
using (var l = writeableBitmap.Lock())
{
unsafe
{
var destinationSizeInBytes = dResult.Info.Width * 4 * dResult.Info.Height;
fixed (byte* srcPtr = dResult.Bytes)
{
Buffer.MemoryCopy(srcPtr, (void*)l.Address, destinationSizeInBytes, destinationSizeInBytes);
}

}
}

dResult.Source = writeableBitmap;

}

var imagePin = new ImagePin();
imagePin.Image.Source = dResult.Source;
imagePin.Width = dResult.Info.Width;
imagePin.Height = dResult.Info.Height;
imagePin.Show();
}));
}
}
6 changes: 5 additions & 1 deletion KitopiaEx/KitopiaEx.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using KitopiaEx.CustomScenarioValueSerializer;
using KitopiaEx.ImagePin;
using KitopiaEx.INodeInputConnector.ScreenCaptureInfoSelfConnector;
using KitopiaEx.Ocr;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -70,11 +71,14 @@ public static IServiceProvider GetServiceProvider()
services.AddSingleton<ImageTools>();
services.AddSingleton<SearchItemEx>();
services.AddSingleton<ClipboardEx>();
services.AddSingleton<ImageTools>();

services.AddTransient<ScreenCaptureInfoSelfConnector>();
services.AddSingleton<KeyboardSimulation>();
services.AddSingleton<ScreenCaptureNode>();
services.AddTransient<Ocr.Ocr>();

services.AddTransient<ScreenCaptureEx>();
services.AddTransient<ImagePin.ImagePin>();
return services.BuildServiceProvider();
}
}
2 changes: 1 addition & 1 deletion PluginCore
Submodule PluginCore updated 1 files
+5 −0 PluginCore.csproj

0 comments on commit 9538196

Please sign in to comment.