Skip to content
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

[Pull Request] UI更新, 插件列表 #104

Merged
merged 14 commits into from
Aug 19, 2022
Merged
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
11 changes: 11 additions & 0 deletions KitX Dashboard/Data/ErrorCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace KitX_Dashboard.Data
{
internal static class ErrorCodes
{
internal const int StartUpArgumentsError = 1001;

internal const int ConfigFileDidntExists = 1002;


}
}
13 changes: 11 additions & 2 deletions KitX Dashboard/Data/GlobalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ internal static class GlobalInfo

internal const string AssetsPath = "./Assets/";

internal const string ThirdPartLicenseFilePath = $"{AssetsPath}/ThirdPartLicense.md";
internal const string KXPTempReleasePath = "Temp/";

internal const string ConfigFilePath = $"{ConfigPath}config.json";

internal const string PluginsDataBaseFilePath = $"{DataBasePath}plugins.db";

internal const string PluginsListConfigFilePath = $"{ConfigPath}plugins.json";

internal const string ThirdPartLicenseFilePath = $"{AssetsPath}ThirdPartLicense.md";

internal static int ServerPortNumber = 0;

Expand All @@ -24,8 +32,9 @@ internal static class GlobalInfo

internal const string Api_Get_Announcement = "get-announcement.php";

internal const string AnnouncementsJsonPath = "./Config/announcements.json";
internal const string AnnouncementsJsonPath = $"{ConfigPath}announcements.json";

internal static string MyMacAddress = string.Empty;
}
}

Expand Down
12 changes: 12 additions & 0 deletions KitX Dashboard/Data/PluginsList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using KitX_Dashboard.Models;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace KitX_Dashboard.Data
{
public class PluginsList
{
[JsonInclude]
public List<Plugin> Plugins = new();
}
}
2 changes: 1 addition & 1 deletion KitX Dashboard/KitX Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<PackageReference Include="Catrol.Algorithm.Interop" Version="1.1.6240.1190" />
<PackageReference Include="Catrol.BasicHelper" Version="1.1.6240.1190" />
<PackageReference Include="FluentAvaloniaUI" Version="1.4.1" />
<PackageReference Include="KitX.KXP.Helper" Version="22.4.6241.948" />
<PackageReference Include="KitX.KXP.Helper" Version="22.4.6242.183" />
<PackageReference Include="KitX.Web.Rules" Version="22.4.6241.948" />
<PackageReference Include="LiteDB" Version="5.0.12" />
<PackageReference Include="Markdown.Avalonia" Version="0.10.11" />
Expand Down
16 changes: 12 additions & 4 deletions KitX Dashboard/Models/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ internal static class EventHandlers

internal delegate void MicaOpacityChangedHandler();

internal delegate void PluginsListChangedHandler();

internal static event LanguageChangedHandler? LanguageChanged;

internal static event GreetingTextIntervalUpdatedHandler? GreetingTextIntervalUpdated;
Expand All @@ -21,6 +23,8 @@ internal static class EventHandlers

internal static event MicaOpacityChangedHandler? MicaOpacityChanged;

internal static event PluginsListChangedHandler? PluginsListChanged;


/// <summary>
/// 必要的初始化
Expand All @@ -31,6 +35,7 @@ internal static void Init()
GreetingTextIntervalUpdated += () => { };
ConfigSettingsChanged += () => { };
MicaOpacityChanged += () => { };
PluginsListChanged += () => { };
}

