Skip to content
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
24 changes: 24 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Mirror Repo

on:
push:
branches:
- "*"
workflow_dispatch:

jobs:
mirror-repo:
runs-on: ubuntu-latest

steps:
- name: Mirror
uses: Yikun/hub-mirror-action@master
with:
src: github/Crequency
dst: gitee/Crequency
dst_key: ${{ secrets.GITEE_SYNC_KEY }}
dst_token: ${{ secrets.GITEE_SYNC_TOKEN }}
account_type: org
static_list: "KitX-Plugins"
force_update: true
debug: true
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Ignore Visual Studio temporary files, build results, and
## Platform ignores
.DS_Store

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
Expand Down Expand Up @@ -348,3 +351,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Official Plugins working folder
OfficialPlugins/
111 changes: 92 additions & 19 deletions TestPlugin.CSharp/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
using KitX.Contract.CSharp;
using KitX.Shared.Plugin;
using KitX.Shared.WebCommand;
using System.Text;
using System.Text.Json;
using KitX.Contract.CSharp;
using KitX.Shared.CSharp.Plugin;
using KitX.Shared.CSharp.WebCommand;
using KitX.Shared.CSharp.WebCommand.Details;
using KitX.Shared.CSharp.WebCommand.Infos;

namespace TestPlugin.CSharp;