/// <summary>
Expand All @@ -41,18 +46,21 @@ internal static void Invoke(string eventName)
{
switch (eventName)
{
case "LanguageChanged":
case nameof(LanguageChanged):
LanguageChanged();
break;
case "GreetingTextIntervalUpdated":
case nameof(GreetingTextIntervalUpdated):
GreetingTextIntervalUpdated();
break;
case "ConfigSettingsChanged":
case nameof(ConfigSettingsChanged):
ConfigSettingsChanged();
break;
case "MicaOpacityChanged":
case nameof(MicaOpacityChanged):
MicaOpacityChanged();
break;
case nameof(PluginsListChanged):
PluginsListChanged();
break;
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions KitX Dashboard/Models/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
using KitX.Web.Rules;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace KitX_Dashboard.Models
{
internal class Plugin
public class Plugin
{
public Plugin()
{
[JsonInclude]
/// <summary>
/// 该插件的详细信息
/// </summary>
public PluginStruct PluginDetails { get; set; }

}
[JsonInclude]
/// <summary>
/// 需要的加载器的详细信息
/// </summary>
public LoaderStruct RequiredLoaderStruct { get; set; }

internal PluginStruct? PluginDetails { get; set; }

internal List<string>? MacAddressOfInstalledDevice { get; set; }

internal string? RequiredLoaderName { get; set; }

internal string? RequiredLoaderVersion { get; set; }
[JsonInclude]
/// <summary>
/// 已安装此插件的网络设备
/// </summary>
public List<string>? MacAddressOfInstalledDevice { get; set; }
}
}
6 changes: 6 additions & 0 deletions KitX Dashboard/Services/LoadersManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace KitX_Dashboard.Services
{
internal class LoadersManager
{
}
}
70 changes: 63 additions & 7 deletions KitX Dashboard/Services/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using KitX_Dashboard.Data;
using KitX_Dashboard.Models;
using KitX_Dashboard.Views.Pages.Controls;
using LiteDB;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -44,6 +43,10 @@ internal static void Execute(string msg, IPEndPoint endPoint)

internal static readonly Queue<PluginStruct> pluginsToAdd = new();

internal static readonly Queue<Plugin> pluginsToRemoveFromDB = new();

internal static readonly Queue<Plugin> pluginsToDelete = new();

/// <summary>
/// 持续检查并移除
/// </summary>
Expand Down Expand Up @@ -137,10 +140,6 @@ internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false)
if (workbase == null)
throw new Exception("Can not get path of \"KitX\"");
}
using LiteDatabase pgdb = new(Path.GetFullPath(
$"{GlobalInfo.DataBasePath}\\{GlobalInfo.PluginsDataBaseFile}"
));
var pgs = pgdb.GetCollection<Plugin>("Plugins");
string releaseDir = Path.GetFullPath($"{workbase}/{GlobalInfo.KXPTempReleasePath}");
foreach (var item in kxpfiles)
{
Expand Down Expand Up @@ -169,13 +168,13 @@ internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false)
string thisplugindir = $"{pluginsavedir}/" +
$"{pluginStruct.PublisherName}_{pluginStruct.AuthorName}/" +
$"{pluginStruct.Name}/" +
$"{pluginStruct.Version}";
$"{pluginStruct.Version}/";
if (Directory.Exists(thisplugindir))
Directory.Delete(thisplugindir, true);
_ = Directory.CreateDirectory(thisplugindir);
_ = decoder.Decode(thisplugindir);

pgs.Insert(new Plugin()
Program.PluginsList.Plugins.Add(new Plugin()
{
PluginDetails = pluginStruct,
RequiredLoaderStruct = loaderStruct,
Expand All @@ -188,6 +187,63 @@ internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false)
if (inGraphic) throw; // 如果是图形界面调用, 则再次抛出便于给出图形化提示
}
}
EventHandlers.Invoke("PluginsListChanged");
}

/// <summary>
/// 请求移除插件
/// </summary>
/// <param name="plugin">插件的安装信息</param>
internal static void RequireRemovePlugin(Plugin plugin) => pluginsToRemoveFromDB.Enqueue(plugin);

/// <summary>
/// 请求删除插件
/// </summary>
/// <param name="plugin">插件的安装信息</param>
internal static void RequireDeletePlugin(Plugin plugin) => pluginsToDelete.Enqueue(plugin);

/// <summary>
/// 持续检查移除和删除队列
/// </summary>
internal static void KeepCheckAndRemoveOrDelete()
{
System.Timers.Timer timer = new()
{
Interval = 2000,
AutoReset = true
};
timer.Elapsed += (_, _) =>
{
bool isPluginsListUpdated = false;

if (pluginsToRemoveFromDB.Count > 0)
{
isPluginsListUpdated = true;
while (pluginsToRemoveFromDB.Count > 0)
{
Program.PluginsList.Plugins.Remove(pluginsToRemoveFromDB.Dequeue());
}
}

if (pluginsToDelete.Count > 0)
{
isPluginsListUpdated = true;
while (pluginsToDelete.Count > 0)
{
Plugin pg = pluginsToDelete.Dequeue();
Program.PluginsList.Plugins.Remove(pg);
string pgfiledir = Path.GetFullPath(
$"{Program.GlobalConfig.App.LocalPluginsFileDirectory}/" +
$"{pg.PluginDetails.PublisherName}_{pg.PluginDetails.AuthorName}/" +
$"{pg.PluginDetails.Name}/{pg.PluginDetails.Version}/"
);
Directory.Delete(pgfiledir, true);
}
}

if (isPluginsListUpdated) EventHandlers.Invoke("PluginsListChanged");
};
timer.Start();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions KitX Dashboard/Services/WebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
#pragma warning disable CS8602 // 解引用可能出现空引用。
#pragma warning disable CS8604 // 引用类型参数可能为 null。
#pragma warning disable CS8601 // 引用类型赋值可能为 null。

namespace KitX_Dashboard.Services
{
Expand All @@ -29,6 +28,7 @@ public WebServer()
{
DevicesManager.KeepCheckAndRemove();
PluginsManager.KeepCheckAndRemove();
PluginsManager.KeepCheckAndRemoveOrDelete();
MultiDevicesBoradCastInit();
MultiDevicesBroadCastSend();
MultiDevicesBroadCastReceive();
Expand Down Expand Up @@ -301,7 +301,6 @@ public void Dispose()
}
}

#pragma warning restore CS8601 // 引用类型赋值可能为 null。
#pragma warning restore CS8604 // 引用类型参数可能为 null。
#pragma warning restore CS8602 // 解引用可能出现空引用。
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
Expand Down
Loading