public class Controller : IController
{
private Action<Command>? sendCommandAction;
private Action<Request>? sendCommandAction;

private static readonly JsonSerializerOptions serializerOptions = new()
{
WriteIndented = true,
IncludeFields = true,
PropertyNameCaseInsensitive = true,
};

public void Start()
{
Expand All @@ -27,27 +37,90 @@ public void End()
public void Execute(Command cmd)
{
Console.WriteLine($"Execute: {JsonSerializer.Serialize(cmd)}");
}

public List<Function> GetFunctions()
{
return [];
}
// 从 Tags 中获取 RequestId,用于发送响应
string? requestId = null;
if (cmd.Tags is not null && cmd.Tags.TryGetValue("RequestId", out var reqId))
{
requestId = reqId;
}

public void SetSendCommandAction(Action<Command> action) => sendCommandAction = action;
if (cmd.FunctionName == "SayHello")
{
// 从参数中获取 name
var name = "World"; // 默认值

public void SetRootPath(string path)
{
Console.WriteLine($"Root path: {path}");
}
if (cmd.FunctionArgs is not null && cmd.FunctionArgs.Count > 0)
{
var firstArg = cmd.FunctionArgs[0];
name = firstArg.Value ?? "World";
}

public void SetWorkPath(string path)
{
Console.WriteLine($"Work path: {path}");
var result = $"Hello, {name}!";
Console.WriteLine($"SayHello result: {result}");

// 如果有 RequestId,发送响应
if (requestId is not null && sendCommandAction is not null)
{
var responseBytes = Encoding.UTF8.GetBytes(result);

var responseCommand = new Command
{
Request = CommandRequestInfo.ReceiveCommand,
PluginConnectionId = cmd.PluginConnectionId ?? string.Empty,
Body = responseBytes,
BodyLength = responseBytes.Length,
Tags = new Dictionary<string, string>
{
{ "RequestId", requestId }
}
};

var responseRequest = new Request
{
Content = JsonSerializer.Serialize(responseCommand, serializerOptions)
};

sendCommandAction.Invoke(responseRequest);
Console.WriteLine($"[DEBUG] Response sent via sendCommandAction: {result}");
}
}
}

public void SetCommandsSendBuffer(ref Queue<Command> commands)
public List<Function> GetFunctions()
{
throw new NotImplementedException();
return [
new Function()
{
Name = "SayHello",
DisplayNames = new()
{
{ "zh-cn", "打招呼" },
{ "zh-tw", "打招呼" },
{ "en-us", "Say Hello" },
},
ReturnValueType = "string",
Parameters = [
new Parameter()
{
Name = "name",
Type = "string",
DisplayNames = new()
{
{ "zh-cn", "姓名" },
{ "zh-tw", "姓名" },
{ "en-us", "Name" },
},
IsOptional = false,
}
],
}
];
}

public void SetSendCommandAction(Action<Request> action) => sendCommandAction = action;

public void SetWorkingDetail(PluginWorkingDetail workingDetail) => Console.WriteLine(
$"WorkingDetail: {JsonSerializer.Serialize(workingDetail)}"
);
}
96 changes: 57 additions & 39 deletions TestPlugin.CSharp/IdentityInterface.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
using KitX.Contract.CSharp;
using KitX.Shared.CSharp.Plugin;

namespace TestPlugin.CSharp;

public class IdentityInterface : IIdentityInterface
{
public string GetName() => "TestPlugin.CSharp";
public IController GetController() => new Controller();

public string GetVersion() => "v0.1.0";
public IMarketPluginContract GetMarketPluginContract() => null!;

public Dictionary<string, string> GetDisplayName() => new()
public PluginInfo GetPluginInfo() => new()
{
Name = "TestPlugin.CSharp",
Version = "v0.1.0",
DisplayName = new()
{
{ "zh-cn", "适用于 C# 的 KitX 测试用插件" },
{ "zh-cnt", "適用於 C# 的 KitX 測試用插件" },
{ "zh-tw", "適用於 C# 的 KitX 測試用插件" },
{ "en-us", "KitX Testing Plugin for C#" },
};

public string GetAuthorName() => "Dynesshely";

public string GetPublisherName() => "Crequency";

public string GetAuthorLink() => "https://blog.catrol.cn";

public string GetPublisherLink() => "https://catrol.cn";

public Dictionary<string, string> GetSimpleDescription() => new()
},
AuthorName = "Dynesshely",
AuthorLink = "https://blog.catrol.cn",
PublisherName = "Crequency",
PublisherLink = "https://catrol.cn",
SimpleDescription = new()
{
{ "zh-cn", "KitX 测试用插件" },
{ "zh-cnt", "KitX 測試用插件" },
{ "zh-tw", "KitX 測試用插件" },
{ "en-us", "KitX Test Plugin" },
};

public Dictionary<string, string> GetComplexDescription() => new()
},
ComplexDescription = new()
{
{ "zh-cn", "KitX 测试用插件, 使用 KitX.Loader.CSharp 作为加载器." },
{ "zh-cnt", "KitX 測試用插件, 使用 KitX.Loader.CSharp 作爲加載器." },
{ "zh-tw", "KitX 測試用插件, 使用 KitX.Loader.CSharp 作爲加載器." },
{ "en-us", "KitX Test Plugin, use KitX.Loader.CSharp as loader." },
};

public Dictionary<string, string> GetTotalDescriptionInMarkdown() => new()
},
TotalDescriptionInMarkdown = new()
{
{
"zh-cn",
Expand All @@ -48,7 +46,7 @@ 使用 KitX.Loader.CSharp 作为加载器
"""
},
{
"zh-cnt",
"zh-tw",
"""
# 關於
這是一個適用於 C# 的 KitX 測試用插件
Expand All @@ -63,19 +61,39 @@ 使用 KitX.Loader.CSharp 作爲加載器
Use KitX.Loader.CSharp as loader
"""
},
};

public string GetIconInBase64() => "图标";

public DateTime GetPublishDate() => DateTime.Now;

public DateTime GetLastUpdateDate() => DateTime.Now;

public IController GetController() => new Controller();

public bool IsMarketVersion() => false;

public IMarketPluginContract GetMarketPluginContract() => null;

public string GetRootStartupFileName() => "TestPlugin.CSharp.dll";
},
IconInBase64 = "Icon",
PublishDate = DateTime.Now,
LastUpdateDate = DateTime.Now,
IsMarketVersion = false,
RootStartupFileName = "TestPlugin.CSharp.dll",
Tags = [],
Functions = [
new Function()
{
Name = "SayHello",
DisplayNames = new()
{
{ "zh-cn", "打招呼" },
{ "zh-tw", "打招呼" },
{ "en-us", "Say Hello" },
},
ReturnValueType = "string",
Parameters = [
new Parameter()
{
Name = "name",
Type = "string",
DisplayNames = new()
{
{ "zh-cn", "姓名" },
{ "zh-tw", "姓名" },
{ "en-us", "Name" },
},
IsOptional = false,
}
],
}
]
};
}
3 changes: 1 addition & 2 deletions TestPlugin.CSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

Console.WriteLine("Hello, World!");
// 插件入口点 - 不需要顶级语句,Loader 会通过 MEF 加载 IIdentityInterface
4 changes: 2 additions & 2 deletions TestPlugin.CSharp/TestPlugin.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Library</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Preview</LangVersion>
Expand Down
40 changes: 35 additions & 5 deletions TestPlugin.WPF.Core/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
using KitX.Contract.CSharp;
using KitX.Shared.WebCommand;
using KitX.Shared.WebCommand.Details;
using System;
using System;
using System.Text;
using System.Text.Json;
using System.Windows;
using KitX.Contract.CSharp;
using KitX.Shared.CSharp.WebCommand;
using KitX.Shared.CSharp.WebCommand.Details;

namespace TestPlugin.WPF.Core;

public class Controller(MainWindow mainwin) : IController
{
private readonly MainWindow mainwin = mainwin;

private static readonly JsonSerializerOptions _serializerOptions = new()
{
WriteIndented = false,
IncludeFields = true,
PropertyNameCaseInsensitive = true,
};

public PluginWorkingDetail? WorkingDetail { get; set; }

public void End()
Expand All @@ -31,7 +40,28 @@ public void Execute(Command command)
{
if (command.FunctionName.Equals("HelloKitX"))
{
MessageBox.Show("Hello KitX !");
Functions.HelloKitX();
}
else if (command.FunctionName.Equals("HelloAnything"))
{
var name = command.FunctionArgs != null && command.FunctionArgs.Count > 0 ? command.FunctionArgs[0].Value : "Anything";
Functions.HelloAnything(name);
}
else if (command.FunctionName.Equals("GetInput"))
{
var inputText = mainwin.GetInputText();
var bodyBytes = Encoding.UTF8.GetBytes(inputText);
mainwin.sendCommandAction?.Invoke(new Request
{
Type = RequestTypes.Command,
Version = RequestVersions.V1,
Content = JsonSerializer.Serialize(new Command
{
Tags = command.Tags, // 保留 RequestId 用于响应匹配
Body = bodyBytes,
BodyLength = bodyBytes.Length
}, _serializerOptions)
});
}
}

Expand Down
Loading
Loading