From 332513620d0ebdbb2f5b19993594071f1e688708 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sat, 20 Jan 2024 02:38:37 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20Big=20renaming=20f?= =?UTF-8?q?or=20web=20rules.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KitX.Dashboard.Assets.csproj | 2 +- .../KitX.Dashboard.Core.csproj | 2 +- .../KitX.Dashboard.Fonts.csproj | 2 +- .../KitX.Dashboard.RepairTool.csproj | 2 +- .../KitX.Dashboard.Updater.csproj | 2 +- KitX Dashboard/App.axaml.cs | 15 ----- KitX Dashboard/Data/AppConfig.cs | 2 +- KitX Dashboard/Data/GlobalInfo.cs | 2 +- KitX Dashboard/KitX.Dashboard.csproj | 22 +++---- KitX Dashboard/Managers/PluginsManager.cs | 10 +-- KitX Dashboard/Models/Plugin.cs | 6 +- .../Network/DevicesDiscoveryServer.cs | 53 +++++++-------- KitX Dashboard/Network/DevicesNetwork.cs | 64 +++++++++---------- KitX Dashboard/Network/DevicesServer.cs | 4 +- KitX Dashboard/Network/NetworkHelper.cs | 47 ++++---------- KitX Dashboard/Network/PluginsNetwork.cs | 8 ++- KitX Dashboard/Services/EventService.cs | 12 ++-- .../Pages/Controls/DeviceCardViewModel.cs | 18 +++--- .../Pages/Controls/PluginBarViewModel.cs | 10 +-- .../Pages/Controls/PluginCardViewModel.cs | 6 +- .../Controls/Settings_PerformenceViewModel.cs | 2 +- .../Controls/Settings_UpdateViewModel.cs | 6 +- .../ViewModels/Pages/RepoPageViewModel.cs | 10 +-- .../ViewModels/PluginDetailWindowViewModel.cs | 21 +++--- .../Views/Pages/Controls/DeviceCard.axaml.cs | 4 +- .../Views/Pages/Controls/PluginCard.axaml.cs | 4 +- .../Views/PluginDetailWindow.axaml.cs | 4 +- 27 files changed, 153 insertions(+), 187 deletions(-) diff --git a/KitX Dashboard Assets/KitX.Dashboard.Assets.csproj b/KitX Dashboard Assets/KitX.Dashboard.Assets.csproj index 8f66ea34..ab33cbab 100644 --- a/KitX Dashboard Assets/KitX.Dashboard.Assets.csproj +++ b/KitX Dashboard Assets/KitX.Dashboard.Assets.csproj @@ -1,7 +1,7 @@  Library - net7.0 + net8.0 enable copyused true diff --git a/KitX Dashboard Core/KitX.Dashboard.Core.csproj b/KitX Dashboard Core/KitX.Dashboard.Core.csproj index d4398000..6f4623a8 100644 --- a/KitX Dashboard Core/KitX.Dashboard.Core.csproj +++ b/KitX Dashboard Core/KitX.Dashboard.Core.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable diff --git a/KitX Dashboard Fonts/KitX.Dashboard.Fonts.csproj b/KitX Dashboard Fonts/KitX.Dashboard.Fonts.csproj index da9f5006..7a826c12 100644 --- a/KitX Dashboard Fonts/KitX.Dashboard.Fonts.csproj +++ b/KitX Dashboard Fonts/KitX.Dashboard.Fonts.csproj @@ -1,7 +1,7 @@  Library - net7.0 + net8.0 enable copyused true diff --git a/KitX Dashboard Repair Tool/KitX.Dashboard.RepairTool.csproj b/KitX Dashboard Repair Tool/KitX.Dashboard.RepairTool.csproj index 53f71e75..bfca505b 100644 --- a/KitX Dashboard Repair Tool/KitX.Dashboard.RepairTool.csproj +++ b/KitX Dashboard Repair Tool/KitX.Dashboard.RepairTool.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable true diff --git a/KitX Dashboard Updater/KitX.Dashboard.Updater.csproj b/KitX Dashboard Updater/KitX.Dashboard.Updater.csproj index 73bc01b3..c2490c43 100644 --- a/KitX Dashboard Updater/KitX.Dashboard.Updater.csproj +++ b/KitX Dashboard Updater/KitX.Dashboard.Updater.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable diff --git a/KitX Dashboard/App.axaml.cs b/KitX Dashboard/App.axaml.cs index 81f0b183..b729238c 100644 --- a/KitX Dashboard/App.axaml.cs +++ b/KitX Dashboard/App.axaml.cs @@ -29,9 +29,6 @@ public partial class App : Application private AppViewModel? viewModel; - /// - /// Override `Initialize` function - /// public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -48,9 +45,6 @@ public override void Initialize() DataContext = viewModel; } - /// - /// Load Language - /// private void LoadLanguage() { var lang = ConfigManager.AppConfig.App.AppLanguage; @@ -105,9 +99,6 @@ private void LoadLanguage() } } - /// - /// Calculate theme color - /// private static void CalculateThemeColor() { Color c = Color.Parse(ConfigManager.AppConfig.App.ThemeColor); @@ -129,9 +120,6 @@ private static void CalculateThemeColor() } } - /// - /// Init `LiveCharts` - /// private static void InitLiveCharts() { { @@ -156,9 +144,6 @@ private static void InitLiveCharts() }; } - /// - /// Override `OnFrameworkInitializationCompleted` function - /// public override void OnFrameworkInitializationCompleted() { var location = $"{nameof(App)}.{nameof(OnFrameworkInitializationCompleted)}"; diff --git a/KitX Dashboard/Data/AppConfig.cs b/KitX Dashboard/Data/AppConfig.cs index a837c45f..64351dbc 100644 --- a/KitX Dashboard/Data/AppConfig.cs +++ b/KitX Dashboard/Data/AppConfig.cs @@ -312,7 +312,7 @@ public class Config_Web public int SocketBufferSize { get; set; } = 1024 * 100; [JsonInclude] - public int DeviceInfoStructTTLSeconds { get; set; } = 7; + public int DeviceInfoTTLSeconds { get; set; } = 7; [JsonInclude] public bool DisableRemovingOfflineDeviceCard { get; set; } = false; diff --git a/KitX Dashboard/Data/GlobalInfo.cs b/KitX Dashboard/Data/GlobalInfo.cs index ae14f985..76244945 100644 --- a/KitX Dashboard/Data/GlobalInfo.cs +++ b/KitX Dashboard/Data/GlobalInfo.cs @@ -51,7 +51,7 @@ internal static class GlobalInfo internal static bool SkipNetworkSystemOnStartup = false; - internal static int DeviceServerPort = -1; + internal static int DevicesServerPort = -1; internal static DateTime ServerBuildTime = new(); diff --git a/KitX Dashboard/KitX.Dashboard.csproj b/KitX Dashboard/KitX.Dashboard.csproj index 6ddeac51..ce783c44 100644 --- a/KitX Dashboard/KitX.Dashboard.csproj +++ b/KitX Dashboard/KitX.Dashboard.csproj @@ -1,7 +1,7 @@  WinExe - net7.0 + net8.0 enable true Assets\KitX-Icon-256x.ico @@ -66,14 +66,14 @@ - - - - - + + + + + - - + + @@ -84,11 +84,11 @@ - + - + - + diff --git a/KitX Dashboard/Managers/PluginsManager.cs b/KitX Dashboard/Managers/PluginsManager.cs index c04a544a..c378232f 100644 --- a/KitX Dashboard/Managers/PluginsManager.cs +++ b/KitX Dashboard/Managers/PluginsManager.cs @@ -2,8 +2,10 @@ using KitX.Dashboard.Data; using KitX.Dashboard.Models; using KitX.Dashboard.Services; -using KitX.Formats.KXP; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; +using KitX.Formats.KXP; using Serilog; using System; using System.Collections.Generic; @@ -33,10 +35,10 @@ internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false) { var decoder = new Decoder(item); - var rst = decoder.GetLoaderAndPluginStruct(); + var rst = decoder.GetLoaderAndPluginInfo(); - var loaderStruct = JsonSerializer.Deserialize(rst.Item1); - var pluginStruct = JsonSerializer.Deserialize(rst.Item2); + var loaderStruct = JsonSerializer.Deserialize(rst.Item1); + var pluginStruct = JsonSerializer.Deserialize(rst.Item2); var config = inGraphic ? ConfigManager.AppConfig : diff --git a/KitX Dashboard/Models/Plugin.cs b/KitX Dashboard/Models/Plugin.cs index 2a6c5b7c..c6e6ac90 100644 --- a/KitX Dashboard/Models/Plugin.cs +++ b/KitX Dashboard/Models/Plugin.cs @@ -1,4 +1,6 @@ using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -16,13 +18,13 @@ public class Plugin /// 该插件的详细信息 /// [JsonIgnore] - public PluginStruct PluginDetails { get; set; } + public PluginInfo PluginDetails { get; set; } /// /// 需要的加载器的详细信息 /// [JsonIgnore] - public LoaderStruct RequiredLoaderStruct { get; set; } + public LoaderInfo RequiredLoaderInfo { get; set; } /// /// 已安装此插件的网络设备 diff --git a/KitX Dashboard/Network/DevicesDiscoveryServer.cs b/KitX Dashboard/Network/DevicesDiscoveryServer.cs index ec34df4f..7ac86cbb 100644 --- a/KitX Dashboard/Network/DevicesDiscoveryServer.cs +++ b/KitX Dashboard/Network/DevicesDiscoveryServer.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Names; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Serilog; using System; using System.Collections.Generic; @@ -28,7 +30,7 @@ internal class DevicesDiscoveryServer : IKitXServer private static System.Timers.Timer? UdpSendTimer = null; - private static int DeviceInfoStructUpdatedTimes = 0; + private static int DeviceInfoUpdatedTimes = 0; private static int LastTimeToOSVersionUpdated = 0; @@ -42,7 +44,7 @@ internal class DevicesDiscoveryServer : IKitXServer internal static readonly Queue Messages2BroadCast = new(); - internal static DeviceInfoStruct DefaultDeviceInfoStruct = NetworkHelper.GetDeviceInfo(); + internal static DeviceInfo DefaultDeviceInfo = NetworkHelper.GetDeviceInfo(); private static ServerStatus status = ServerStatus.Pending; @@ -55,9 +57,6 @@ internal static ServerStatus Status } } - /// - /// 寻找受支持的网络适配器并把 UDP 客户端加入组播 - /// private static void FindSupportNetworkInterfaces(List clients, IPAddress multicastAddress) { var multicastGroupJoinedInterfacesCount = 0; @@ -117,36 +116,30 @@ private static void FindSupportNetworkInterfaces(List clients, IPAddr $"Joined {multicastGroupJoinedInterfacesCount} multicast groups."); } - /// - /// 更新默认设备信息结构 - /// - private static void UpdateDefaultDeviceInfoStruct() + private static void UpdateDefaultDeviceInfo() { - DefaultDeviceInfoStruct.IsMainDevice = GlobalInfo.IsMainMachine; - DefaultDeviceInfoStruct.SendTime = DateTime.UtcNow; - DefaultDeviceInfoStruct.IPv4 = NetworkHelper.GetInterNetworkIPv4(); - DefaultDeviceInfoStruct.IPv6 = NetworkHelper.GetInterNetworkIPv6(); - DefaultDeviceInfoStruct.PluginServerPort = GlobalInfo.PluginServerPort; - DefaultDeviceInfoStruct.PluginsCount = Instances.PluginCards.Count; - DefaultDeviceInfoStruct.IsMainDevice = GlobalInfo.IsMainMachine; - DefaultDeviceInfoStruct.DeviceServerPort = GlobalInfo.DeviceServerPort; - DefaultDeviceInfoStruct.DeviceServerBuildTime = GlobalInfo.ServerBuildTime; + DefaultDeviceInfo.IsMainDevice = GlobalInfo.IsMainMachine; + DefaultDeviceInfo.SendTime = DateTime.UtcNow; + DefaultDeviceInfo.Device.IPv4 = NetworkHelper.GetInterNetworkIPv4(); + DefaultDeviceInfo.Device.IPv6 = NetworkHelper.GetInterNetworkIPv6(); + DefaultDeviceInfo.PluginServerPort = GlobalInfo.PluginServerPort; + DefaultDeviceInfo.PluginsCount = Instances.PluginCards.Count; + DefaultDeviceInfo.IsMainDevice = GlobalInfo.IsMainMachine; + DefaultDeviceInfo.DevicesServerPort = GlobalInfo.DevicesServerPort; + DefaultDeviceInfo.DeviceServerBuildTime = GlobalInfo.ServerBuildTime; if (LastTimeToOSVersionUpdated > ConfigManager.AppConfig.IO.OperatingSystemVersionUpdateInterval) { LastTimeToOSVersionUpdated = 0; - DefaultDeviceInfoStruct.DeviceOSVersion = NetworkHelper.TryGetOSVersionString(); + DefaultDeviceInfo.DeviceOSVersion = NetworkHelper.TryGetOSVersionString(); } - ++DeviceInfoStructUpdatedTimes; + ++DeviceInfoUpdatedTimes; ++LastTimeToOSVersionUpdated; - if (DeviceInfoStructUpdatedTimes < 0) DeviceInfoStructUpdatedTimes = 0; + if (DeviceInfoUpdatedTimes < 0) DeviceInfoUpdatedTimes = 0; } - /// - /// 多设备广播发送方法 - /// private void MultiDevicesBroadCastSend() { var location = $"{nameof(DevicesDiscoveryServer)}.{nameof(MultiDevicesBroadCastSend)}"; @@ -181,12 +174,12 @@ private void MultiDevicesBroadCastSend() erroredInterfacesIndexes.Clear(); } - UpdateDefaultDeviceInfoStruct(); + UpdateDefaultDeviceInfo(); if (closingRequest) - DefaultDeviceInfoStruct.SendTime -= TimeSpan.FromSeconds(20); + DefaultDeviceInfo.SendTime -= TimeSpan.FromSeconds(20); - var sendText = JsonSerializer.Serialize(DefaultDeviceInfoStruct); + var sendText = JsonSerializer.Serialize(DefaultDeviceInfo); var sendBytes = sendText.FromUTF8(); foreach (var item in SupportedNetworkInterfacesIndexes) @@ -274,7 +267,7 @@ private void MultiDevicesBroadCastReceive() try { DevicesNetwork.Update( - JsonSerializer.Deserialize(result) + JsonSerializer.Deserialize(result) ); } catch (Exception ex) @@ -299,7 +292,7 @@ private static void Init() { disposed = false; - DeviceInfoStructUpdatedTimes = 0; + DeviceInfoUpdatedTimes = 0; LastTimeToOSVersionUpdated = 0; @@ -309,7 +302,7 @@ private static void Init() Messages2BroadCast.Clear(); - DefaultDeviceInfoStruct = NetworkHelper.GetDeviceInfo(); + DefaultDeviceInfo = NetworkHelper.GetDeviceInfo(); } public async Task Start() diff --git a/KitX Dashboard/Network/DevicesNetwork.cs b/KitX Dashboard/Network/DevicesNetwork.cs index 1eff5df0..bb6d8209 100644 --- a/KitX Dashboard/Network/DevicesNetwork.cs +++ b/KitX Dashboard/Network/DevicesNetwork.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Services; using KitX.Dashboard.Views.Pages.Controls; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Serilog; using System; using System.Collections.Generic; @@ -18,11 +20,11 @@ internal class DevicesNetwork internal static DevicesClient? devicesClient = null; - private static readonly object _receivedDeviceInfoStruct4WatchLock = new(); + private static readonly object _receivedDeviceInfo4WatchLock = new(); - internal static List? receivedDeviceInfoStruct4Watch; + internal static List? receivedDeviceInfo4Watch; - internal static readonly Queue deviceInfoStructs = new(); + internal static readonly Queue deviceInfoStructs = new(); private static readonly object AddDeviceCard2ViewLock = new(); @@ -30,7 +32,7 @@ internal class DevicesNetwork private static void InitEvents() { - EventService.OnReceivingDeviceInfoStruct += dis => + EventService.OnReceivingDeviceInfo += dis => { if (dis.IsMainDevice && dis.DeviceServerBuildTime < GlobalInfo.ServerBuildTime) { @@ -39,7 +41,7 @@ private static void InitEvents() Watch4MainDevice(); Log.Information($"In DevicesService: Watched earlier built server. " + - $"DeviceServerAddress: {dis.IPv4}:{dis.DeviceServerPort} " + + $"DeviceServerAddress: {dis.Device.IPv4}:{dis.DevicesServerPort} " + $"DeviceServerBuildTime: {dis.DeviceServerBuildTime}"); } }; @@ -50,29 +52,21 @@ private static void InitEvents() /// /// 设备广播信息 /// 是否离线 - private static bool CheckDeviceIsOffline(DeviceInfoStruct info) + private static bool CheckDeviceIsOffline(DeviceInfo info) => DateTime.UtcNow - info.SendTime.ToUniversalTime() > new TimeSpan( 0, 0, - ConfigManager.AppConfig.Web.DeviceInfoStructTTLSeconds + ConfigManager.AppConfig.Web.DeviceInfoTTLSeconds ); - /// - /// 判断是否是本机卡片 - /// - /// 设备信息 - /// 是否是本机卡片 - private static bool CheckIsCurrentMachine(DeviceInfoStruct info) + private static bool CheckIsCurrentMachine(DeviceInfo info) { - var self = DevicesDiscoveryServer.DefaultDeviceInfoStruct; + var self = DevicesDiscoveryServer.DefaultDeviceInfo; - return info.DeviceMacAddress.Equals(self.DeviceMacAddress) - && info.DeviceName.Equals(self.DeviceName); + return info.Device.MacAddress.Equals(self.Device.MacAddress) + && info.Device.DeviceName.Equals(self.Device.DeviceName); } - /// - /// 更新数据源中的设备信息并添加数据源中没有的设备卡片 - /// private static void UpdateSourceAndAddCards() { var needToAddDevicesCount = 0; @@ -91,7 +85,7 @@ private static void UpdateSourceAndAddCards() foreach (var item in Instances.DeviceCards) { - if (item.viewModel.DeviceInfo.DeviceName.Equals(deviceInfoStruct.DeviceName)) + if (item.viewModel.DeviceInfo.Device.DeviceName.Equals(deviceInfoStruct.Device.DeviceName)) { item.viewModel.DeviceInfo = deviceInfoStruct; findThis = true; @@ -241,19 +235,19 @@ private static void KeepCheckAndRemove() /// 更新收到的UDP包 /// /// 设备信息结构 - internal static void Update(DeviceInfoStruct deviceInfo) + internal static void Update(DeviceInfo deviceInfo) { deviceInfoStructs.Enqueue(deviceInfo); - if (receivedDeviceInfoStruct4Watch is not null) + if (receivedDeviceInfo4Watch is not null) { - lock (_receivedDeviceInfoStruct4WatchLock) + lock (_receivedDeviceInfo4WatchLock) { - receivedDeviceInfoStruct4Watch.Add(deviceInfo); + receivedDeviceInfo4Watch.Add(deviceInfo); } } - EventService.Invoke(nameof(EventService.OnReceivingDeviceInfoStruct), deviceInfo); + EventService.Invoke(nameof(EventService.OnReceivingDeviceInfo), deviceInfo); } /// @@ -265,7 +259,7 @@ internal static void Watch4MainDevice() new Thread(() => { - receivedDeviceInfoStruct4Watch = new(); + receivedDeviceInfo4Watch = new(); var checkedTime = 0; var hadMainDevice = false; @@ -277,18 +271,18 @@ internal static void Watch4MainDevice() { try { - if (receivedDeviceInfoStruct4Watch is null) continue; + if (receivedDeviceInfo4Watch is null) continue; - lock (_receivedDeviceInfoStruct4WatchLock) + lock (_receivedDeviceInfo4WatchLock) { - foreach (var item in receivedDeviceInfoStruct4Watch) + foreach (var item in receivedDeviceInfo4Watch) { if (item.IsMainDevice) { if (item.DeviceServerBuildTime.ToUniversalTime() < earliestBuiltServerTime) { - serverPort = item.DeviceServerPort; - serverAddress = item.IPv4; + serverPort = item.DevicesServerPort; + serverAddress = item.Device.IPv4; } hadMainDevice = true; } @@ -301,8 +295,8 @@ internal static void Watch4MainDevice() if (checkedTime == 7) { - receivedDeviceInfoStruct4Watch?.Clear(); - receivedDeviceInfoStruct4Watch = null; + receivedDeviceInfo4Watch?.Clear(); + receivedDeviceInfo4Watch = null; WatchingOver(hadMainDevice, serverAddress, serverPort); } @@ -311,8 +305,8 @@ internal static void Watch4MainDevice() } catch (Exception e) { - receivedDeviceInfoStruct4Watch?.Clear(); - receivedDeviceInfoStruct4Watch = null; + receivedDeviceInfo4Watch?.Clear(); + receivedDeviceInfo4Watch = null; Log.Error(e, $"In {location}: {e.Message} Rewatch."); diff --git a/KitX Dashboard/Network/DevicesServer.cs b/KitX Dashboard/Network/DevicesServer.cs index a8e30f3b..03ea8cc0 100644 --- a/KitX Dashboard/Network/DevicesServer.cs +++ b/KitX Dashboard/Network/DevicesServer.cs @@ -205,7 +205,7 @@ await TasksManager.RunTaskAsync(() => var port = ((IPEndPoint)listener.LocalEndpoint).Port; // 取服务端口号 - GlobalInfo.DeviceServerPort = port; // 全局端口号标明 + GlobalInfo.DevicesServerPort = port; // 全局端口号标明 GlobalInfo.ServerBuildTime = DateTime.UtcNow; GlobalInfo.IsMainMachine = true; @@ -245,7 +245,7 @@ await TasksManager.RunTaskAsync(() => clients.Clear(); GlobalInfo.IsMainMachine = false; - GlobalInfo.DeviceServerPort = -1; + GlobalInfo.DevicesServerPort = -1; EventService.Invoke(nameof(EventService.DevicesServerPortChanged)); diff --git a/KitX Dashboard/Network/NetworkHelper.cs b/KitX Dashboard/Network/NetworkHelper.cs index 968d3bad..45e854d2 100644 --- a/KitX Dashboard/Network/NetworkHelper.cs +++ b/KitX Dashboard/Network/NetworkHelper.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Data; using KitX.Dashboard.Managers; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Serilog; using System; using System.IO; @@ -16,11 +18,6 @@ namespace KitX.Dashboard.Network; internal static class NetworkHelper { - /// - /// 检查网络适配器是否符合要求 - /// - /// 网络适配器 - /// 是否符合要求 internal static bool CheckNetworkInterface ( NetworkInterface adapter, @@ -50,11 +47,6 @@ IPInterfaceProperties adapterProperties return true; } - /// - /// 判断 IPv4 地址是否为内部网络地址 - /// - /// 网络地址 - /// 是否为内部网络地址 internal static bool IsInterNetworkAddressV4(IPAddress address) { var bytes = address.GetAddressBytes(); @@ -68,10 +60,6 @@ internal static bool IsInterNetworkAddressV4(IPAddress address) }; } - /// - /// 获取本机内网 IPv4 地址 - /// - /// 使用点分十进制表示法的本机内网IPv4地址 internal static string GetInterNetworkIPv4() { var location = $"{nameof(NetworkHelper)}.{nameof(GetInterNetworkIPv4)}"; @@ -100,10 +88,6 @@ from ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList } } - /// - /// 获取本机内网 IPv6 地址 - /// - /// IPv6 地址 internal static string GetInterNetworkIPv6() { var location = $"{nameof(NetworkHelper)}.{nameof(GetInterNetworkIPv6)}"; @@ -130,10 +114,6 @@ from ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList } } - /// - /// 尝试获取设备 MAC 地址 - /// - /// MAC 地址 internal static string? TryGetDeviceMacAddress() { var location = $"{nameof(NetworkHelper)}.{nameof(TryGetDeviceMacAddress)}"; @@ -160,10 +140,6 @@ from nic in NetworkInterface.GetAllNetworkInterfaces() } } - /// - /// 尝试获取系统版本 - /// - /// 系统版本 internal static string? TryGetOSVersionString() { var location = $"{nameof(NetworkHelper)}.{nameof(TryGetOSVersionString)}"; @@ -232,22 +208,21 @@ from nic in NetworkInterface.GetAllNetworkInterfaces() return result; } - /// - /// 获取设备信息 - /// - /// 设备信息结构体 - internal static DeviceInfoStruct GetDeviceInfo() => new() + internal static DeviceInfo GetDeviceInfo() => new() { - DeviceName = Environment.MachineName, - DeviceMacAddress = TryGetDeviceMacAddress(), + Device = new() + { + DeviceName = Environment.MachineName, + MacAddress = TryGetDeviceMacAddress(), + IPv4 = GetInterNetworkIPv4(), + IPv6 = GetInterNetworkIPv6(), + }, IsMainDevice = GlobalInfo.IsMainMachine, SendTime = DateTime.UtcNow, DeviceOSType = OperatingSystem2Enum.GetOSType(), DeviceOSVersion = TryGetOSVersionString(), - IPv4 = GetInterNetworkIPv4(), - IPv6 = GetInterNetworkIPv6(), PluginServerPort = GlobalInfo.PluginServerPort, - DeviceServerPort = GlobalInfo.DeviceServerPort, + DevicesServerPort = GlobalInfo.DevicesServerPort, DeviceServerBuildTime = new(), PluginsCount = Instances.PluginCards.Count, }; diff --git a/KitX Dashboard/Network/PluginsNetwork.cs b/KitX Dashboard/Network/PluginsNetwork.cs index ec6d058a..72bc4423 100644 --- a/KitX Dashboard/Network/PluginsNetwork.cs +++ b/KitX Dashboard/Network/PluginsNetwork.cs @@ -5,6 +5,8 @@ using KitX.Dashboard.Services; using KitX.Dashboard.Views.Pages.Controls; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Serilog; using System; using System.Collections.Generic; @@ -27,11 +29,11 @@ internal static void Execute(string msg, IPEndPoint endPoint) try { - if (msg.StartsWith("PluginStruct: ")) + if (msg.StartsWith("PluginInfo: ")) { var json = msg[14..]; - var pluginStruct = JsonSerializer.Deserialize(json); + var pluginStruct = JsonSerializer.Deserialize(json); pluginStruct.Tags ??= new(); @@ -64,7 +66,7 @@ internal static void Execute(string msg, IPEndPoint endPoint) internal static readonly Queue pluginsToRemove = new(); - internal static readonly Queue pluginsToAdd = new(); + internal static readonly Queue pluginsToAdd = new(); internal static readonly Queue pluginsToRemoveFromDB = new(); diff --git a/KitX Dashboard/Services/EventService.cs b/KitX Dashboard/Services/EventService.cs index c867f771..c133b822 100644 --- a/KitX Dashboard/Services/EventService.cs +++ b/KitX Dashboard/Services/EventService.cs @@ -1,4 +1,6 @@ using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; namespace KitX.Dashboard.Services; @@ -29,7 +31,7 @@ internal static class EventService internal delegate void DevicesServerPortChangedHandler(); - internal delegate void OnReceivingDeviceInfoStructHandler(DeviceInfoStruct dis); + internal delegate void OnReceivingDeviceInfoHandler(DeviceInfo dis); internal delegate void OnConfigHotReloadedHandler(); @@ -59,7 +61,7 @@ internal static class EventService internal static event DevicesServerPortChangedHandler? DevicesServerPortChanged; - internal static event OnReceivingDeviceInfoStructHandler? OnReceivingDeviceInfoStruct; + internal static event OnReceivingDeviceInfoHandler? OnReceivingDeviceInfo; internal static event OnConfigHotReloadedHandler? OnConfigHotReloaded; @@ -80,7 +82,7 @@ internal static void Init() UseStatisticsChanged += () => { }; OnExiting += () => { }; DevicesServerPortChanged += () => { }; - OnReceivingDeviceInfoStruct += dis => { }; + OnReceivingDeviceInfo += dis => { }; OnConfigHotReloaded += () => { }; PluginsServerPortChanged += () => { }; } @@ -144,8 +146,8 @@ internal static void Invoke(string eventName, object arg) { switch (eventName) { - case nameof(OnReceivingDeviceInfoStruct): - OnReceivingDeviceInfoStruct?.Invoke((DeviceInfoStruct)arg); + case nameof(OnReceivingDeviceInfo): + OnReceivingDeviceInfo?.Invoke((DeviceInfo)arg); break; } } diff --git a/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs index 23430906..34fe1ba1 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs @@ -1,6 +1,8 @@ using Avalonia; using Common.BasicHelper.Utils.Extensions; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Material.Icons; using System.ComponentModel; @@ -15,20 +17,20 @@ public DeviceCardViewModel() } - private DeviceInfoStruct deviceInfo = new(); + private DeviceInfo deviceInfo = new(); - internal DeviceInfoStruct DeviceInfo + internal DeviceInfo DeviceInfo { get => deviceInfo; set { deviceInfo = value; - DeviceName = DeviceInfo.DeviceName; - DeviceMacAddress = DeviceInfo.DeviceMacAddress.IsNullOrWhiteSpace() + DeviceName = DeviceInfo.Device.DeviceName; + DeviceMacAddress = DeviceInfo.Device.MacAddress.IsNullOrWhiteSpace() ? FetchStringFromResource(Application.Current, "Text_Device_NoMacAddress") : - DeviceInfo.DeviceMacAddress + DeviceInfo.Device.MacAddress ; LastOnlineTime = DeviceInfo.SendTime.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss"); DeviceVersion = DeviceInfo.DeviceOSVersion; @@ -48,8 +50,8 @@ internal DeviceInfoStruct DeviceInfo OperatingSystems.IoT => MaterialIconKind.Chip, _ => MaterialIconKind.QuestionMarkCircle, }; - IPv4 = $"{DeviceInfo.IPv4}:{DeviceInfo.PluginServerPort}"; - IPv6 = DeviceInfo.IPv6; + IPv4 = $"{DeviceInfo.Device.IPv4}:{DeviceInfo.PluginServerPort}"; + IPv6 = DeviceInfo.Device.IPv6; PluginsCount = DeviceInfo.PluginsCount.ToString(); DeviceControlStatus = DeviceInfo.IsMainDevice ? FetchStringFromResource(Application.Current, "Text_Device_Type_Master") @@ -119,7 +121,7 @@ internal DeviceInfoStruct DeviceInfo internal string? DeviceServerAddress { get => deviceInfo.IsMainDevice - ? $"{deviceInfo.IPv4}:{deviceInfo.DeviceServerPort}" + ? $"{deviceInfo.Device.IPv4}:{deviceInfo.DevicesServerPort}" : null; } } diff --git a/KitX Dashboard/ViewModels/Pages/Controls/PluginBarViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/PluginBarViewModel.cs index 51c7ff27..99f729ee 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/PluginBarViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/PluginBarViewModel.cs @@ -39,7 +39,7 @@ internal void InitCommands() { WindowStartupLocation = WindowStartupLocation.CenterOwner } - .SetPluginStruct(PluginDetail.PluginDetails) + .SetPluginInfo(PluginDetail.PluginDetails) .Show(Instances.MainWindow); }); @@ -70,20 +70,20 @@ internal void InitCommands() { try { - var loaderName = PluginDetail?.RequiredLoaderStruct.LoaderName; - var loaderVersion = PluginDetail?.RequiredLoaderStruct.LoaderVersion; + var loaderName = PluginDetail?.RequiredLoaderInfo.LoaderName; + var loaderVersion = PluginDetail?.RequiredLoaderInfo.LoaderVersion; var pd = PluginDetail?.PluginDetails; var pluginPath = $"{PluginDetail?.InstallPath}/{pd?.RootStartupFileName}"; var pluginFile = pluginPath.GetFullPath(); var connectStr = "" + - $"{DevicesDiscoveryServer.DefaultDeviceInfoStruct.IPv4}" + + $"{DevicesDiscoveryServer.DefaultDeviceInfo.Device.IPv4}" + $":" + $"{GlobalInfo.PluginServerPort}"; if (PluginDetail is null) return; - if (PluginDetail.RequiredLoaderStruct.SelfLoad) + if (PluginDetail.RequiredLoaderInfo.SelfLoad) Process.Start(pluginFile, $"--connect {connectStr}"); else { diff --git a/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs index 59497939..cf42eb48 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Views; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using ReactiveUI; using Serilog; using System; @@ -14,7 +16,7 @@ namespace KitX.Dashboard.ViewModels.Pages.Controls; internal class PluginCardViewModel { - internal PluginStruct pluginStruct = new(); + internal PluginInfo pluginStruct = new(); public PluginCardViewModel() { @@ -32,7 +34,7 @@ private void InitCommands() { WindowStartupLocation = WindowStartupLocation.CenterOwner } - .SetPluginStruct(pluginStruct) + .SetPluginInfo(pluginStruct) .Show(Instances.MainWindow); }); } diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs index aec470b2..08873d48 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs @@ -211,7 +211,7 @@ internal static int PluginsServerPort } } - internal static int DevicesServerPort => GlobalInfo.DeviceServerPort; + internal static int DevicesServerPort => GlobalInfo.DevicesServerPort; internal static string LocalIPFilter { diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs index 44bbd5a1..d18e5913 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs @@ -9,6 +9,8 @@ using KitX.Dashboard.Network; using KitX.Dashboard.Services; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using MsBox.Avalonia; using MsBox.Avalonia.Enums; using ReactiveUI; @@ -234,7 +236,7 @@ HttpClient client ConfigManager.AppConfig.Web.UpdateServer + ConfigManager.AppConfig.Web.UpdatePath.Replace( "%platform%", - DevicesDiscoveryServer.DefaultDeviceInfoStruct.DeviceOSType switch + DevicesDiscoveryServer.DefaultDeviceInfo.DeviceOSType switch { OperatingSystems.Windows => "win", OperatingSystems.Linux => "linux", @@ -439,7 +441,7 @@ ref HttpClient client ConfigManager.AppConfig.Web.UpdateServer + ConfigManager.AppConfig.Web.UpdateDownloadPath.Replace( "%platform%", - DevicesDiscoveryServer.DefaultDeviceInfoStruct.DeviceOSType switch + DevicesDiscoveryServer.DefaultDeviceInfo.DeviceOSType switch { OperatingSystems.Windows => "win", OperatingSystems.Linux => "linux", diff --git a/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs b/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs index 2b8fc739..4a69a14b 100644 --- a/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Services; using KitX.Dashboard.Views.Pages.Controls; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using ReactiveUI; using Serilog; using System; @@ -83,14 +85,14 @@ private void InitCommands() var plugin = new Plugin() { InstallPath = item.InstallPath, - PluginDetails = JsonSerializer.Deserialize( + PluginDetails = JsonSerializer.Deserialize( File.ReadAllText( - Path.GetFullPath($"{item.InstallPath}/PluginStruct.json") + Path.GetFullPath($"{item.InstallPath}/PluginInfo.json") ) ), - RequiredLoaderStruct = JsonSerializer.Deserialize( + RequiredLoaderInfo = JsonSerializer.Deserialize( File.ReadAllText( - Path.GetFullPath($"{item.InstallPath}/LoaderStruct.json") + Path.GetFullPath($"{item.InstallPath}/LoaderInfo.json") ) ), InstalledDevices = new() diff --git a/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs b/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs index 3d7b8c6f..ec8c4dae 100644 --- a/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs @@ -6,6 +6,8 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Services; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using ReactiveUI; using Serilog; using System; @@ -44,7 +46,7 @@ internal void InitEvents() ); } - internal PluginStruct? PluginDetail { get; set; } + internal PluginInfo? PluginDetail { get; set; } internal string? DisplayName { @@ -196,27 +198,22 @@ internal void InitFunctionsAndTags() sb.Append('('); - if (func.Parameters.Count != func.ParametersType.Count) - throw new InvalidDataException( - "Parameters return type count didn't match parameters count." - ); - var index = 0; foreach (var param in func.Parameters) { - sb.Append(func.ParametersType[index]); - - ++index; + sb.Append(param.Type); sb.Append(' '); - if (param.Value.TryGetValue(langKey, out var paramName)) + if (param.DisplayNames.TryGetValue(langKey, out var paramName)) sb.Append(paramName); - else sb.Append(param.Key); + else sb.Append(param.Name); - if (index != func.Parameters.Count) + if (index != func.Parameters.Count - 1) sb.Append(", "); + + ++index; } sb.Append(')'); diff --git a/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs b/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs index 8586894a..8dcfabfc 100644 --- a/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs +++ b/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs @@ -1,6 +1,8 @@ using Avalonia.Controls; using KitX.Dashboard.ViewModels.Pages.Controls; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; namespace KitX.Dashboard.Views.Pages.Controls; @@ -15,7 +17,7 @@ public DeviceCard() DataContext = viewModel; } - public DeviceCard(DeviceInfoStruct deviceInfo) + public DeviceCard(DeviceInfo deviceInfo) { InitializeComponent(); diff --git a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs b/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs index db4143c1..a90250c0 100644 --- a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs +++ b/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs @@ -1,6 +1,8 @@ using Avalonia.Controls; using KitX.Dashboard.ViewModels.Pages.Controls; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; namespace KitX.Dashboard.Views.Pages.Controls; @@ -17,7 +19,7 @@ public PluginCard() DataContext = viewModel; } - public PluginCard(PluginStruct ps) + public PluginCard(PluginInfo ps) { InitializeComponent(); diff --git a/KitX Dashboard/Views/PluginDetailWindow.axaml.cs b/KitX Dashboard/Views/PluginDetailWindow.axaml.cs index 3bd4886e..dccfdb09 100644 --- a/KitX Dashboard/Views/PluginDetailWindow.axaml.cs +++ b/KitX Dashboard/Views/PluginDetailWindow.axaml.cs @@ -4,6 +4,8 @@ using KitX.Dashboard.Services; using KitX.Dashboard.ViewModels; using KitX.Web.Rules; +using KitX.Web.Rules.Plugin; +using KitX.Web.Rules.Device; using Serilog; using System; @@ -60,7 +62,7 @@ public PluginDetailWindow() EventService.OnExiting += Close; } - public PluginDetailWindow SetPluginStruct(PluginStruct ps) + public PluginDetailWindow SetPluginInfo(PluginInfo ps) { viewModel.PluginDetail = ps; From 8eda5b8a18a2189d31df68552600ef7473b5acfd Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sat, 20 Jan 2024 02:51:08 +0800 Subject: [PATCH 02/27] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20Big=20renaming=20f?= =?UTF-8?q?or=20web=20rules.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/WindowAttributesConverter.cs | 12 +-- KitX Dashboard/Data/AppConfig.cs | 102 +++++++++--------- KitX Dashboard/Data/MarketConfig.cs | 6 +- KitX Dashboard/Helper.cs | 42 +++----- KitX Dashboard/Managers/ActivityManager.cs | 18 ++-- KitX Dashboard/Managers/AnouncementManager.cs | 8 +- KitX Dashboard/Managers/CacheManager.cs | 54 +++++----- KitX Dashboard/Managers/FileWatcherManager.cs | 64 +++++------ KitX Dashboard/Managers/TasksManager.cs | 24 ++--- KitX Dashboard/Managers/WebManager.cs | 48 ++++----- KitX Dashboard/Models/Plugin.cs | 24 ++--- .../Network/DevicesDiscoveryServer.cs | 22 ++-- KitX Dashboard/Network/DevicesNetwork.cs | 48 ++++----- KitX Dashboard/Network/DevicesServer.cs | 14 +-- KitX Dashboard/Network/NetworkStatus.cs | 78 +++++++------- KitX Dashboard/Network/PluginsNetwork.cs | 44 ++++---- KitX Dashboard/Network/PluginsServer.cs | 14 +-- KitX Dashboard/Program.cs | 24 ++--- KitX Dashboard/Services/DebugService.cs | 62 +++++------ KitX Dashboard/Services/EventService.cs | 24 ++--- .../Pages/Controls/Home_RecentUseViewModel.cs | 6 +- .../ViewModels/Pages/LibPageViewModel.cs | 12 +-- KitX Dashboard/Views/MainWindow.axaml.cs | 102 +++++++++--------- KitX Dashboard/Views/Pages/HomePage.axaml.cs | 22 ++-- .../Views/Pages/SettingsPage.axaml.cs | 22 ++-- 25 files changed, 440 insertions(+), 456 deletions(-) diff --git a/KitX Dashboard/Converters/WindowAttributesConverter.cs b/KitX Dashboard/Converters/WindowAttributesConverter.cs index 441c4ae5..e9ada86a 100644 --- a/KitX Dashboard/Converters/WindowAttributesConverter.cs +++ b/KitX Dashboard/Converters/WindowAttributesConverter.cs @@ -5,12 +5,12 @@ namespace KitX.Dashboard.Converters; internal class WindowAttributesConverter { - /// - /// 坐标回正 - /// - /// 传入的坐标 - /// 是否是距左距离 - /// 回正的坐标 + + + + + + internal static int PositionCameCenter(int input, bool isLeft, Screens screens, Resolution win) { if (win.Width is null || win.Height is null) return 0; diff --git a/KitX Dashboard/Data/AppConfig.cs b/KitX Dashboard/Data/AppConfig.cs index 64351dbc..cb2a50a4 100644 --- a/KitX Dashboard/Data/AppConfig.cs +++ b/KitX Dashboard/Data/AppConfig.cs @@ -6,9 +6,9 @@ namespace KitX.Dashboard.Data; -/// -/// 配置结构 -/// + + + public class AppConfig { [JsonInclude] @@ -35,9 +35,9 @@ public class AppConfig [JsonInclude] public Config_Loaders Loaders { get; set; } = new(); - /// - /// AppConfig - /// + + + public class Config_App { [JsonInclude] @@ -83,9 +83,9 @@ public class Config_App public ulong RanTime { get; set; } = 0; } - /// - /// WindowsConfig - /// + + + public class Config_Windows { @@ -95,9 +95,9 @@ public class Config_Windows [JsonInclude] public Config_AnnouncementWindow AnnouncementWindow { get; set; } = new(); - /// - /// MainWindowConfig - /// + + + public class Config_MainWindow { [JsonInclude] @@ -149,9 +149,9 @@ public class Config_MainWindow public int GreetingUpdateInterval { get; set; } = 10; } - /// - /// AnnouncementWindowConfig - /// + + + public class Config_AnnouncementWindow { [JsonInclude] @@ -168,9 +168,9 @@ public class Config_AnnouncementWindow } } - /// - /// ViewsConfig - /// + + + public class Config_Pages { [JsonInclude] @@ -185,9 +185,9 @@ public class Config_Pages [JsonInclude] public Config_SettingsPage Settings { get; set; } = new(); - /// - /// HomePageConfig - /// + + + public class Config_HomePage { [JsonInclude] @@ -204,25 +204,25 @@ public class Config_HomePage public bool UseAreaExpanded { get; set; } = true; } - /// - /// DevicePageConfig - /// + + + public class Config_DevicePage { } - /// - /// MargetPageConfig - /// + + + public class Config_MarketPage { } - /// - /// SettingsPageConfig - /// + + + public class Config_SettingsPage { [JsonInclude] @@ -270,9 +270,9 @@ public class Config_SettingsPage } } - /// - /// WebConfig - /// + + + public class Config_Web { [JsonInclude] @@ -320,18 +320,18 @@ public class Config_Web [JsonInclude] public string UpdateServer { get; set; } = "api.catrol.cn"; - /// - /// %platform% - Windows, Linux, MacOS (win, linux, mac) - /// + + + [JsonInclude] public string UpdatePath { get; set; } = "/apps/kitx/%platform%/"; [JsonInclude] public string UpdateDownloadPath { get; set; } = "/apps/kitx/update/%platform%/"; - /// - /// %channel% - Stable, Beta, Alpha (stable, beta, alpha) - /// + + + [JsonInclude] public string UpdateChannel { get; set; } = "stable"; @@ -342,9 +342,9 @@ public class Config_Web public int DebugServicesServerPort { get; set; } = 7777; } - /// - /// LogConfig - /// + + + public class Config_Log { @@ -378,9 +378,9 @@ public class Config_Log } - /// - /// IOConfig - /// + + + public class Config_IO { [JsonInclude] @@ -390,18 +390,18 @@ public class Config_IO public int OperatingSystemVersionUpdateInterval { get; set; } = 60; } - /// - /// ActivityConfig - /// + + + public class Config_Activity { [JsonInclude] public int TotalRecorded { get; set; } = 0; } - /// - /// LoadersConfig - /// + + + public class Config_Loaders { [JsonInclude] diff --git a/KitX Dashboard/Data/MarketConfig.cs b/KitX Dashboard/Data/MarketConfig.cs index 8166230c..ec09bf91 100644 --- a/KitX Dashboard/Data/MarketConfig.cs +++ b/KitX Dashboard/Data/MarketConfig.cs @@ -3,9 +3,9 @@ namespace KitX.Dashboard.Data; -/// -/// 市场配置文件 -/// + + + public class MarketConfig { [JsonInclude] diff --git a/KitX Dashboard/Helper.cs b/KitX Dashboard/Helper.cs index 352d182b..98664a47 100644 --- a/KitX Dashboard/Helper.cs +++ b/KitX Dashboard/Helper.cs @@ -18,10 +18,6 @@ namespace KitX.Dashboard; public static class Helper { - /// - /// 处理启动参数 - /// - /// 参数列表 public static void ProcessStartupArguments(string[] args) { try @@ -62,9 +58,6 @@ public static void ProcessStartupArguments(string[] args) } } - /// - /// Run framework - /// public static void RunFramework() { if (GlobalInfo.IsSingleProcessStartMode) @@ -196,9 +189,6 @@ public static void RunFramework() } - /// - /// 初始化环境 - /// private static void InitEnvironment() { var location = $"{nameof(Helper)}.{nameof(InitEnvironment)}"; @@ -217,9 +207,9 @@ private static void InitEnvironment() }).Start(); } - /// - /// 初始化数据库 - /// + + + private static void InitDataBase() { var location = $"{nameof(Helper)}.{nameof(InitDataBase)}"; @@ -244,9 +234,9 @@ private static void InitDataBase() } } - /// - /// 检查当前是否是单进程状态 - /// + + + private static void SingleProcessCheck() { var nowProcesses = Process.GetProcesses(); @@ -261,9 +251,9 @@ private static void SingleProcessCheck() } } - /// - /// 读取资源 - /// + + + private static async void LoadResource() { var location = $"{nameof(Helper)}.{nameof(LoadResource)}"; @@ -280,10 +270,10 @@ private static async void LoadResource() } } - /// - /// 导入插件 - /// - /// .kxp Path + + + + private static void ImportPlugin(string kxpPath) { try @@ -305,9 +295,9 @@ private static void ImportPlugin(string kxpPath) } } - /// - /// 退出 - /// + + + public static void Exit() { var location = $"{nameof(Helper)}.{nameof(Exit)}"; diff --git a/KitX Dashboard/Managers/ActivityManager.cs b/KitX Dashboard/Managers/ActivityManager.cs index 26ea4b01..22798a20 100644 --- a/KitX Dashboard/Managers/ActivityManager.cs +++ b/KitX Dashboard/Managers/ActivityManager.cs @@ -16,11 +16,11 @@ internal class ActivityManager private static Activity? _appActivity; - /// - /// 记录活动 - /// - /// 活动 - /// 键选择器 + + + + + public static void Record(Activity activity, Expression> keySelector) { var location = $"{nameof(ActivityManager)}.{nameof(Record)}"; @@ -45,10 +45,10 @@ public static void Record(Activity activity, Expression> key }, location, catchException: true); } - /// - /// 更新活动 - /// - /// 活动 + + + + public static void Update(Activity activity) { var location = $"{nameof(ActivityManager)}.{nameof(Update)}"; diff --git a/KitX Dashboard/Managers/AnouncementManager.cs b/KitX Dashboard/Managers/AnouncementManager.cs index b31b9771..52f8c04b 100644 --- a/KitX Dashboard/Managers/AnouncementManager.cs +++ b/KitX Dashboard/Managers/AnouncementManager.cs @@ -14,10 +14,10 @@ namespace KitX.Dashboard.Managers; internal class AnouncementManager { - /// - /// 异步检查新公告 - /// - /// 异步任务 + + + + public static async Task CheckNewAnnouncements() { var client = new HttpClient(); diff --git a/KitX Dashboard/Managers/CacheManager.cs b/KitX Dashboard/Managers/CacheManager.cs index 4b1d655f..9f60d52d 100644 --- a/KitX Dashboard/Managers/CacheManager.cs +++ b/KitX Dashboard/Managers/CacheManager.cs @@ -16,12 +16,12 @@ internal CacheManager() ReceivingFilesCache = new(); } - /// - /// 异步获取 MD5 值 - /// - /// 要计算的数据 - /// 是否转换格式 - /// MD5 值 + + + + + + private static async Task GetMD5(byte[] bytes, bool trans = false) { byte[]? result = null; @@ -42,12 +42,12 @@ await Task.Run(() => return sb.ToString(); } - /// - /// 异步加载本地文件到缓存 - /// - /// 文件路径 - /// 取消口令 - /// 缓存文件编号 (MD5), 如果 Hash 值已存在, 则替换原内容 + + + + + + public async Task LoadFileToCache(string fileLocation, CancellationToken token = default) { var fullPath = Path.GetFullPath(fileLocation); @@ -68,12 +68,12 @@ await Task.Run(() => return id; } - /// - /// 异步接收文件到缓存 - /// - /// 文件字节数组 - /// 取消口令 - /// 缓存文件编号 (MD5), 如果 Hash 值已存在, 则替换原内容 + + + + + + public async Task ReceiveFileToCache(byte[] bin, CancellationToken token = default) { var id = await GetMD5(bin, true); @@ -90,11 +90,11 @@ await Task.Run(() => return id; } - /// - /// 从接收到的文件缓存中获取文件 - /// - /// 缓存 ID - /// 文件字节数组 + + + + + public byte[]? GetReceivedFileFromCache(string id) { if (ReceivingFilesCache is null) return null; @@ -104,10 +104,10 @@ await Task.Run(() => else return null; } - /// - /// 清除文件缓存 - /// - /// 指定 ID 清除 + + + + public bool? DisposeFileCache(string id) { if (FilesCache is null) return null; diff --git a/KitX Dashboard/Managers/FileWatcherManager.cs b/KitX Dashboard/Managers/FileWatcherManager.cs index a81d724f..9e04e252 100644 --- a/KitX Dashboard/Managers/FileWatcherManager.cs +++ b/KitX Dashboard/Managers/FileWatcherManager.cs @@ -9,13 +9,13 @@ internal class FileWatcherManager { private readonly Dictionary Watchers = new(); - /// - /// 注册文件监控 - /// - /// 监控名称 - /// 监控文件路径 - /// 文件变更时事件 - /// 试图注册已经注册的监控 + + + + + + + public FileWatcherManager RegisterWatcher( string name, string filePath, @@ -34,10 +34,10 @@ public FileWatcherManager RegisterWatcher( return this; } - /// - /// 注销文件监控, 不存在则什么也不做 - /// - /// 监控名称 + + + + public FileWatcherManager UnregisterWatcher(string name) { if (Watchers.TryGetValue(name, out var watcher)) @@ -49,11 +49,11 @@ public FileWatcherManager UnregisterWatcher(string name) return this; } - /// - /// 增加例外次数 - /// - /// 要增加的监控 - /// 要增加的次数 + + + + + public FileWatcherManager IncreaseExceptCount(string name, int count = 1) { if (Watchers.TryGetValue(name, out var watcher)) @@ -62,11 +62,11 @@ public FileWatcherManager IncreaseExceptCount(string name, int count = 1) return this; } - /// - /// 减少例外次数 - /// - /// 要减少的监控 - /// 要减少的例外次数 + + + + + public FileWatcherManager DecreaseExceptCount(string name, int count = 1) { if (Watchers.TryGetValue(name, out var watcher)) @@ -75,9 +75,9 @@ public FileWatcherManager DecreaseExceptCount(string name, int count = 1) return this; } - /// - /// 清空所有监控 - /// + + + public FileWatcherManager Clear() { foreach (KeyValuePair item in Watchers) @@ -122,16 +122,16 @@ public FileWatcher( watcher.EnableRaisingEvents = true; } - /// - /// 增加例外次数 - /// - /// 次数 + + + + public void IncreaseExceptCount(int count) => ExceptCounts += count; - /// - /// 减少例外次数 - /// - /// 次数 + + + + public void DecreaseExceptCount(int count) => ExceptCounts -= count; public void Dispose() diff --git a/KitX Dashboard/Managers/TasksManager.cs b/KitX Dashboard/Managers/TasksManager.cs index b4a97f4a..6b8de53a 100644 --- a/KitX Dashboard/Managers/TasksManager.cs +++ b/KitX Dashboard/Managers/TasksManager.cs @@ -6,12 +6,12 @@ namespace KitX.Dashboard.Managers; internal class TasksManager { - /// - /// 执行任务, 并带有更好的日志显示 - /// - /// 要执行的动作 - /// 日志显示名称 - /// 日志提示 + + + + + + public static void RunTask( Action action, string name = nameof(Action), @@ -36,12 +36,12 @@ public static void RunTask( Log.Information($"{prompt}Task `{name}` done."); } - /// - /// 异步执行任务, 并带有更好的日志显示 - /// - /// 要执行的动作 - /// 任务名称 - /// 日志提示 + + + + + + public static async Task RunTaskAsync( Action action, string name = nameof(Action), diff --git a/KitX Dashboard/Managers/WebManager.cs b/KitX Dashboard/Managers/WebManager.cs index d3a57c1f..c5a2a9e1 100644 --- a/KitX Dashboard/Managers/WebManager.cs +++ b/KitX Dashboard/Managers/WebManager.cs @@ -18,14 +18,14 @@ public WebManager() NetworkInterfaceRegistered = new(); } - /// - /// 开始执行网络相关服务 - /// - /// 是否启动全部 - /// 是否启动插件服务器 - /// 是否启动设备服务器 - /// 是否启动设备自发现服务器 - /// 网络管理器本身 + + + + + + + + public async Task Start ( bool startAll = true, @@ -67,12 +67,12 @@ await TasksManager.RunTaskAsync(async () => return this; } - /// - /// 停止执行网络相关服务 - /// - /// 是否停止插件服务器 - /// 是否停止设备服务器 - /// 网络管理器本身 + + + + + + public WebManager Stop ( bool stopAll = true, @@ -116,13 +116,13 @@ public WebManager Stop return this; } - /// - /// 重启网络相关服务 - /// - /// 是否重启插件服务器 - /// 是否重启设备服务器 - /// 重新启动前要执行的操作 - /// 网络管理器本身 + + + + + + + public WebManager Restart ( bool restartAll = true, @@ -158,9 +158,9 @@ await Start( return this; } - /// - /// 释放资源 - /// + + + public void Dispose() { GC.SuppressFinalize(this); diff --git a/KitX Dashboard/Models/Plugin.cs b/KitX Dashboard/Models/Plugin.cs index c6e6ac90..4ee2f650 100644 --- a/KitX Dashboard/Models/Plugin.cs +++ b/KitX Dashboard/Models/Plugin.cs @@ -8,27 +8,27 @@ namespace KitX.Dashboard.Models; public class Plugin { - /// - /// 插件安装路径 - /// + + + [JsonInclude] public string? InstallPath { get; set; } - /// - /// 该插件的详细信息 - /// + + + [JsonIgnore] public PluginInfo PluginDetails { get; set; } - /// - /// 需要的加载器的详细信息 - /// + + + [JsonIgnore] public LoaderInfo RequiredLoaderInfo { get; set; } - /// - /// 已安装此插件的网络设备 - /// + + + [JsonIgnore] public List? InstalledDevices { get; set; } } diff --git a/KitX Dashboard/Network/DevicesDiscoveryServer.cs b/KitX Dashboard/Network/DevicesDiscoveryServer.cs index 7ac86cbb..cde88298 100644 --- a/KitX Dashboard/Network/DevicesDiscoveryServer.cs +++ b/KitX Dashboard/Network/DevicesDiscoveryServer.cs @@ -19,9 +19,9 @@ namespace KitX.Dashboard.Network; -/// -/// 设备自发现网络服务器 -/// + + + internal class DevicesDiscoveryServer : IKitXServer { private static UdpClient? UdpSender = null; @@ -233,9 +233,9 @@ private void MultiDevicesBroadCastSend() UdpSendTimer.Start(); } - /// - /// 多设备广播接收方法 - /// + + + private void MultiDevicesBroadCastReceive() { var location = $"{nameof(DevicesDiscoveryServer)}.{nameof(MultiDevicesBroadCastReceive)}"; @@ -412,11 +412,11 @@ public async Task BroadCast(byte[] content, Func - /// 设定当接收到数据时的处理代码 - /// - /// 处理代码, 参数一为接收到的数据 (byte[]), 参数二是数据发送者, ip:port - /// 设备自发现网络服务器本身 + + + + + public DevicesDiscoveryServer OnReceive(Action action) { onReceive = action; diff --git a/KitX Dashboard/Network/DevicesNetwork.cs b/KitX Dashboard/Network/DevicesNetwork.cs index bb6d8209..c1fc5e65 100644 --- a/KitX Dashboard/Network/DevicesNetwork.cs +++ b/KitX Dashboard/Network/DevicesNetwork.cs @@ -47,11 +47,11 @@ private static void InitEvents() }; } - /// - /// 判断设备是否应该标记为离线 - /// - /// 设备广播信息 - /// 是否离线 + + + + + private static bool CheckDeviceIsOffline(DeviceInfo info) => DateTime.UtcNow - info.SendTime.ToUniversalTime() > new TimeSpan( 0, @@ -117,9 +117,9 @@ private static void UpdateSourceAndAddCards() while (needToAddDevicesCount != 0) ; } - /// - /// 移除离线设备 - /// + + + private static void RemoveOfflineCards() { var devicesNeedToBeRemoved = new List(); @@ -146,9 +146,9 @@ private static void RemoveOfflineCards() while (removeDeviceTaskRunning) ; } - /// - /// 移动本机设备卡片到第一个 - /// + + + private static void MoveSelfCard2First() { var index = 0; @@ -184,9 +184,9 @@ private static void MoveSelfCard2First() } } - /// - /// 持续检查并移除 - /// + + + private static void KeepCheckAndRemove() { var location = $"{nameof(DevicesNetwork)}.{nameof(KeepCheckAndRemove)}"; @@ -231,10 +231,10 @@ private static void KeepCheckAndRemove() }; } - /// - /// 更新收到的UDP包 - /// - /// 设备信息结构 + + + + internal static void Update(DeviceInfo deviceInfo) { deviceInfoStructs.Enqueue(deviceInfo); @@ -250,9 +250,9 @@ internal static void Update(DeviceInfo deviceInfo) EventService.Invoke(nameof(EventService.OnReceivingDeviceInfo), deviceInfo); } - /// - /// 观察主控 - /// + + + internal static void Watch4MainDevice() { var location = $"{nameof(DevicesNetwork)}.{nameof(Watch4MainDevice)}"; @@ -318,9 +318,9 @@ internal static void Watch4MainDevice() }).Start(); } - /// - /// 观察结束 - /// + + + internal static async void WatchingOver(bool foundMainDevice, string serverAddress, int serverPort) { var location = $"{nameof(DevicesNetwork)}.{nameof(WatchingOver)}"; diff --git a/KitX Dashboard/Network/DevicesServer.cs b/KitX Dashboard/Network/DevicesServer.cs index 03ea8cc0..3dfc6fd2 100644 --- a/KitX Dashboard/Network/DevicesServer.cs +++ b/KitX Dashboard/Network/DevicesServer.cs @@ -50,9 +50,9 @@ private static void Init() keepListen = true; } - /// - /// 接收客户端 - /// + + + private static void AcceptClient() { var location = $"{nameof(DevicesServer)}.{nameof(AcceptClient)}"; @@ -80,10 +80,10 @@ private static void AcceptClient() } } - /// - /// 接收客户端消息 - /// - /// TcpClient + + + + private static void ReceiveMessage(TcpClient client) { var location = $"{nameof(DevicesServer)}.{nameof(ReceiveMessage)}"; diff --git a/KitX Dashboard/Network/NetworkStatus.cs b/KitX Dashboard/Network/NetworkStatus.cs index 88786c0f..bfd9b308 100644 --- a/KitX Dashboard/Network/NetworkStatus.cs +++ b/KitX Dashboard/Network/NetworkStatus.cs @@ -1,73 +1,67 @@ namespace KitX.Dashboard.Network; -/// -/// 服务器状态 -/// internal enum ServerStatus { - /// - /// 未知状态 - /// + + + Unknown = 0, - /// - /// 启动中 - /// + + + Starting = 1, - /// - /// 运行中 - /// + + + Running = 2, - /// - /// 停止中 - /// + + + Stopping = 3, - /// - /// 等待中 - /// + + + Pending = 4, - /// - /// 发生错误 - /// + + + Errored = 5, } -/// -/// 客户端状态 -/// internal enum ClientStatus { - /// - /// 未知状态 - /// + + + Unknown = 0, - /// - /// 连接中 - /// + + + Connecting = 1, - /// - /// 运行中 - /// + + + Running = 2, - /// - /// 断开连接中 - /// + + + Disconnecting = 3, - /// - /// 等待中 - /// + + + Pending = 4, - /// - /// 发生错误 - /// + + + Errored = 5, } diff --git a/KitX Dashboard/Network/PluginsNetwork.cs b/KitX Dashboard/Network/PluginsNetwork.cs index 72bc4423..f8820f55 100644 --- a/KitX Dashboard/Network/PluginsNetwork.cs +++ b/KitX Dashboard/Network/PluginsNetwork.cs @@ -19,10 +19,10 @@ namespace KitX.Dashboard.Managers; internal class PluginsNetwork { - /// - /// 执行 Socket 消息 - /// - /// 消息 + + + + internal static void Execute(string msg, IPEndPoint endPoint) { var location = $"{nameof(PluginsNetwork)}.{nameof(Execute)}"; @@ -74,9 +74,9 @@ internal static void Execute(string msg, IPEndPoint endPoint) internal static readonly object PluginsListOperationLock = new(); - /// - /// 持续检查并移除 - /// + + + internal static void KeepCheckAndRemove() { var location = $"{nameof(PluginsNetwork)}.{nameof(KeepCheckAndRemove)}"; @@ -142,30 +142,30 @@ internal static void KeepCheckAndRemove() timer.Start(); } - /// - /// 断开了连接 - /// - /// 插件 id + + + + internal static void Disconnect(IPEndPoint endPoint) { pluginsToRemove.Enqueue(endPoint); } - /// - /// 请求移除插件 - /// - /// 插件的安装信息 + + + + internal static void RequireRemovePlugin(Plugin plugin) => pluginsToRemoveFromDB.Enqueue(plugin); - /// - /// 请求删除插件 - /// - /// 插件的安装信息 + + + + internal static void RequireDeletePlugin(Plugin plugin) => pluginsToDelete.Enqueue(plugin); - /// - /// 持续检查移除和删除队列 - /// + + + internal static void KeepCheckAndRemoveOrDelete() { var location = $"{nameof(PluginsNetwork)}.{nameof(KeepCheckAndRemoveOrDelete)}"; diff --git a/KitX Dashboard/Network/PluginsServer.cs b/KitX Dashboard/Network/PluginsServer.cs index ede98d30..3803e50d 100644 --- a/KitX Dashboard/Network/PluginsServer.cs +++ b/KitX Dashboard/Network/PluginsServer.cs @@ -51,9 +51,9 @@ private static void Init() keepListen = true; } - /// - /// 接收客户端 - /// + + + private static void AcceptClient() { var location = $"{nameof(PluginsServer)}.{nameof(AcceptClient)}"; @@ -81,10 +81,10 @@ private static void AcceptClient() } } - /// - /// 接收消息 - /// - /// TcpClient + + + + private static void ReceiveMessage(TcpClient client) { var location = $"{nameof(PluginsServer)}.{nameof(ReceiveMessage)}"; diff --git a/KitX Dashboard/Program.cs b/KitX Dashboard/Program.cs index 38a8d072..8cfaef85 100644 --- a/KitX Dashboard/Program.cs +++ b/KitX Dashboard/Program.cs @@ -10,13 +10,13 @@ namespace KitX.Dashboard; class Program { - /// - /// Main entry for program - /// - /// - /// Initialization code. Don't use any Avalonia, third-party APIs or any - /// SynchronizationContext-reliant code before AppMain is called: things aren't initialized - /// yet and stuff might break. + + + + + + + [STAThread] public static void Main(string[] args) { @@ -61,11 +61,11 @@ public static void Main(string[] args) } } - /// - /// Build Avalonia app - /// - /// Avalonia AppBuilder - /// Do not remove this, it also used by visual designer. + + + + + public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() diff --git a/KitX Dashboard/Services/DebugService.cs b/KitX Dashboard/Services/DebugService.cs index 0253157d..2d4b39b0 100644 --- a/KitX Dashboard/Services/DebugService.cs +++ b/KitX Dashboard/Services/DebugService.cs @@ -14,11 +14,11 @@ namespace KitX.Dashboard.Services; internal class DebugService { - /// - /// 执行命令 - /// - /// 命令 - /// 执行结果 + + + + + internal static string? ExecuteCommand(string cmd) { var header = cmd.GetCommandHeader(); @@ -330,11 +330,11 @@ private static string SaveConfig() internal static class DebugServiceTool { - /// - /// 获取命令头 - /// - /// 命令 - /// 命令头 + + + + + internal static string? GetCommandHeader(this string cmd) { var command = cmd.Trim(); @@ -343,11 +343,11 @@ internal static class DebugServiceTool return header; } - /// - /// 获取命令参数 - /// - /// 命令 - /// 参数字典 + + + + + internal static Dictionary? GetCommandArgs(this string cmd) { var args = new Dictionary(); @@ -376,11 +376,11 @@ internal static class DebugServiceTool return args; } - /// - /// 替换文本中的引号内容 - /// - /// 文本 - /// 新的引号键以及对应的值 + + + + + internal static (string, Dictionary) ReplaceQuotes(this string text) { // 记录被替换的引号内容的键与内容 @@ -409,20 +409,20 @@ internal static (string, Dictionary) ReplaceQuotes(this string t return (text, rst); } - /// - /// 获取字典中的值 - /// - /// 字典 - /// 键 - /// + + + + + + internal static string? Value(this Dictionary src, string key) => src.TryGetValue(key, out var value) ? value : null; - /// - /// 将命令转为可能的函数名称 - /// - /// 命令 - /// 可能的函数名称 + + + + + internal static string ToFunctionName(this string cmd) => $"{cmd[0].ToString().ToUpper()}{cmd[1..].ToLower()}"; } diff --git a/KitX Dashboard/Services/EventService.cs b/KitX Dashboard/Services/EventService.cs index c133b822..bf27cba1 100644 --- a/KitX Dashboard/Services/EventService.cs +++ b/KitX Dashboard/Services/EventService.cs @@ -66,9 +66,9 @@ internal static class EventService internal static event OnConfigHotReloadedHandler? OnConfigHotReloaded; - /// - /// 必要的初始化 - /// + + + internal static void Init() { LanguageChanged += () => { }; @@ -87,10 +87,10 @@ internal static void Init() PluginsServerPortChanged += () => { }; } - /// - /// 执行全局事件 - /// - /// 事件名称 + + + + internal static void Invoke(string eventName) { switch (eventName) @@ -137,11 +137,11 @@ internal static void Invoke(string eventName) } } - /// - /// 执行全局事件 - /// - /// 事件名称 - /// 事件参数 + + + + + internal static void Invoke(string eventName, object arg) { switch (eventName) diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs index 20c4951a..a2884390 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs @@ -8,8 +8,8 @@ internal class Home_RecentUseViewModel : ViewModelBase public double NoRecent_TipHeight { get; set; } = 200; - /// - /// 插件卡片集合 - /// + + + public ObservableCollection RecentPluginCards { get; } = new(); } diff --git a/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs b/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs index 09e39824..0a2f7a9d 100644 --- a/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs @@ -47,13 +47,13 @@ public double NoPlugins_TipHeight } } - /// - /// 插件卡片集合 - /// + + + public static ObservableCollection PluginCards => Instances.PluginCards; - /// - /// 搜索框文字 - /// + + + public string? SearchingText { get; set; } } diff --git a/KitX Dashboard/Views/MainWindow.axaml.cs b/KitX Dashboard/Views/MainWindow.axaml.cs index 9cb01ec6..e152e716 100644 --- a/KitX Dashboard/Views/MainWindow.axaml.cs +++ b/KitX Dashboard/Views/MainWindow.axaml.cs @@ -24,9 +24,9 @@ public partial class MainWindow : Window { private readonly MainWindowViewModel viewModel = new(); - /// - /// 主窗体的构造函数 - /// + + + public MainWindow() { var location = $"{nameof(MainWindow)}"; @@ -106,9 +106,9 @@ public MainWindow() InitMainWindow(); } - /// - /// 建议分辨率和位置 - /// + + + private void SuggestResolutionAndLocation() { if (Screens.Primary is null) return; @@ -133,9 +133,9 @@ private void SuggestResolutionAndLocation() } } - /// - /// 初始化主窗体 - /// + + + private void InitMainWindow() { // 导航到上次关闭时界面 @@ -179,17 +179,17 @@ private void InitMainWindow() Instances.SignalTasksManager?.RaiseSignal(nameof(SignalsNames.MainWindowInitSignal)); } - /// - /// 保存对配置文件的修改 - /// + + + private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); } - /// - /// 更新招呼语 - /// + + + internal void UpdateGreetingText() { try @@ -213,11 +213,11 @@ internal void UpdateGreetingText() } } - /// - /// 通过名称获取页面类型 - /// - /// 页面名称 - /// 页面类型 + + + + + private static Type GetPageTypeFromName(string name) => name switch { "Page_Home" => typeof(Pages.HomePage), @@ -230,9 +230,9 @@ internal void UpdateGreetingText() _ => typeof(Pages.HomePage), }; - /// - /// 已选择的页面名称 - /// + + + private static string SelectedPageName { get => ConfigManager.AppConfig.Windows.MainWindow.Tags["SelectedPage"]; @@ -243,11 +243,11 @@ private static string SelectedPageName } } - /// - /// 前台页面切换事件 - /// - /// 被点击的 NavigationViewItem - /// 路由事件参数 + + + + + private void MainNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) @@ -274,9 +274,9 @@ private void MainNavigationView_SelectionChanged( } } - /// - /// 储存元数据 - /// + + + private void SaveMetaData() { if (WindowState != WindowState.Maximized) @@ -301,10 +301,10 @@ private void SaveMetaData() ConfigManager.AppConfig.Windows.MainWindow.Tags["SelectedPage"] = SelectedPageName; } - /// - /// 窗口状态改变事件 - /// - /// 窗口状态 + + + + //protected override void HandleWindowStateChanged(WindowState state) //{ // ConfigManager.AppConfig.Windows.MainWindow.WindowState = state; @@ -315,10 +315,10 @@ private void SaveMetaData() // base.HandleWindowStateChanged(state); //} - /// - /// 正在关闭窗口时事件 - /// - /// 关闭事件参数 + + + + protected override void OnClosing(WindowClosingEventArgs e) { base.OnClosing(e); @@ -341,10 +341,10 @@ protected override void OnClosing(WindowClosingEventArgs e) } } - /// - /// 窗体正在启动事件 - /// - /// 窗体启动参数 + + + + protected override void OnOpened(EventArgs e) { base.OnOpened(e); @@ -362,11 +362,11 @@ protected override void OnOpened(EventArgs e) Instances.SignalTasksManager?.RaiseSignal(nameof(SignalsNames.MainWindowOpenedSignal)); } - /// - /// 主题正在更改请求事件 - /// - /// FluentAvaloniaTheme - /// 主题正在更改请求参数 + + + + + //private void OnRequestedThemeChanged( // FluentAvaloniaTheme sender, // RequestedThemeChangedEventArgs args) @@ -380,9 +380,9 @@ protected override void OnOpened(EventArgs e) // } //} - /// - /// 尝试启用云母特效 - /// + + + private void TryEnableMicaEffect() { _ = this.TryFindResource( diff --git a/KitX Dashboard/Views/Pages/HomePage.axaml.cs b/KitX Dashboard/Views/Pages/HomePage.axaml.cs index f977e8ea..259c4c10 100644 --- a/KitX Dashboard/Views/Pages/HomePage.axaml.cs +++ b/KitX Dashboard/Views/Pages/HomePage.axaml.cs @@ -22,18 +22,18 @@ public HomePage() InitHomePage(); } - /// - /// 初始化主页 - /// + + + private void InitHomePage() { this.FindControl("HomeNavigationView").SelectedItem = this.FindControl(SelectedViewName); } - /// - /// 保存对配置文件的修改 - /// + + + private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); @@ -49,11 +49,11 @@ private static string SelectedViewName } } - /// - /// 前台页面切换事件 - /// - /// 被点击的 NavigationViewItem - /// 路由事件参数 + + + + + private void HomeNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) diff --git a/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs b/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs index fb6b0bd9..2333cca0 100644 --- a/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs +++ b/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs @@ -22,28 +22,28 @@ public SettingsPage() InitSettingsPage(); } - /// - /// 初始化设置页面 - /// + + + private void InitSettingsPage() { this.FindControl("SettingsNavigationView").SelectedItem = this.FindControl(SelectedViewName); } - /// - /// 保存对配置文件的修改 - /// + + + private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); } - /// - /// 前台页面切换事件 - /// - /// 被点击的 NavigationViewItem - /// 路由事件参数 + + + + + private void SettingsNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) From cdc0d1dc9124ede324d7382065342b44a76541a7 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Fri, 26 Jan 2024 16:45:12 +0800 Subject: [PATCH 03/27] =?UTF-8?q?=F0=9F=93=A6=20Struct:=20Optimized.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/WindowAttributesConverter.cs | 6 --- KitX Dashboard/Data/AppConfig.cs | 54 ++----------------- KitX Dashboard/Data/MarketConfig.cs | 3 -- KitX Dashboard/Helper.cs | 16 ------ KitX Dashboard/Managers/ActivityManager.cs | 9 ---- KitX Dashboard/Managers/AnouncementManager.cs | 4 -- KitX Dashboard/Managers/CacheManager.cs | 27 ---------- KitX Dashboard/Managers/FileWatcherManager.cs | 32 ----------- KitX Dashboard/Managers/TasksManager.cs | 12 ----- KitX Dashboard/Managers/WebManager.cs | 24 --------- KitX Dashboard/Models/Plugin.cs | 12 ----- .../Network/DevicesDiscoveryServer.cs | 11 ---- KitX Dashboard/Network/DevicesNetwork.cs | 24 --------- KitX Dashboard/Network/DevicesServer.cs | 7 --- KitX Dashboard/Network/NetworkStatus.cs | 36 ------------- KitX Dashboard/Network/PluginsNetwork.cs | 22 -------- KitX Dashboard/Network/PluginsServer.cs | 7 --- KitX Dashboard/Program.cs | 24 ++++----- KitX Dashboard/Services/DebugService.cs | 31 ----------- KitX Dashboard/Services/EventService.cs | 13 ----- .../Pages/Controls/Home_RecentUseViewModel.cs | 3 -- .../ViewModels/Pages/LibPageViewModel.cs | 6 --- KitX Dashboard/Views/MainWindow.axaml.cs | 51 ------------------ KitX Dashboard/Views/Pages/HomePage.axaml.cs | 11 ---- .../Views/Pages/SettingsPage.axaml.cs | 11 ---- 25 files changed, 15 insertions(+), 441 deletions(-) diff --git a/KitX Dashboard/Converters/WindowAttributesConverter.cs b/KitX Dashboard/Converters/WindowAttributesConverter.cs index e9ada86a..eb9aee0c 100644 --- a/KitX Dashboard/Converters/WindowAttributesConverter.cs +++ b/KitX Dashboard/Converters/WindowAttributesConverter.cs @@ -5,12 +5,6 @@ namespace KitX.Dashboard.Converters; internal class WindowAttributesConverter { - - - - - - internal static int PositionCameCenter(int input, bool isLeft, Screens screens, Resolution win) { if (win.Width is null || win.Height is null) return 0; diff --git a/KitX Dashboard/Data/AppConfig.cs b/KitX Dashboard/Data/AppConfig.cs index cb2a50a4..d12431eb 100644 --- a/KitX Dashboard/Data/AppConfig.cs +++ b/KitX Dashboard/Data/AppConfig.cs @@ -6,9 +6,6 @@ namespace KitX.Dashboard.Data; - - - public class AppConfig { [JsonInclude] @@ -35,9 +32,6 @@ public class AppConfig [JsonInclude] public Config_Loaders Loaders { get; set; } = new(); - - - public class Config_App { [JsonInclude] @@ -83,9 +77,6 @@ public class Config_App public ulong RanTime { get; set; } = 0; } - - - public class Config_Windows { @@ -95,9 +86,6 @@ public class Config_Windows [JsonInclude] public Config_AnnouncementWindow AnnouncementWindow { get; set; } = new(); - - - public class Config_MainWindow { [JsonInclude] @@ -149,9 +137,6 @@ public class Config_MainWindow public int GreetingUpdateInterval { get; set; } = 10; } - - - public class Config_AnnouncementWindow { [JsonInclude] @@ -168,9 +153,6 @@ public class Config_AnnouncementWindow } } - - - public class Config_Pages { [JsonInclude] @@ -185,9 +167,6 @@ public class Config_Pages [JsonInclude] public Config_SettingsPage Settings { get; set; } = new(); - - - public class Config_HomePage { [JsonInclude] @@ -204,25 +183,16 @@ public class Config_HomePage public bool UseAreaExpanded { get; set; } = true; } - - - public class Config_DevicePage { } - - - public class Config_MarketPage { } - - - public class Config_SettingsPage { [JsonInclude] @@ -270,9 +240,6 @@ public class Config_SettingsPage } } - - - public class Config_Web { [JsonInclude] @@ -320,18 +287,15 @@ public class Config_Web [JsonInclude] public string UpdateServer { get; set; } = "api.catrol.cn"; - - - [JsonInclude] public string UpdatePath { get; set; } = "/apps/kitx/%platform%/"; [JsonInclude] public string UpdateDownloadPath { get; set; } = "/apps/kitx/update/%platform%/"; - - - + /// + /// %channel% - Stable, Beta, Alpha (stable, beta, alpha) + /// [JsonInclude] public string UpdateChannel { get; set; } = "stable"; @@ -342,9 +306,6 @@ public class Config_Web public int DebugServicesServerPort { get; set; } = 7777; } - - - public class Config_Log { @@ -378,9 +339,6 @@ public class Config_Log } - - - public class Config_IO { [JsonInclude] @@ -390,18 +348,12 @@ public class Config_IO public int OperatingSystemVersionUpdateInterval { get; set; } = 60; } - - - public class Config_Activity { [JsonInclude] public int TotalRecorded { get; set; } = 0; } - - - public class Config_Loaders { [JsonInclude] diff --git a/KitX Dashboard/Data/MarketConfig.cs b/KitX Dashboard/Data/MarketConfig.cs index ec09bf91..921bba52 100644 --- a/KitX Dashboard/Data/MarketConfig.cs +++ b/KitX Dashboard/Data/MarketConfig.cs @@ -3,9 +3,6 @@ namespace KitX.Dashboard.Data; - - - public class MarketConfig { [JsonInclude] diff --git a/KitX Dashboard/Helper.cs b/KitX Dashboard/Helper.cs index 98664a47..d90cfd8e 100644 --- a/KitX Dashboard/Helper.cs +++ b/KitX Dashboard/Helper.cs @@ -207,9 +207,6 @@ private static void InitEnvironment() }).Start(); } - - - private static void InitDataBase() { var location = $"{nameof(Helper)}.{nameof(InitDataBase)}"; @@ -234,9 +231,6 @@ private static void InitDataBase() } } - - - private static void SingleProcessCheck() { var nowProcesses = Process.GetProcesses(); @@ -251,9 +245,6 @@ private static void SingleProcessCheck() } } - - - private static async void LoadResource() { var location = $"{nameof(Helper)}.{nameof(LoadResource)}"; @@ -270,10 +261,6 @@ private static async void LoadResource() } } - - - - private static void ImportPlugin(string kxpPath) { try @@ -295,9 +282,6 @@ private static void ImportPlugin(string kxpPath) } } - - - public static void Exit() { var location = $"{nameof(Helper)}.{nameof(Exit)}"; diff --git a/KitX Dashboard/Managers/ActivityManager.cs b/KitX Dashboard/Managers/ActivityManager.cs index 22798a20..cba9ce3a 100644 --- a/KitX Dashboard/Managers/ActivityManager.cs +++ b/KitX Dashboard/Managers/ActivityManager.cs @@ -16,11 +16,6 @@ internal class ActivityManager private static Activity? _appActivity; - - - - - public static void Record(Activity activity, Expression> keySelector) { var location = $"{nameof(ActivityManager)}.{nameof(Record)}"; @@ -45,10 +40,6 @@ public static void Record(Activity activity, Expression> key }, location, catchException: true); } - - - - public static void Update(Activity activity) { var location = $"{nameof(ActivityManager)}.{nameof(Update)}"; diff --git a/KitX Dashboard/Managers/AnouncementManager.cs b/KitX Dashboard/Managers/AnouncementManager.cs index 52f8c04b..b9322797 100644 --- a/KitX Dashboard/Managers/AnouncementManager.cs +++ b/KitX Dashboard/Managers/AnouncementManager.cs @@ -14,10 +14,6 @@ namespace KitX.Dashboard.Managers; internal class AnouncementManager { - - - - public static async Task CheckNewAnnouncements() { var client = new HttpClient(); diff --git a/KitX Dashboard/Managers/CacheManager.cs b/KitX Dashboard/Managers/CacheManager.cs index 9f60d52d..03d58b2c 100644 --- a/KitX Dashboard/Managers/CacheManager.cs +++ b/KitX Dashboard/Managers/CacheManager.cs @@ -16,12 +16,6 @@ internal CacheManager() ReceivingFilesCache = new(); } - - - - - - private static async Task GetMD5(byte[] bytes, bool trans = false) { byte[]? result = null; @@ -42,12 +36,6 @@ await Task.Run(() => return sb.ToString(); } - - - - - - public async Task LoadFileToCache(string fileLocation, CancellationToken token = default) { var fullPath = Path.GetFullPath(fileLocation); @@ -68,12 +56,6 @@ await Task.Run(() => return id; } - - - - - - public async Task ReceiveFileToCache(byte[] bin, CancellationToken token = default) { var id = await GetMD5(bin, true); @@ -90,11 +72,6 @@ await Task.Run(() => return id; } - - - - - public byte[]? GetReceivedFileFromCache(string id) { if (ReceivingFilesCache is null) return null; @@ -104,10 +81,6 @@ await Task.Run(() => else return null; } - - - - public bool? DisposeFileCache(string id) { if (FilesCache is null) return null; diff --git a/KitX Dashboard/Managers/FileWatcherManager.cs b/KitX Dashboard/Managers/FileWatcherManager.cs index 9e04e252..c18a3e14 100644 --- a/KitX Dashboard/Managers/FileWatcherManager.cs +++ b/KitX Dashboard/Managers/FileWatcherManager.cs @@ -9,13 +9,6 @@ internal class FileWatcherManager { private readonly Dictionary Watchers = new(); - - - - - - - public FileWatcherManager RegisterWatcher( string name, string filePath, @@ -34,10 +27,6 @@ public FileWatcherManager RegisterWatcher( return this; } - - - - public FileWatcherManager UnregisterWatcher(string name) { if (Watchers.TryGetValue(name, out var watcher)) @@ -49,11 +38,6 @@ public FileWatcherManager UnregisterWatcher(string name) return this; } - - - - - public FileWatcherManager IncreaseExceptCount(string name, int count = 1) { if (Watchers.TryGetValue(name, out var watcher)) @@ -62,11 +46,6 @@ public FileWatcherManager IncreaseExceptCount(string name, int count = 1) return this; } - - - - - public FileWatcherManager DecreaseExceptCount(string name, int count = 1) { if (Watchers.TryGetValue(name, out var watcher)) @@ -75,9 +54,6 @@ public FileWatcherManager DecreaseExceptCount(string name, int count = 1) return this; } - - - public FileWatcherManager Clear() { foreach (KeyValuePair item in Watchers) @@ -122,16 +98,8 @@ public FileWatcher( watcher.EnableRaisingEvents = true; } - - - - public void IncreaseExceptCount(int count) => ExceptCounts += count; - - - - public void DecreaseExceptCount(int count) => ExceptCounts -= count; public void Dispose() diff --git a/KitX Dashboard/Managers/TasksManager.cs b/KitX Dashboard/Managers/TasksManager.cs index 6b8de53a..e15a63cf 100644 --- a/KitX Dashboard/Managers/TasksManager.cs +++ b/KitX Dashboard/Managers/TasksManager.cs @@ -6,12 +6,6 @@ namespace KitX.Dashboard.Managers; internal class TasksManager { - - - - - - public static void RunTask( Action action, string name = nameof(Action), @@ -36,12 +30,6 @@ public static void RunTask( Log.Information($"{prompt}Task `{name}` done."); } - - - - - - public static async Task RunTaskAsync( Action action, string name = nameof(Action), diff --git a/KitX Dashboard/Managers/WebManager.cs b/KitX Dashboard/Managers/WebManager.cs index c5a2a9e1..63b646d0 100644 --- a/KitX Dashboard/Managers/WebManager.cs +++ b/KitX Dashboard/Managers/WebManager.cs @@ -18,14 +18,6 @@ public WebManager() NetworkInterfaceRegistered = new(); } - - - - - - - - public async Task Start ( bool startAll = true, @@ -67,12 +59,6 @@ await TasksManager.RunTaskAsync(async () => return this; } - - - - - - public WebManager Stop ( bool stopAll = true, @@ -116,13 +102,6 @@ public WebManager Stop return this; } - - - - - - - public WebManager Restart ( bool restartAll = true, @@ -158,9 +137,6 @@ await Start( return this; } - - - public void Dispose() { GC.SuppressFinalize(this); diff --git a/KitX Dashboard/Models/Plugin.cs b/KitX Dashboard/Models/Plugin.cs index 4ee2f650..1f666f71 100644 --- a/KitX Dashboard/Models/Plugin.cs +++ b/KitX Dashboard/Models/Plugin.cs @@ -8,27 +8,15 @@ namespace KitX.Dashboard.Models; public class Plugin { - - - [JsonInclude] public string? InstallPath { get; set; } - - - [JsonIgnore] public PluginInfo PluginDetails { get; set; } - - - [JsonIgnore] public LoaderInfo RequiredLoaderInfo { get; set; } - - - [JsonIgnore] public List? InstalledDevices { get; set; } } diff --git a/KitX Dashboard/Network/DevicesDiscoveryServer.cs b/KitX Dashboard/Network/DevicesDiscoveryServer.cs index cde88298..fbc6d06a 100644 --- a/KitX Dashboard/Network/DevicesDiscoveryServer.cs +++ b/KitX Dashboard/Network/DevicesDiscoveryServer.cs @@ -19,9 +19,6 @@ namespace KitX.Dashboard.Network; - - - internal class DevicesDiscoveryServer : IKitXServer { private static UdpClient? UdpSender = null; @@ -233,9 +230,6 @@ private void MultiDevicesBroadCastSend() UdpSendTimer.Start(); } - - - private void MultiDevicesBroadCastReceive() { var location = $"{nameof(DevicesDiscoveryServer)}.{nameof(MultiDevicesBroadCastReceive)}"; @@ -412,11 +406,6 @@ public async Task BroadCast(byte[] content, Func action) { onReceive = action; diff --git a/KitX Dashboard/Network/DevicesNetwork.cs b/KitX Dashboard/Network/DevicesNetwork.cs index c1fc5e65..9b4a5dd3 100644 --- a/KitX Dashboard/Network/DevicesNetwork.cs +++ b/KitX Dashboard/Network/DevicesNetwork.cs @@ -47,11 +47,6 @@ private static void InitEvents() }; } - - - - - private static bool CheckDeviceIsOffline(DeviceInfo info) => DateTime.UtcNow - info.SendTime.ToUniversalTime() > new TimeSpan( 0, @@ -117,9 +112,6 @@ private static void UpdateSourceAndAddCards() while (needToAddDevicesCount != 0) ; } - - - private static void RemoveOfflineCards() { var devicesNeedToBeRemoved = new List(); @@ -146,9 +138,6 @@ private static void RemoveOfflineCards() while (removeDeviceTaskRunning) ; } - - - private static void MoveSelfCard2First() { var index = 0; @@ -184,9 +173,6 @@ private static void MoveSelfCard2First() } } - - - private static void KeepCheckAndRemove() { var location = $"{nameof(DevicesNetwork)}.{nameof(KeepCheckAndRemove)}"; @@ -231,10 +217,6 @@ private static void KeepCheckAndRemove() }; } - - - - internal static void Update(DeviceInfo deviceInfo) { deviceInfoStructs.Enqueue(deviceInfo); @@ -250,9 +232,6 @@ internal static void Update(DeviceInfo deviceInfo) EventService.Invoke(nameof(EventService.OnReceivingDeviceInfo), deviceInfo); } - - - internal static void Watch4MainDevice() { var location = $"{nameof(DevicesNetwork)}.{nameof(Watch4MainDevice)}"; @@ -318,9 +297,6 @@ internal static void Watch4MainDevice() }).Start(); } - - - internal static async void WatchingOver(bool foundMainDevice, string serverAddress, int serverPort) { var location = $"{nameof(DevicesNetwork)}.{nameof(WatchingOver)}"; diff --git a/KitX Dashboard/Network/DevicesServer.cs b/KitX Dashboard/Network/DevicesServer.cs index 3dfc6fd2..c9d665dd 100644 --- a/KitX Dashboard/Network/DevicesServer.cs +++ b/KitX Dashboard/Network/DevicesServer.cs @@ -50,9 +50,6 @@ private static void Init() keepListen = true; } - - - private static void AcceptClient() { var location = $"{nameof(DevicesServer)}.{nameof(AcceptClient)}"; @@ -80,10 +77,6 @@ private static void AcceptClient() } } - - - - private static void ReceiveMessage(TcpClient client) { var location = $"{nameof(DevicesServer)}.{nameof(ReceiveMessage)}"; diff --git a/KitX Dashboard/Network/NetworkStatus.cs b/KitX Dashboard/Network/NetworkStatus.cs index bfd9b308..e3a9a9de 100644 --- a/KitX Dashboard/Network/NetworkStatus.cs +++ b/KitX Dashboard/Network/NetworkStatus.cs @@ -2,66 +2,30 @@ internal enum ServerStatus { - - - Unknown = 0, - - - Starting = 1, - - - Running = 2, - - - Stopping = 3, - - - Pending = 4, - - - Errored = 5, } internal enum ClientStatus { - - - Unknown = 0, - - - Connecting = 1, - - - Running = 2, - - - Disconnecting = 3, - - - Pending = 4, - - - Errored = 5, } diff --git a/KitX Dashboard/Network/PluginsNetwork.cs b/KitX Dashboard/Network/PluginsNetwork.cs index f8820f55..b9057107 100644 --- a/KitX Dashboard/Network/PluginsNetwork.cs +++ b/KitX Dashboard/Network/PluginsNetwork.cs @@ -19,10 +19,6 @@ namespace KitX.Dashboard.Managers; internal class PluginsNetwork { - - - - internal static void Execute(string msg, IPEndPoint endPoint) { var location = $"{nameof(PluginsNetwork)}.{nameof(Execute)}"; @@ -74,9 +70,6 @@ internal static void Execute(string msg, IPEndPoint endPoint) internal static readonly object PluginsListOperationLock = new(); - - - internal static void KeepCheckAndRemove() { var location = $"{nameof(PluginsNetwork)}.{nameof(KeepCheckAndRemove)}"; @@ -142,30 +135,15 @@ internal static void KeepCheckAndRemove() timer.Start(); } - - - - internal static void Disconnect(IPEndPoint endPoint) { pluginsToRemove.Enqueue(endPoint); } - - - - internal static void RequireRemovePlugin(Plugin plugin) => pluginsToRemoveFromDB.Enqueue(plugin); - - - - internal static void RequireDeletePlugin(Plugin plugin) => pluginsToDelete.Enqueue(plugin); - - - internal static void KeepCheckAndRemoveOrDelete() { var location = $"{nameof(PluginsNetwork)}.{nameof(KeepCheckAndRemoveOrDelete)}"; diff --git a/KitX Dashboard/Network/PluginsServer.cs b/KitX Dashboard/Network/PluginsServer.cs index 3803e50d..f53a57b5 100644 --- a/KitX Dashboard/Network/PluginsServer.cs +++ b/KitX Dashboard/Network/PluginsServer.cs @@ -51,9 +51,6 @@ private static void Init() keepListen = true; } - - - private static void AcceptClient() { var location = $"{nameof(PluginsServer)}.{nameof(AcceptClient)}"; @@ -81,10 +78,6 @@ private static void AcceptClient() } } - - - - private static void ReceiveMessage(TcpClient client) { var location = $"{nameof(PluginsServer)}.{nameof(ReceiveMessage)}"; diff --git a/KitX Dashboard/Program.cs b/KitX Dashboard/Program.cs index 8cfaef85..38a8d072 100644 --- a/KitX Dashboard/Program.cs +++ b/KitX Dashboard/Program.cs @@ -10,13 +10,13 @@ namespace KitX.Dashboard; class Program { - - - - - - - + /// + /// Main entry for program + /// + /// + /// Initialization code. Don't use any Avalonia, third-party APIs or any + /// SynchronizationContext-reliant code before AppMain is called: things aren't initialized + /// yet and stuff might break. [STAThread] public static void Main(string[] args) { @@ -61,11 +61,11 @@ public static void Main(string[] args) } } - - - - - + /// + /// Build Avalonia app + /// + /// Avalonia AppBuilder + /// Do not remove this, it also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() diff --git a/KitX Dashboard/Services/DebugService.cs b/KitX Dashboard/Services/DebugService.cs index 2d4b39b0..093b8fd5 100644 --- a/KitX Dashboard/Services/DebugService.cs +++ b/KitX Dashboard/Services/DebugService.cs @@ -14,11 +14,6 @@ namespace KitX.Dashboard.Services; internal class DebugService { - - - - - internal static string? ExecuteCommand(string cmd) { var header = cmd.GetCommandHeader(); @@ -330,11 +325,6 @@ private static string SaveConfig() internal static class DebugServiceTool { - - - - - internal static string? GetCommandHeader(this string cmd) { var command = cmd.Trim(); @@ -343,11 +333,6 @@ internal static class DebugServiceTool return header; } - - - - - internal static Dictionary? GetCommandArgs(this string cmd) { var args = new Dictionary(); @@ -376,11 +361,6 @@ internal static class DebugServiceTool return args; } - - - - - internal static (string, Dictionary) ReplaceQuotes(this string text) { // 记录被替换的引号内容的键与内容 @@ -409,20 +389,9 @@ internal static (string, Dictionary) ReplaceQuotes(this string t return (text, rst); } - - - - - - internal static string? Value(this Dictionary src, string key) => src.TryGetValue(key, out var value) ? value : null; - - - - - internal static string ToFunctionName(this string cmd) => $"{cmd[0].ToString().ToUpper()}{cmd[1..].ToLower()}"; } diff --git a/KitX Dashboard/Services/EventService.cs b/KitX Dashboard/Services/EventService.cs index bf27cba1..88346a97 100644 --- a/KitX Dashboard/Services/EventService.cs +++ b/KitX Dashboard/Services/EventService.cs @@ -65,10 +65,6 @@ internal static class EventService internal static event OnConfigHotReloadedHandler? OnConfigHotReloaded; - - - - internal static void Init() { LanguageChanged += () => { }; @@ -87,10 +83,6 @@ internal static void Init() PluginsServerPortChanged += () => { }; } - - - - internal static void Invoke(string eventName) { switch (eventName) @@ -137,11 +129,6 @@ internal static void Invoke(string eventName) } } - - - - - internal static void Invoke(string eventName, object arg) { switch (eventName) diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs index a2884390..8328e33e 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs @@ -8,8 +8,5 @@ internal class Home_RecentUseViewModel : ViewModelBase public double NoRecent_TipHeight { get; set; } = 200; - - - public ObservableCollection RecentPluginCards { get; } = new(); } diff --git a/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs b/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs index 0a2f7a9d..f9ae0423 100644 --- a/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/LibPageViewModel.cs @@ -47,13 +47,7 @@ public double NoPlugins_TipHeight } } - - - public static ObservableCollection PluginCards => Instances.PluginCards; - - - public string? SearchingText { get; set; } } diff --git a/KitX Dashboard/Views/MainWindow.axaml.cs b/KitX Dashboard/Views/MainWindow.axaml.cs index e152e716..2cfbaa15 100644 --- a/KitX Dashboard/Views/MainWindow.axaml.cs +++ b/KitX Dashboard/Views/MainWindow.axaml.cs @@ -24,9 +24,6 @@ public partial class MainWindow : Window { private readonly MainWindowViewModel viewModel = new(); - - - public MainWindow() { var location = $"{nameof(MainWindow)}"; @@ -106,9 +103,6 @@ public MainWindow() InitMainWindow(); } - - - private void SuggestResolutionAndLocation() { if (Screens.Primary is null) return; @@ -133,9 +127,6 @@ private void SuggestResolutionAndLocation() } } - - - private void InitMainWindow() { // 导航到上次关闭时界面 @@ -179,17 +170,11 @@ private void InitMainWindow() Instances.SignalTasksManager?.RaiseSignal(nameof(SignalsNames.MainWindowInitSignal)); } - - - private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); } - - - internal void UpdateGreetingText() { try @@ -213,11 +198,6 @@ internal void UpdateGreetingText() } } - - - - - private static Type GetPageTypeFromName(string name) => name switch { "Page_Home" => typeof(Pages.HomePage), @@ -230,9 +210,6 @@ internal void UpdateGreetingText() _ => typeof(Pages.HomePage), }; - - - private static string SelectedPageName { get => ConfigManager.AppConfig.Windows.MainWindow.Tags["SelectedPage"]; @@ -243,11 +220,6 @@ private static string SelectedPageName } } - - - - - private void MainNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) @@ -274,9 +246,6 @@ private void MainNavigationView_SelectionChanged( } } - - - private void SaveMetaData() { if (WindowState != WindowState.Maximized) @@ -301,10 +270,6 @@ private void SaveMetaData() ConfigManager.AppConfig.Windows.MainWindow.Tags["SelectedPage"] = SelectedPageName; } - - - - //protected override void HandleWindowStateChanged(WindowState state) //{ // ConfigManager.AppConfig.Windows.MainWindow.WindowState = state; @@ -315,10 +280,6 @@ private void SaveMetaData() // base.HandleWindowStateChanged(state); //} - - - - protected override void OnClosing(WindowClosingEventArgs e) { base.OnClosing(e); @@ -341,10 +302,6 @@ protected override void OnClosing(WindowClosingEventArgs e) } } - - - - protected override void OnOpened(EventArgs e) { base.OnOpened(e); @@ -362,11 +319,6 @@ protected override void OnOpened(EventArgs e) Instances.SignalTasksManager?.RaiseSignal(nameof(SignalsNames.MainWindowOpenedSignal)); } - - - - - //private void OnRequestedThemeChanged( // FluentAvaloniaTheme sender, // RequestedThemeChangedEventArgs args) @@ -380,9 +332,6 @@ protected override void OnOpened(EventArgs e) // } //} - - - private void TryEnableMicaEffect() { _ = this.TryFindResource( diff --git a/KitX Dashboard/Views/Pages/HomePage.axaml.cs b/KitX Dashboard/Views/Pages/HomePage.axaml.cs index 259c4c10..e3ff8ff9 100644 --- a/KitX Dashboard/Views/Pages/HomePage.axaml.cs +++ b/KitX Dashboard/Views/Pages/HomePage.axaml.cs @@ -22,18 +22,12 @@ public HomePage() InitHomePage(); } - - - private void InitHomePage() { this.FindControl("HomeNavigationView").SelectedItem = this.FindControl(SelectedViewName); } - - - private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); @@ -49,11 +43,6 @@ private static string SelectedViewName } } - - - - - private void HomeNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) diff --git a/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs b/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs index 2333cca0..cffdf392 100644 --- a/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs +++ b/KitX Dashboard/Views/Pages/SettingsPage.axaml.cs @@ -22,28 +22,17 @@ public SettingsPage() InitSettingsPage(); } - - - private void InitSettingsPage() { this.FindControl("SettingsNavigationView").SelectedItem = this.FindControl(SelectedViewName); } - - - private static void SaveChanges() { EventService.Invoke(nameof(EventService.ConfigSettingsChanged)); } - - - - - private void SettingsNavigationView_SelectionChanged( object? sender, NavigationViewSelectionChangedEventArgs e) From e993df07d69fb091b8ba757a140c7169ca5eedde Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Thu, 8 Feb 2024 04:57:41 +0800 Subject: [PATCH 04/27] =?UTF-8?q?=EF=BB=BF=F0=9F=92=BE=20Feat:=20Optimized?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KitX Dashboard Repair Tool/Program.cs | 32 ++++++++++++----- KitX Dashboard/App.axaml.cs | 4 +-- .../Converters/OperatingSystem2Enum.cs | 2 +- KitX Dashboard/Helper.cs | 2 +- KitX Dashboard/Instances.cs | 4 +-- KitX Dashboard/KitX.Dashboard.csproj | 4 +-- KitX Dashboard/Managers/AnouncementManager.cs | 2 +- KitX Dashboard/Managers/CacheManager.cs | 7 ++-- KitX Dashboard/Managers/ConfigManager.cs | 4 +-- KitX Dashboard/Managers/FileWatcherManager.cs | 2 +- KitX Dashboard/Managers/HotKeyManager.cs | 2 +- KitX Dashboard/Managers/PluginsManager.cs | 9 +++-- KitX Dashboard/Managers/StatisticsManager.cs | 8 ++--- KitX Dashboard/Managers/WebManager.cs | 2 +- KitX Dashboard/Models/Plugin.cs | 6 ++-- .../Network/DevicesDiscoveryServer.cs | 18 ++++------ KitX Dashboard/Network/DevicesNetwork.cs | 6 ++-- KitX Dashboard/Network/DevicesServer.cs | 2 +- KitX Dashboard/Network/NetworkHelper.cs | 8 ++--- KitX Dashboard/Network/PluginsNetwork.cs | 6 ++-- KitX Dashboard/Network/PluginsServer.cs | 2 +- KitX Dashboard/Program.cs | 1 + KitX Dashboard/Services/EventService.cs | 4 +-- KitX Dashboard/ViewLocator.cs | 14 ++++---- .../ViewModels/AnouncementsWindowViewModel.cs | 21 ++++++----- .../Pages/Controls/DeviceCardViewModel.cs | 4 +-- .../Pages/Controls/Home_CountViewModel.cs | 32 ++++++++--------- .../Pages/Controls/Home_RecentUseViewModel.cs | 2 +- .../Pages/Controls/PluginCardViewModel.cs | 4 +-- .../Controls/Settings_PerformenceViewModel.cs | 14 ++++---- .../Controls/Settings_PersonaliseViewModel.cs | 10 +++--- .../Controls/Settings_UpdateViewModel.cs | 22 ++++++------ .../ViewModels/Pages/RepoPageViewModel.cs | 36 +++++++++++-------- .../ViewModels/PluginDetailWindowViewModel.cs | 8 ++--- .../Views/AnouncementsWindow.axaml.cs | 2 ++ .../Views/Pages/Controls/DeviceCard.axaml.cs | 4 +-- .../Views/Pages/Controls/PluginCard.axaml.cs | 4 +-- .../Pages/Controls/Settings_About.axaml.cs | 27 ++++++++++---- KitX Dashboard/Views/Pages/HomePage.axaml.cs | 8 +++-- KitX Dashboard/Views/Pages/RepoPage.axaml.cs | 8 ++--- .../Views/Pages/SettingsPage.axaml.cs | 8 +++-- .../Views/PluginDetailWindow.axaml.cs | 25 ++++++------- 42 files changed, 201 insertions(+), 189 deletions(-) diff --git a/KitX Dashboard Repair Tool/Program.cs b/KitX Dashboard Repair Tool/Program.cs index a19ac410..bdcfa745 100644 --- a/KitX Dashboard Repair Tool/Program.cs +++ b/KitX Dashboard Repair Tool/Program.cs @@ -6,7 +6,8 @@ KitX Repair Tool (C) Crequency Environment: {Environment.Version} OS Version: {Environment.OSVersion} - """); + """ + ); }; var log_exception = (Exception e) => @@ -15,13 +16,18 @@ KitX Repair Tool (C) Crequency Console.WriteLine(e.StackTrace); }; -T? ask(string tip = "Input: ", Func? parse = null) +static T? ask(string tip = "Input: ", Func? parse = null) { Console.Write(tip); - string? input = Console.ReadLine(); + + var input = Console.ReadLine(); + if (input is null) return default(T); - if (parse is not null) return parse(input); - else throw new Exception(input); + + if (parse is not null) + return parse(input); + else + throw new Exception(input); }; var menu = () => @@ -29,11 +35,16 @@ KitX Repair Tool (C) Crequency Console.WriteLine( """ 1. (root) Linux wayland repair (add `LC_ALL=C` to environment variables) - """); - return ask("Your select: ", x => int.TryParse(x, out int y) ? y : -1); + """ + ); + + return ask("You selected: ", x => int.TryParse(x, out int y) ? y : -1); }; + + tip_copyright(); + switch (menu()) { case 1: @@ -44,7 +55,12 @@ KitX Repair Tool (C) Crequency } try { - File.AppendAllLines("/etc/environment", new string[] { "LC_ALL=C" }); + await File.AppendAllLinesAsync( + "/etc/environment", + [ + "LC_ALL=C" + ] + ); } catch (Exception e) { diff --git a/KitX Dashboard/App.axaml.cs b/KitX Dashboard/App.axaml.cs index b729238c..59d1c834 100644 --- a/KitX Dashboard/App.axaml.cs +++ b/KitX Dashboard/App.axaml.cs @@ -61,7 +61,7 @@ private void LoadLanguage() Resources.MergedDictionaries.Add( AvaloniaRuntimeXamlLoader.Load( File.ReadAllText(path) - ) as ResourceDictionary ?? new() + ) as ResourceDictionary ?? [] ); } catch (Exception ex) @@ -75,7 +75,7 @@ private void LoadLanguage() Resources.MergedDictionaries.Add( AvaloniaRuntimeXamlLoader.Load( File.ReadAllText(backup_langPath) - ) as ResourceDictionary ?? new() + ) as ResourceDictionary ?? [] ); ConfigManager.AppConfig.App.AppLanguage = backup_lang; } diff --git a/KitX Dashboard/Converters/OperatingSystem2Enum.cs b/KitX Dashboard/Converters/OperatingSystem2Enum.cs index dca0feef..504d860f 100644 --- a/KitX Dashboard/Converters/OperatingSystem2Enum.cs +++ b/KitX Dashboard/Converters/OperatingSystem2Enum.cs @@ -1,4 +1,4 @@ -using KitX.Web.Rules; +using KitX.Shared.Device; using System; namespace KitX.Dashboard.Converters; diff --git a/KitX Dashboard/Helper.cs b/KitX Dashboard/Helper.cs index d90cfd8e..d63f2be7 100644 --- a/KitX Dashboard/Helper.cs +++ b/KitX Dashboard/Helper.cs @@ -273,7 +273,7 @@ private static void ImportPlugin(string kxpPath) } else { - PluginsManager.ImportPlugin(new string[] { kxpPath }); + PluginsManager.ImportPlugin([kxpPath]); } } catch (Exception ex) diff --git a/KitX Dashboard/Instances.cs b/KitX Dashboard/Instances.cs index 9b5221c2..50a3bd61 100644 --- a/KitX Dashboard/Instances.cs +++ b/KitX Dashboard/Instances.cs @@ -13,9 +13,9 @@ internal class Instances internal static FileWatcherManager? FileWatcherManager; - internal static ObservableCollection PluginCards = new(); + internal static ObservableCollection PluginCards = []; - internal static ObservableCollection DeviceCards = new(); + internal static ObservableCollection DeviceCards = []; internal static LiteDatabase? ActivitiesDataBase; diff --git a/KitX Dashboard/KitX.Dashboard.csproj b/KitX Dashboard/KitX.Dashboard.csproj index ce783c44..3225e3f1 100644 --- a/KitX Dashboard/KitX.Dashboard.csproj +++ b/KitX Dashboard/KitX.Dashboard.csproj @@ -92,10 +92,10 @@ - - + + diff --git a/KitX Dashboard/Managers/AnouncementManager.cs b/KitX Dashboard/Managers/AnouncementManager.cs index b9322797..4469dba2 100644 --- a/KitX Dashboard/Managers/AnouncementManager.cs +++ b/KitX Dashboard/Managers/AnouncementManager.cs @@ -42,7 +42,7 @@ public static async Task CheckNewAnnouncements() readed = JsonSerializer.Deserialize>( await FileHelper.ReadAllAsync(confPath) ); - else readed = new(); + else readed = []; // 未阅读列表 var unreads = new List(); diff --git a/KitX Dashboard/Managers/CacheManager.cs b/KitX Dashboard/Managers/CacheManager.cs index 03d58b2c..b0e8dba9 100644 --- a/KitX Dashboard/Managers/CacheManager.cs +++ b/KitX Dashboard/Managers/CacheManager.cs @@ -12,8 +12,8 @@ internal class CacheManager { internal CacheManager() { - FilesCache = new(); - ReceivingFilesCache = new(); + FilesCache = []; + ReceivingFilesCache = []; } private static async Task GetMD5(byte[] bytes, bool trans = false) @@ -64,8 +64,7 @@ await Task.Run(() => if (ReceivingFilesCache is null || id is null) return null; - if (!ReceivingFilesCache.ContainsKey(id)) - ReceivingFilesCache.Add(id, bin); + _ = ReceivingFilesCache.TryAdd(id, bin); GC.Collect(); diff --git a/KitX Dashboard/Managers/ConfigManager.cs b/KitX Dashboard/Managers/ConfigManager.cs index 85281ab5..d0147b72 100644 --- a/KitX Dashboard/Managers/ConfigManager.cs +++ b/KitX Dashboard/Managers/ConfigManager.cs @@ -184,12 +184,12 @@ await TasksManager.RunTaskAsync(async () => { PluginsManager.Plugins = JsonSerializer.Deserialize>( await FileHelper.ReadAllAsync(GlobalInfo.PluginsListConfigFilePath) - ) ?? new(); + ) ?? []; } catch (Exception ex) { Log.Error(ex, $"In {location}: {ex.Message}"); - PluginsManager.Plugins = new(); + PluginsManager.Plugins = []; } }, location); } diff --git a/KitX Dashboard/Managers/FileWatcherManager.cs b/KitX Dashboard/Managers/FileWatcherManager.cs index c18a3e14..3d259659 100644 --- a/KitX Dashboard/Managers/FileWatcherManager.cs +++ b/KitX Dashboard/Managers/FileWatcherManager.cs @@ -7,7 +7,7 @@ namespace KitX.Dashboard.Managers; internal class FileWatcherManager { - private readonly Dictionary Watchers = new(); + private readonly Dictionary Watchers = []; public FileWatcherManager RegisterWatcher( string name, diff --git a/KitX Dashboard/Managers/HotKeyManager.cs b/KitX Dashboard/Managers/HotKeyManager.cs index 86184efc..8afca532 100644 --- a/KitX Dashboard/Managers/HotKeyManager.cs +++ b/KitX Dashboard/Managers/HotKeyManager.cs @@ -18,7 +18,7 @@ public HotKeyManager() { keyPressed = new(); - hotKeyHandlers = new(); + hotKeyHandlers = []; } public HotKeyManager Hook() diff --git a/KitX Dashboard/Managers/PluginsManager.cs b/KitX Dashboard/Managers/PluginsManager.cs index c378232f..9e47fd38 100644 --- a/KitX Dashboard/Managers/PluginsManager.cs +++ b/KitX Dashboard/Managers/PluginsManager.cs @@ -2,10 +2,9 @@ using KitX.Dashboard.Data; using KitX.Dashboard.Models; using KitX.Dashboard.Services; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; -using KitX.Formats.KXP; +using KitX.FileFormats.ExtensionsPackage; +using KitX.Shared.Loader; +using KitX.Shared.Plugin; using Serilog; using System; using System.Collections.Generic; @@ -17,7 +16,7 @@ namespace KitX.Dashboard.Managers; internal class PluginsManager { - internal static List Plugins = new(); + internal static List Plugins = []; internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false) { diff --git a/KitX Dashboard/Managers/StatisticsManager.cs b/KitX Dashboard/Managers/StatisticsManager.cs index f9753560..d956a66f 100644 --- a/KitX Dashboard/Managers/StatisticsManager.cs +++ b/KitX Dashboard/Managers/StatisticsManager.cs @@ -13,7 +13,7 @@ namespace KitX.Dashboard.Managers; internal class StatisticsManager { - internal static Dictionary? UseStatistics = new(); + internal static Dictionary? UseStatistics = []; internal static void Start() { @@ -106,15 +106,11 @@ internal static void BeginRecord() if (UseStatistics is null) return; - if (UseStatistics.ContainsKey(today)) + if (!UseStatistics.TryAdd(today, 0.01)) { UseStatistics[today] += 0.01; UseStatistics[today] = Math.Round(UseStatistics[today], 2); } - else - { - UseStatistics.Add(today, 0.01); - } EventService.Invoke(nameof(EventService.UseStatisticsChanged)); } diff --git a/KitX Dashboard/Managers/WebManager.cs b/KitX Dashboard/Managers/WebManager.cs index 63b646d0..d6b63c97 100644 --- a/KitX Dashboard/Managers/WebManager.cs +++ b/KitX Dashboard/Managers/WebManager.cs @@ -15,7 +15,7 @@ public class WebManager : IDisposable public WebManager() { - NetworkInterfaceRegistered = new(); + NetworkInterfaceRegistered = []; } public async Task Start diff --git a/KitX Dashboard/Models/Plugin.cs b/KitX Dashboard/Models/Plugin.cs index 1f666f71..57c98786 100644 --- a/KitX Dashboard/Models/Plugin.cs +++ b/KitX Dashboard/Models/Plugin.cs @@ -1,6 +1,6 @@ -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; +using KitX.Shared.Loader; +using KitX.Shared.Plugin; using System.Collections.Generic; using System.Text.Json.Serialization; diff --git a/KitX Dashboard/Network/DevicesDiscoveryServer.cs b/KitX Dashboard/Network/DevicesDiscoveryServer.cs index fbc6d06a..b1dc4169 100644 --- a/KitX Dashboard/Network/DevicesDiscoveryServer.cs +++ b/KitX Dashboard/Network/DevicesDiscoveryServer.cs @@ -3,9 +3,7 @@ using KitX.Dashboard.Interfaces.Network; using KitX.Dashboard.Managers; using KitX.Dashboard.Names; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; using Serilog; using System; using System.Collections.Generic; @@ -31,7 +29,7 @@ internal class DevicesDiscoveryServer : IKitXServer private static int LastTimeToOSVersionUpdated = 0; - private static readonly List SupportedNetworkInterfacesIndexes = new(); + private static readonly List SupportedNetworkInterfacesIndexes = []; private static bool disposed = false; @@ -117,8 +115,9 @@ private static void UpdateDefaultDeviceInfo() { DefaultDeviceInfo.IsMainDevice = GlobalInfo.IsMainMachine; DefaultDeviceInfo.SendTime = DateTime.UtcNow; - DefaultDeviceInfo.Device.IPv4 = NetworkHelper.GetInterNetworkIPv4(); - DefaultDeviceInfo.Device.IPv6 = NetworkHelper.GetInterNetworkIPv6(); + DefaultDeviceInfo.Device + .ResetIPv4(NetworkHelper.GetInterNetworkIPv4()) + .ResetIPv6(NetworkHelper.GetInterNetworkIPv6()); DefaultDeviceInfo.PluginServerPort = GlobalInfo.PluginServerPort; DefaultDeviceInfo.PluginsCount = Instances.PluginCards.Count; DefaultDeviceInfo.IsMainDevice = GlobalInfo.IsMainMachine; @@ -128,7 +127,7 @@ private static void UpdateDefaultDeviceInfo() if (LastTimeToOSVersionUpdated > ConfigManager.AppConfig.IO.OperatingSystemVersionUpdateInterval) { LastTimeToOSVersionUpdated = 0; - DefaultDeviceInfo.DeviceOSVersion = NetworkHelper.TryGetOSVersionString(); + DefaultDeviceInfo.DeviceOSVersion = NetworkHelper.TryGetOSVersionString() ?? ""; } ++DeviceInfoUpdatedTimes; @@ -328,10 +327,7 @@ await TasksManager.RunTaskAsync(() => try { FindSupportNetworkInterfaces( - new() - { - UdpSender, UdpReceiver - }, + [UdpSender, UdpReceiver], IPAddress.Parse(ConfigManager.AppConfig.Web.UDPBroadcastAddress) ); // 寻找所有支持的网络适配器 } diff --git a/KitX Dashboard/Network/DevicesNetwork.cs b/KitX Dashboard/Network/DevicesNetwork.cs index 9b4a5dd3..abb7bc92 100644 --- a/KitX Dashboard/Network/DevicesNetwork.cs +++ b/KitX Dashboard/Network/DevicesNetwork.cs @@ -3,9 +3,7 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Services; using KitX.Dashboard.Views.Pages.Controls; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; using Serilog; using System; using System.Collections.Generic; @@ -238,7 +236,7 @@ internal static void Watch4MainDevice() new Thread(() => { - receivedDeviceInfo4Watch = new(); + receivedDeviceInfo4Watch = []; var checkedTime = 0; var hadMainDevice = false; diff --git a/KitX Dashboard/Network/DevicesServer.cs b/KitX Dashboard/Network/DevicesServer.cs index c9d665dd..86eb4b33 100644 --- a/KitX Dashboard/Network/DevicesServer.cs +++ b/KitX Dashboard/Network/DevicesServer.cs @@ -21,7 +21,7 @@ internal class DevicesServer : IKitXServer private static bool disposed = false; - private static readonly Dictionary clients = new(); + private static readonly Dictionary clients = []; private static Action? onReceive = null; diff --git a/KitX Dashboard/Network/NetworkHelper.cs b/KitX Dashboard/Network/NetworkHelper.cs index 45e854d2..e0e02659 100644 --- a/KitX Dashboard/Network/NetworkHelper.cs +++ b/KitX Dashboard/Network/NetworkHelper.cs @@ -3,9 +3,7 @@ using KitX.Dashboard.Converters; using KitX.Dashboard.Data; using KitX.Dashboard.Managers; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; using Serilog; using System; using System.IO; @@ -213,14 +211,14 @@ from nic in NetworkInterface.GetAllNetworkInterfaces() Device = new() { DeviceName = Environment.MachineName, - MacAddress = TryGetDeviceMacAddress(), + MacAddress = TryGetDeviceMacAddress() ?? "", IPv4 = GetInterNetworkIPv4(), IPv6 = GetInterNetworkIPv6(), }, IsMainDevice = GlobalInfo.IsMainMachine, SendTime = DateTime.UtcNow, DeviceOSType = OperatingSystem2Enum.GetOSType(), - DeviceOSVersion = TryGetOSVersionString(), + DeviceOSVersion = TryGetOSVersionString() ?? "", PluginServerPort = GlobalInfo.PluginServerPort, DevicesServerPort = GlobalInfo.DevicesServerPort, DeviceServerBuildTime = new(), diff --git a/KitX Dashboard/Network/PluginsNetwork.cs b/KitX Dashboard/Network/PluginsNetwork.cs index b9057107..ab939b8d 100644 --- a/KitX Dashboard/Network/PluginsNetwork.cs +++ b/KitX Dashboard/Network/PluginsNetwork.cs @@ -4,9 +4,7 @@ using KitX.Dashboard.Models; using KitX.Dashboard.Services; using KitX.Dashboard.Views.Pages.Controls; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Plugin; using Serilog; using System; using System.Collections.Generic; @@ -31,7 +29,7 @@ internal static void Execute(string msg, IPEndPoint endPoint) var pluginStruct = JsonSerializer.Deserialize(json); - pluginStruct.Tags ??= new(); + pluginStruct.Tags ??= []; // 标注实例注册 ID pluginStruct.Tags.Add("Authorized_ID", diff --git a/KitX Dashboard/Network/PluginsServer.cs b/KitX Dashboard/Network/PluginsServer.cs index f53a57b5..74817482 100644 --- a/KitX Dashboard/Network/PluginsServer.cs +++ b/KitX Dashboard/Network/PluginsServer.cs @@ -21,7 +21,7 @@ internal class PluginsServer : IKitXServer private static bool disposed = false; - private static readonly Dictionary clients = new(); + private static readonly Dictionary clients = []; private static Action? onReceive = null; diff --git a/KitX Dashboard/Program.cs b/KitX Dashboard/Program.cs index 38a8d072..25835711 100644 --- a/KitX Dashboard/Program.cs +++ b/KitX Dashboard/Program.cs @@ -1,4 +1,5 @@ using Avalonia; +using Avalonia.Controls; using Avalonia.ReactiveUI; using Common.BasicHelper.Utils.Extensions; using KitX.Dashboard.Managers; diff --git a/KitX Dashboard/Services/EventService.cs b/KitX Dashboard/Services/EventService.cs index 88346a97..9f15dc42 100644 --- a/KitX Dashboard/Services/EventService.cs +++ b/KitX Dashboard/Services/EventService.cs @@ -1,6 +1,4 @@ -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; namespace KitX.Dashboard.Services; diff --git a/KitX Dashboard/ViewLocator.cs b/KitX Dashboard/ViewLocator.cs index a357355a..614f38c7 100644 --- a/KitX Dashboard/ViewLocator.cs +++ b/KitX Dashboard/ViewLocator.cs @@ -7,12 +7,14 @@ namespace KitX.Dashboard; public class ViewLocator : IDataTemplate { - public Control Build(object data) - { - var name = data.GetType().FullName!.Replace("ViewModel", "View"); + public Control? Build(object? data) + { + if (data is null) return null; + + var name = data.GetType().FullName!.Replace("ViewModel", "View"); var type = Type.GetType(name); - if (type != null) + if (type is not null) { return (Control)Activator.CreateInstance(type)!; } @@ -20,8 +22,8 @@ public Control Build(object data) return new TextBlock { Text = "Not Found: " + name }; } - public bool Match(object data) + public bool Match(object? data) { return data is ViewModelBase; } -} \ No newline at end of file +} diff --git a/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs b/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs index 2ed90dbe..68172aca 100644 --- a/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs @@ -1,5 +1,4 @@ -using Avalonia.Collections; -using Common.BasicHelper.Utils.Extensions; +using Common.BasicHelper.Utils.Extensions; using FluentAvalonia.UI.Controls; using KitX.Dashboard.Data; using KitX.Dashboard.Managers; @@ -24,13 +23,19 @@ public AnouncementsWindowViewModel() InitCommands(); } + public static JsonSerializerOptions JsonSerializerOptions = new() + { + WriteIndented = true, + IncludeFields = true, + }; + private void InitCommands() { ConfirmReceivedCommand = ReactiveCommand.Create(async () => { if (SelectedMenuItem is null || Readed is null) return; - var key = SelectedMenuItem.Content.ToString(); + var key = SelectedMenuItem.Content!.ToString(); if (key is null) return; @@ -39,15 +44,9 @@ private void InitCommands() var ConfigFilePath = GlobalInfo.AnnouncementsJsonPath.GetFullPath(); - var options = new JsonSerializerOptions() - { - WriteIndented = true, - IncludeFields = true, - }; - await File.WriteAllTextAsync( ConfigFilePath, - JsonSerializer.Serialize(Readed, options) + JsonSerializer.Serialize(Readed, JsonSerializerOptions) ); var finded = false; @@ -157,7 +156,7 @@ internal string Markdown } } - private Dictionary sources = new(); + private Dictionary sources = []; internal Dictionary Sources { diff --git a/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs index 34fe1ba1..f8b212e2 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/DeviceCardViewModel.cs @@ -1,8 +1,6 @@ using Avalonia; using Common.BasicHelper.Utils.Extensions; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; using Material.Icons; using System.ComponentModel; diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Home_CountViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Home_CountViewModel.cs index 0615c753..98423b96 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Home_CountViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Home_CountViewModel.cs @@ -14,30 +14,30 @@ internal class Home_CountViewModel : ViewModelBase, INotifyPropertyChanged private double noCount_TipHeight = 200; - private List use_xAxes = new() - { + private List use_xAxes = + [ new Axis { Labeler = Labelers.Default } - }; + ]; - private List use_yAxes = new() - { + private List use_yAxes = + [ new Axis { Labeler = (value) => $"{value} h" } - }; + ]; private ISeries[] useSeries = - { + [ new LineSeries { Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, Fill = null } - }; + ]; public Home_CountViewModel() { @@ -57,25 +57,23 @@ internal void RecoveryUseCount() { var use = StatisticsManager.UseStatistics; - Use_XAxes = new() - { + Use_XAxes = + [ new Axis { Labels = use?.Keys.ToList() } - }; + ]; - Use_Series = new ISeries[] - { + Use_Series = + [ new LineSeries { Values = use?.Values.ToArray(), Fill = null, - TooltipLabelFormatter = chartpoint => - $"{use?.Keys.ToArray()[(int)chartpoint.SecondaryValue]}: " + - $"{chartpoint.PrimaryValue} h" + XToolTipLabelFormatter = x => $"{use?.Keys.ToArray()[(int)x.Coordinate.SecondaryValue]}: {x.Coordinate.PrimaryValue} h" } - }; + ]; } internal double NoCount_TipHeight diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs index 8328e33e..abbdf6b6 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Home_RecentUseViewModel.cs @@ -8,5 +8,5 @@ internal class Home_RecentUseViewModel : ViewModelBase public double NoRecent_TipHeight { get; set; } = 200; - public ObservableCollection RecentPluginCards { get; } = new(); + public ObservableCollection RecentPluginCards { get; } = []; } diff --git a/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs index cf42eb48..76057dfe 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/PluginCardViewModel.cs @@ -3,9 +3,7 @@ using KitX.Dashboard.Data; using KitX.Dashboard.Managers; using KitX.Dashboard.Views; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Plugin; using ReactiveUI; using Serilog; using System; diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs index 08873d48..618529d3 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PerformenceViewModel.cs @@ -242,16 +242,14 @@ internal static string AcceptedNetworkInterfacesNames { var userInput = value.Split(';'); - ConfigManager.AppConfig.Web.AcceptedNetworkInterfaces = userInput.ToList(); + ConfigManager.AppConfig.Web.AcceptedNetworkInterfaces = [.. userInput]; } } } - internal static ObservableCollection? AvailableNetworkInterfaces - => Instances.WebManager?.NetworkInterfaceRegistered; + internal static ObservableCollection? AvailableNetworkInterfaces => Instances.WebManager?.NetworkInterfaceRegistered; - internal static ObservableCollection? SelectedNetworkInterfaces { get; } - = new(); + internal static ObservableCollection? SelectedNetworkInterfaces { get; } = []; internal static int DevicesListRefreshDelay { @@ -366,8 +364,8 @@ private static string GetLogLevelDisplayText(string key) => FetchStringFromResou prefix: "Text_Log_" ) ?? string.Empty; - internal static List SupportedLogLevels { get; } = new() - { + internal static List SupportedLogLevels { get; } = + [ new() { LogEventLevel = Serilog.Events.LogEventLevel.Verbose, @@ -404,7 +402,7 @@ private static string GetLogLevelDisplayText(string key) => FetchStringFromResou LogLevelName = "Fatal", LogLevelDisplayName = GetLogLevelDisplayText("Fatal") }, - }; + ]; private SupportedLogLevel? _currentLogLevel = SupportedLogLevels.Find( x => x.LogEventLevel == ConfigManager.AppConfig.Log.LogLevel diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PersonaliseViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PersonaliseViewModel.cs index 028c1466..b9333900 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Settings_PersonaliseViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Settings_PersonaliseViewModel.cs @@ -132,8 +132,8 @@ private static string GetThemeDisplayText(string key) => FetchStringFromResource prefix: "Text_Settings_Personalise_Theme_" ) ?? string.Empty; - internal static List SupportedThemes { get; } = new() - { + internal static List SupportedThemes { get; } = + [ new() { ThemeName = FluentAvaloniaTheme.LightModeString, @@ -154,7 +154,7 @@ private static string GetThemeDisplayText(string key) => FetchStringFromResource ThemeName = "Follow", ThemeDisplayName = GetThemeDisplayText("Follow"), } - }; + ]; private SupportedTheme? _currentAppTheme = SupportedThemes.Find( x => x.ThemeName.Equals(ConfigManager.AppConfig.App.Theme) @@ -186,7 +186,7 @@ internal SupportedTheme? CurrentAppTheme } } - internal List SupportedLanguages { get; } = new(); + internal List SupportedLanguages { get; } = []; internal static void LoadLanguage() { @@ -203,7 +203,7 @@ internal static void LoadLanguage() Application.Current.Resources.MergedDictionaries.Add( AvaloniaRuntimeXamlLoader.Load( File.ReadAllText($"{GlobalInfo.LanguageFilePath}/{lang}.axaml") - ) as ResourceDictionary ?? new() + ) as ResourceDictionary ?? [] ); } catch (Exception ex) diff --git a/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs b/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs index d18e5913..0d679ddd 100644 --- a/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/Controls/Settings_UpdateViewModel.cs @@ -8,9 +8,7 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Network; using KitX.Dashboard.Services; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; using MsBox.Avalonia; using MsBox.Avalonia.Enums; using ReactiveUI; @@ -81,7 +79,7 @@ internal int CanUpdateCount internal static int ComponentsCount { get => Components.Count; } - internal static ObservableCollection Components { get; } = new(); + internal static ObservableCollection Components { get; } = []; private string? tip = string.Empty; @@ -225,6 +223,13 @@ private void CalculateComponentsHash(Checker checker) _calculateFinished = true; } + private static readonly JsonSerializerOptions JsonSerializerOptions = new() + { + WriteIndented = true, + IncludeFields = true, + PropertyNamingPolicy = new UpdateHashNamePolicy(), + }; + private static async Task?> GetLatestComponentsAsync ( HttpClient client @@ -249,17 +254,10 @@ HttpClient client var json = await client.GetStringAsync(link); - var option = new JsonSerializerOptions() - { - WriteIndented = true, - IncludeFields = true, - PropertyNamingPolicy = new UpdateHashNamePolicy(), - }; - var latestComponents = JsonSerializer .Deserialize>( json, - option + JsonSerializerOptions ); return latestComponents; diff --git a/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs b/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs index 4a69a14b..fc320a5b 100644 --- a/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs +++ b/KitX Dashboard/ViewModels/Pages/RepoPageViewModel.cs @@ -2,16 +2,17 @@ using KitX.Dashboard.Managers; using KitX.Dashboard.Models; using KitX.Dashboard.Services; +using KitX.Dashboard.Views.Pages; using KitX.Dashboard.Views.Pages.Controls; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Loader; +using KitX.Shared.Plugin; using ReactiveUI; using Serilog; using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; +using System.Linq; using System.Reactive; using System.Text.Json; using System.Threading; @@ -20,6 +21,8 @@ namespace KitX.Dashboard.ViewModels.Pages; internal class RepoPageViewModel : ViewModelBase, INotifyPropertyChanged { + private RepoPage? CurrentPage { get; set; } + public new event PropertyChangedEventHandler? PropertyChanged; public RepoPageViewModel() @@ -41,18 +44,15 @@ private void InitCommands() { if (win is not Window window) return; - var ofd = new OpenFileDialog() - { - AllowMultiple = true, - }; + var topLevel = TopLevel.GetTopLevel(CurrentPage!); - ofd.Filters?.Add(new() - { - Name = "KitX Extensions Packages", - Extensions = { "kxp" } - }); + if (topLevel is null) return; - var files = await ofd.ShowAsync(window); + var files = (await topLevel.StorageProvider.OpenFilePickerAsync(new() + { + Title = "Open KitX Extensions Package File", + AllowMultiple = true, + })).Select(x => x.Path.LocalPath).ToList().ToArray(); if (files is not null && files?.Length > 0) { @@ -95,7 +95,7 @@ private void InitCommands() Path.GetFullPath($"{item.InstallPath}/LoaderInfo.json") ) ), - InstalledDevices = new() + InstalledDevices = [] }; PluginBars.Add(new(plugin, ref pluginBars)); @@ -109,6 +109,12 @@ private void InitCommands() }); } + internal RepoPageViewModel SetControl(RepoPage control) + { + CurrentPage = control; + return this; + } + private void InitEvents() { EventService.ConfigSettingsChanged += () => @@ -171,7 +177,7 @@ internal bool ImportButtonVisibility } } - private ObservableCollection pluginBars = new(); + private ObservableCollection pluginBars = []; internal ObservableCollection PluginBars { diff --git a/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs b/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs index ec8c4dae..94d06f09 100644 --- a/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/PluginDetailWindowViewModel.cs @@ -5,9 +5,7 @@ using Avalonia.Styling; using KitX.Dashboard.Managers; using KitX.Dashboard.Services; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Plugin; using ReactiveUI; using Serilog; using System; @@ -141,9 +139,9 @@ internal string? TotalDescriptionInMarkdown _ => Color.Parse(ConfigManager.AppConfig.App.ThemeColor), }; - private readonly ObservableCollection functions = new(); + private readonly ObservableCollection functions = []; - private readonly ObservableCollection tags = new(); + private readonly ObservableCollection tags = []; internal Bitmap IconDisplay { diff --git a/KitX Dashboard/Views/AnouncementsWindow.axaml.cs b/KitX Dashboard/Views/AnouncementsWindow.axaml.cs index 8228e734..e7f8b346 100644 --- a/KitX Dashboard/Views/AnouncementsWindow.axaml.cs +++ b/KitX Dashboard/Views/AnouncementsWindow.axaml.cs @@ -57,6 +57,8 @@ public AnouncementsWindow() private void SuggestResolutionAndLocation() { + if (Screens.Primary is null) return; + if (ConfigManager.AppConfig.Windows.AnnouncementWindow.Window_Width == 1280 && ConfigManager.AppConfig.Windows.AnnouncementWindow.Window_Height == 720) { diff --git a/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs b/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs index 8dcfabfc..39e86db0 100644 --- a/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs +++ b/KitX Dashboard/Views/Pages/Controls/DeviceCard.axaml.cs @@ -1,8 +1,6 @@ using Avalonia.Controls; using KitX.Dashboard.ViewModels.Pages.Controls; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Device; namespace KitX.Dashboard.Views.Pages.Controls; diff --git a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs b/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs index a90250c0..da361d78 100644 --- a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs +++ b/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs @@ -1,8 +1,6 @@ using Avalonia.Controls; using KitX.Dashboard.ViewModels.Pages.Controls; -using KitX.Web.Rules; -using KitX.Web.Rules.Plugin; -using KitX.Web.Rules.Device; +using KitX.Shared.Plugin; namespace KitX.Dashboard.Views.Pages.Controls; diff --git a/KitX Dashboard/Views/Pages/Controls/Settings_About.axaml.cs b/KitX Dashboard/Views/Pages/Controls/Settings_About.axaml.cs index 5f2a9ba6..73d27379 100644 --- a/KitX Dashboard/Views/Pages/Controls/Settings_About.axaml.cs +++ b/KitX Dashboard/Views/Pages/Controls/Settings_About.axaml.cs @@ -16,12 +16,21 @@ public Settings_About() DataContext = viewModel; } - private readonly List keyqueue = new(); - - private readonly List rightkey = new() - { - Key.W, Key.W, Key.S, Key.S, Key.A, Key.D, Key.A, Key.D, Key.B, Key.A - }; + private readonly List keyqueue = []; + + private readonly List rightkey = + [ + Key.W, + Key.W, + Key.S, + Key.S, + Key.A, + Key.D, + Key.A, + Key.D, + Key.B, + Key.A + ]; private void AppNameButtonKeyDown(object sender, KeyEventArgs e) { @@ -52,6 +61,8 @@ private void WQY_LeftEnter(object sender, PointerEventArgs e) { var Btn_WQY = this.FindControl + + + + + + + + + + + + FuncName + - - - diff --git a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs b/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs deleted file mode 100644 index da361d78..00000000 --- a/KitX Dashboard/Views/Pages/Controls/PluginCard.axaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Avalonia.Controls; -using KitX.Dashboard.ViewModels.Pages.Controls; -using KitX.Shared.Plugin; - -namespace KitX.Dashboard.Views.Pages.Controls; - -public partial class PluginCard : UserControl -{ - private readonly PluginCardViewModel viewModel = new(); - - internal string? IPEndPoint { get; set; } - - public PluginCard() - { - InitializeComponent(); - - DataContext = viewModel; - } - - public PluginCard(PluginInfo ps) - { - InitializeComponent(); - - viewModel.pluginStruct = ps; - - DataContext = viewModel; - } -} diff --git a/KitX Dashboard/Views/Pages/Controls/PluginLaunchCard.axaml b/KitX Dashboard/Views/Pages/Controls/PluginLaunchCard.axaml index 21c91b8f..29a90749 100644 --- a/KitX Dashboard/Views/Pages/Controls/PluginLaunchCard.axaml +++ b/KitX Dashboard/Views/Pages/Controls/PluginLaunchCard.axaml @@ -1,15 +1,15 @@  - - - + - + - + + FontSize="20" + FontWeight="ExtraBold" + Text="{Binding DisplayName}" + ToolTip.Tip="{Binding DisplayName}"/> + FontSize="14" + FontWeight="Light" + Text="{Binding Version}"/> @@ -66,14 +64,14 @@ - - - - + + + + + diff --git a/KitX Dashboard/Views/PluginDetailWindow.axaml b/KitX Dashboard/Views/PluginDetailWindow.axaml index f68d32a1..9c66d08a 100644 --- a/KitX Dashboard/Views/PluginDetailWindow.axaml +++ b/KitX Dashboard/Views/PluginDetailWindow.axaml @@ -1,12 +1,14 @@  - + + @@ -30,7 +33,7 @@ - + @@ -42,26 +45,26 @@ Height="80" VerticalAlignment="Top" DockPanel.Dock="Left" - Source="{Binding IconDisplay}" + Source="{Binding PluginDetail.IconInBase64, Converter={StaticResource Base64ToIconConverter}}" Stretch="UniformToFill"/> - + + Text="{Binding PluginDetail.DisplayName, Converter={StaticResource PluginMultiLanguagePropertyConverter}}"/> @@ -80,18 +83,18 @@ + NavigateUri="{Binding PluginDetail.AuthorLink}" + ToolTip.Tip="{Binding PluginDetail.AuthorLink}"/> + Content="{Binding PluginDetail.PublisherName}" + NavigateUri="{Binding PluginDetail.PublisherLink}" + ToolTip.Tip="{Binding PluginDetail.PublisherLink}"/> @@ -103,7 +106,7 @@ - + @@ -118,7 +121,7 @@ TintOpacity="1"/> - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs index d0b6a98e..28301a21 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs @@ -42,13 +42,6 @@ public PluginsLaunchWindow() } } - LostFocus += (_, _) => - { - Hide(); - - OnHideAction?.Invoke(); - }; - RegisterGlobalHotKey(); } @@ -97,8 +90,32 @@ public PluginsLaunchWindow OnHide(Action onHideAction) private void PluginsLaunchWindow_KeyDown(object? sender, KeyEventArgs e) { - if (e.Key == Key.Escape) + switch (e.Key) + { + case Key.Escape: + Hide(); + OnHideAction?.Invoke(); + break; + case Key.Right: + viewModel.SelectRightOne(); + break; + case Key.Left: + viewModel.SelectLeftOne(); + break; + case Key.Enter: + viewModel.SelectPluginInfo(); + break; + } + } + + protected override void OnClosing(WindowClosingEventArgs e) + { + base.OnClosing(e); + + if (!ConstantTable.Exiting) { + e.Cancel = true; + Hide(); OnHideAction?.Invoke(); From 79e80f74f42fccadd897bfa8fa996db8b0c533f3 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Thu, 22 Feb 2024 06:21:25 +0800 Subject: [PATCH 22/27] =?UTF-8?q?=F0=9F=92=BE=20Feat(Dashboard):=20Check?= =?UTF-8?q?=20if=20`PluginInfo.Tags`=20is=20null.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs b/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs index 6541f7b2..c5d9e33b 100644 --- a/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs +++ b/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs @@ -137,6 +137,8 @@ public PluginConnector Run() ArgumentNullException.ThrowIfNull(PluginInfo, nameof(PluginInfo)); + ArgumentNullException.ThrowIfNull(PluginInfo.Value.Tags, nameof(PluginInfo.Value.Tags)); + PluginInfo.Value.Tags.Add(nameof(ConnectionId), ConnectionId ?? string.Empty); PluginInfo.Value.Tags.Add( nameof(PluginTagsNames.JoinTime), From 1fc3e5d11a3a4a5fafdcc2b2ebe64a255397abe4 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Thu, 22 Feb 2024 06:27:15 +0800 Subject: [PATCH 23/27] =?UTF-8?q?=F0=9F=92=BE=20Feat(Dashboard):=20Clear?= =?UTF-8?q?=20collection=20on=20exiting.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KitX Dashboard/ViewModels/AppViewModel.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/KitX Dashboard/ViewModels/AppViewModel.cs b/KitX Dashboard/ViewModels/AppViewModel.cs index 29384687..b659e315 100644 --- a/KitX Dashboard/ViewModels/AppViewModel.cs +++ b/KitX Dashboard/ViewModels/AppViewModel.cs @@ -64,6 +64,10 @@ public override void InitCommands() ExitCommand = ReactiveCommand.Create(() => { + ViewInstances.DeviceCards.Clear(); + + ViewInstances.PluginInfos.Clear(); + ConstantTable.Exiting = true; EventService.Invoke(nameof(EventService.OnExiting)); From 9d2773b8c237aba826995a59f8059c3b2a3056db Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Thu, 22 Feb 2024 06:28:34 +0800 Subject: [PATCH 24/27] =?UTF-8?q?=F0=9F=92=BE=20Feat(Dashboard):=20Selecta?= =?UTF-8?q?ble=20plugin=20buttons=20in=20LaunchWindow=20and=20experimental?= =?UTF-8?q?=20flags=20introduced.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KitX Dashboard/ExperimentalFlags.cs | 6 ++ .../PluginsLaunchWindowViewModel.cs | 87 ++++++++++++++++++- .../Views/PluginsLaunchWindow.axaml | 27 ++++-- .../Views/PluginsLaunchWindow.axaml.cs | 41 ++++++++- 4 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 KitX Dashboard/ExperimentalFlags.cs diff --git a/KitX Dashboard/ExperimentalFlags.cs b/KitX Dashboard/ExperimentalFlags.cs new file mode 100644 index 00000000..f18fd6a8 --- /dev/null +++ b/KitX Dashboard/ExperimentalFlags.cs @@ -0,0 +1,6 @@ +namespace KitX.Dashboard; + +public static class ExperimentalFlags +{ + public static bool EnablePluginLaunchWindowWidthSnap { get; set; } = false; +} diff --git a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs index a0ba74eb..8cc13775 100644 --- a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs @@ -2,6 +2,9 @@ using KitX.Shared.Plugin; using ReactiveUI; using System.Collections.ObjectModel; +using Avalonia; +using System; +using Avalonia.Controls; namespace KitX.Dashboard.ViewModels; @@ -87,28 +90,104 @@ public Parameter? SelectedParameter public string? SearchingText { get; set; } + private Vector scrollViewerOffset = new(0, 0); + + public Vector ScrollViewerOffset + { + get => scrollViewerOffset; + set => this.RaiseAndSetIfChanged(ref scrollViewerOffset, value); + } + + private void BringSelectedButtonIntoView(int perLineButtonsCount, object? scrollvierwer) + { + if (scrollvierwer is not ScrollViewer viewer) return; + + var viewerHeight = (int)Math.Floor(viewer?.DesiredSize.Height ?? 240); + + var viewerOffsetY = (int)Math.Floor(viewer?.Offset.Y ?? 0); + + var lineIndex = SelectedPluginIndex / perLineButtonsCount; + + var up = lineIndex * 80; + + var down = up + 80; + + var targetY = lineIndex * 80; + + var condition = (up >= viewerOffsetY && down <= viewerOffsetY + viewerHeight); + + if (condition == false) + { + ScrollViewerOffset = new(0, targetY); + } + } + private static bool SelectedPluginIndexInRange(int index) => index >= 0 && index < PluginInfos.Count; - internal void SelectRightOne() + internal void SelectRightOne(double WindowWidth, object? scrollviewer) { + var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); + if (SelectedPluginIndexInRange(SelectedPluginIndex + 1)) + { SelectedPluginIndex++; + + BringSelectedButtonIntoView(perLineCount, scrollviewer); + } } - internal void SelectLeftOne() + internal void SelectLeftOne(double WindowWidth, object? scrollviewer) { + var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); + if (SelectedPluginIndexInRange(selectedPluginIndex - 1)) + { SelectedPluginIndex--; + + BringSelectedButtonIntoView(perLineCount, scrollviewer); + } } - internal void SelectUpOne() + internal void SelectUpOne(double WindowWidth, object? scrollviewer) { + var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); + + var targetIndex = SelectedPluginIndex - perLineCount; + if (SelectedPluginIndexInRange(targetIndex)) + { + SelectedPluginIndex = targetIndex; + + BringSelectedButtonIntoView(perLineCount, scrollviewer); + } } - internal void SelectDownOne() + internal void SelectDownOne(double WindowWidth, object? scrollviewer) { + var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); + var targetIndex = SelectedPluginIndex + perLineCount; + + if (SelectedPluginIndexInRange(targetIndex)) + { + SelectedPluginIndex = targetIndex; + + BringSelectedButtonIntoView(perLineCount, scrollviewer); + } + else + { + targetIndex = PluginInfos.Count - 1; + + if ((targetIndex / perLineCount) - (SelectedPluginIndex / perLineCount) == 0) + return; + + if (SelectedPluginIndexInRange(targetIndex)) + { + SelectedPluginIndex = targetIndex; + + BringSelectedButtonIntoView(perLineCount, scrollviewer); + } + } } internal void SelectPluginInfo() diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml b/KitX Dashboard/Views/PluginsLaunchWindow.axaml index 9808eea7..0f7540ad 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml @@ -9,12 +9,12 @@ xmlns:uip="using:FluentAvalonia.UI.Controls.Primitives" xmlns:vm="using:KitX.Dashboard.ViewModels" Title="PluginsLaunchWindow" - Width="650" - Height="300" - MinWidth="650" - MinHeight="300" - d:DesignHeight="300" - d:DesignWidth="650" + Width="600" + Height="330" + MinWidth="600" + MinHeight="330" + d:DesignHeight="330" + d:DesignWidth="600" Background="Transparent" ExtendClientAreaChromeHints="NoChrome" ExtendClientAreaToDecorationsHint="True" @@ -62,7 +62,18 @@ - + + + + + + + + + + @@ -93,7 +104,7 @@ - + diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs index 28301a21..7300023f 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs @@ -96,11 +96,29 @@ private void PluginsLaunchWindow_KeyDown(object? sender, KeyEventArgs e) Hide(); OnHideAction?.Invoke(); break; + case Key.Left: + viewModel.SelectLeftOne( + Width, + this.FindControl("PluginsScrollViewer") + ); + break; case Key.Right: - viewModel.SelectRightOne(); + viewModel.SelectRightOne( + Width, + this.FindControl("PluginsScrollViewer") + ); break; - case Key.Left: - viewModel.SelectLeftOne(); + case Key.Up: + viewModel.SelectUpOne( + Width, + this.FindControl("PluginsScrollViewer") + ); + break; + case Key.Down: + viewModel.SelectDownOne( + Width, + this.FindControl("PluginsScrollViewer") + ); break; case Key.Enter: viewModel.SelectPluginInfo(); @@ -108,6 +126,23 @@ private void PluginsLaunchWindow_KeyDown(object? sender, KeyEventArgs e) } } + protected override void OnResized(WindowResizedEventArgs e) + { + if (ExperimentalFlags.EnablePluginLaunchWindowWidthSnap) + { + var basicWidth = 80; + var addonWidth = 40; + var windowWidth = (int)e.ClientSize.Width; + var oneLineCount = (windowWidth - addonWidth) / basicWidth; + var left = (windowWidth - addonWidth) % basicWidth; + + if (left < basicWidth / 2) + Width = oneLineCount * basicWidth + addonWidth; + else + Width = (oneLineCount + 1) * basicWidth + addonWidth; + } + } + protected override void OnClosing(WindowClosingEventArgs e) { base.OnClosing(e); From 069443deae10ec863bdb65587033fe9986b5a9be Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sat, 24 Feb 2024 13:54:00 +0800 Subject: [PATCH 25/27] =?UTF-8?q?=F0=9F=92=BE=20Feat(Dashboard):=20Optimiz?= =?UTF-8?q?ed=20PluginsLaunchWindow.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevicesNetwork/DevicesDiscoveryServer.cs | 6 +- KitX Dashboard/Network/NetworkHelper.cs | 4 +- .../Network/PluginsNetwork/PluginsServer.cs | 6 +- .../PluginsLaunchWindowViewModel.cs | 27 +++- .../Views/PluginsLaunchWindow.axaml | 15 +- .../Views/PluginsLaunchWindow.axaml.cs | 128 +++++++++++++----- 6 files changed, 134 insertions(+), 52 deletions(-) diff --git a/KitX Dashboard/Network/DevicesNetwork/DevicesDiscoveryServer.cs b/KitX Dashboard/Network/DevicesNetwork/DevicesDiscoveryServer.cs index 10f6fe41..ee084950 100644 --- a/KitX Dashboard/Network/DevicesNetwork/DevicesDiscoveryServer.cs +++ b/KitX Dashboard/Network/DevicesNetwork/DevicesDiscoveryServer.cs @@ -1,7 +1,7 @@ using Common.BasicHelper.Utils.Extensions; using KitX.Dashboard.Managers; using KitX.Dashboard.Names; -using KitX.Dashboard.Network.PluginsNetwork; +using KitX.Dashboard.Views; using KitX.Shared.Device; using Serilog; using System; @@ -115,7 +115,7 @@ private static void UpdateDefaultDeviceInfo() .ResetIPv6(NetworkHelper.GetInterNetworkIPv6()) ; DefaultDeviceInfo.PluginsServerPort = ConstantTable.PluginsServerPort; - DefaultDeviceInfo.PluginsCount = PluginsServer.Instance.PluginConnectors.Count; + DefaultDeviceInfo.PluginsCount = ViewInstances.PluginInfos.Count; DefaultDeviceInfo.IsMainDevice = ConstantTable.IsMainMachine; DefaultDeviceInfo.DevicesServerPort = ConstantTable.DevicesServerPort; DefaultDeviceInfo.DevicesServerBuildTime = ConstantTable.ServerBuildTime; @@ -230,7 +230,7 @@ private void MultiDevicesBroadCastReceive() { var location = $"{nameof(DevicesDiscoveryServer)}.{nameof(MultiDevicesBroadCastReceive)}"; - IPEndPoint multicast = new(IPAddress.Any, 0); + var multicast = new IPEndPoint(IPAddress.Any, 0); UdpReceiver?.Client.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, diff --git a/KitX Dashboard/Network/NetworkHelper.cs b/KitX Dashboard/Network/NetworkHelper.cs index c2baa0b4..b72f131c 100644 --- a/KitX Dashboard/Network/NetworkHelper.cs +++ b/KitX Dashboard/Network/NetworkHelper.cs @@ -1,7 +1,7 @@ using Common.BasicHelper.Core.Shell; using Common.BasicHelper.Utils.Extensions; using KitX.Dashboard.Converters; -using KitX.Dashboard.Network.PluginsNetwork; +using KitX.Dashboard.Views; using KitX.Shared.Device; using Serilog; using System; @@ -221,6 +221,6 @@ from nic in NetworkInterface.GetAllNetworkInterfaces() PluginsServerPort = ConstantTable.PluginsServerPort, DevicesServerPort = ConstantTable.DevicesServerPort, DevicesServerBuildTime = new(), - PluginsCount = PluginsServer.Instance.PluginConnectors.Count, + PluginsCount = ViewInstances.PluginInfos.Count, }; } diff --git a/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs b/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs index 73e0c681..e1efe1eb 100644 --- a/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs +++ b/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs @@ -1,7 +1,7 @@ using Fleck; using KitX.Dashboard.Configuration; using KitX.Dashboard.Services; -using System.Collections.ObjectModel; +using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; using System.Threading.Tasks; @@ -16,9 +16,9 @@ public class PluginsServer : ConfigFetcher private WebSocketServer? _server; - private readonly ObservableCollection _connectors = []; + private readonly List _connectors = []; - public ObservableCollection PluginConnectors => _connectors; + public List PluginConnectors => _connectors; public PluginsServer() { diff --git a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs index 8cc13775..9ebfd22a 100644 --- a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs @@ -1,10 +1,12 @@ -using KitX.Dashboard.Views; +using Avalonia; +using Avalonia.Controls; +using KitX.Dashboard.Views; using KitX.Shared.Plugin; using ReactiveUI; -using System.Collections.ObjectModel; -using Avalonia; using System; -using Avalonia.Controls; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; namespace KitX.Dashboard.ViewModels; @@ -27,6 +29,8 @@ public override void InitEvents() PluginInfos.CollectionChanged += (_, _) => { PluginsCount = $"{PluginInfos.Count}"; + + this.RaisePropertyChanged(nameof(SearchItems)); }; } @@ -45,7 +49,7 @@ public string PluginsCount public static double NoPlugins_TipHeight => PluginInfos.Count == 0 ? 40 : 0; - private int selectedPluginIndex = 0; + private int selectedPluginIndex = -1; public int SelectedPluginIndex { @@ -59,7 +63,7 @@ public int SelectedPluginIndex public PluginInfo? SelectedPluginInfo { - get => (SelectedPluginIndex >= 0 && SelectedPluginIndex < PluginInfos.Count) ? PluginInfos[SelectedPluginIndex] : null; + get => SelectedPluginIndexInRange(SelectedPluginIndex) ? PluginInfos[SelectedPluginIndex] : null; set { if (value is null) return; @@ -88,6 +92,17 @@ public Parameter? SelectedParameter public static ObservableCollection PluginInfos => ViewInstances.PluginInfos; + public static IEnumerable SearchItems => PluginInfos.Select(x => x.Name).Distinct(); + //.Concat( + // PluginInfos.SelectMany( + // x => x.SimpleDescription.Select(x => x.Value) + // ) + //).Concat( + // PluginInfos.SelectMany( + // x => x.ComplexDescription.Select(x => x.Value) + // ) + //).Distinct(); + public string? SearchingText { get; set; } private Vector scrollViewerOffset = new(0, 0); diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml b/KitX Dashboard/Views/PluginsLaunchWindow.axaml index 0f7540ad..5c5ecc7e 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml @@ -19,8 +19,6 @@ ExtendClientAreaChromeHints="NoChrome" ExtendClientAreaToDecorationsHint="True" Icon="avares://KitX.Dashboard.Assets/KitX-Icon-32x32.png" - KeyDown="PluginsLaunchWindow_KeyDown" - PointerPressed="PluginsLaunchWindow_PointerPressed" Topmost="True" TransparencyLevelHint="Mica" WindowStartupLocation="CenterScreen" @@ -35,10 +33,14 @@ - @@ -63,6 +65,7 @@ @@ -98,6 +101,7 @@ @@ -107,6 +111,11 @@ + + + + + pluginsLaunchWindowDisplayed = false); + OnHideAction = () => pluginsLaunchWindowDisplayed = false; EventService.OnExiting += Close; @@ -42,9 +44,55 @@ public PluginsLaunchWindow() } } + if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) + { + //box.AttachedToVisualTree += (_, _) => box.Focus(); + //box.TextChanged += (_, _) => + //{ + // if (box.Text?.Equals("`") ?? false) + // box.Text = ""; + //}; + //box.KeyDown += (_, e) => + //{ + // if (e.PhysicalKey == PhysicalKey.Backquote) + // e.Handled = true; + //}; + } + + if (this.FindControl("PluginsScrollViewer") is ScrollViewer viewer) + { + viewer.KeyDown += PluginsScrollViewer_KeyDown; + } + RegisterGlobalHotKey(); } + private void PluginsScrollViewer_KeyDown(object? sender, KeyEventArgs e) + { + if (sender is not ScrollViewer viewer) return; + + if (viewer.IsFocused == false) return; + + switch (e.Key) + { + case Key.Left: + viewModel.SelectLeftOne(Width, sender); + break; + case Key.Right: + viewModel.SelectRightOne(Width, sender); + break; + case Key.Up: + viewModel.SelectUpOne(Width, sender); + break; + case Key.Down: + viewModel.SelectDownOne(Width, sender); + break; + case Key.Enter: + viewModel.SelectPluginInfo(); + break; + } + } + private void RegisterGlobalHotKey() { Instances.KeyHookManager?.RegisterHotKeyHandler(nameof(PluginsLaunchWindow), codes => @@ -79,51 +127,59 @@ private void RegisterGlobalHotKey() }); } - public PluginsLaunchWindow OnHide(Action onHideAction) + protected override void OnPointerPressed(PointerPressedEventArgs e) { - OnHideAction = onHideAction; + BeginMoveDrag(e); - return this; + base.OnPointerPressed(e); } - private void PluginsLaunchWindow_PointerPressed(object? sender, PointerPressedEventArgs e) => BeginMoveDrag(e); - - private void PluginsLaunchWindow_KeyDown(object? sender, KeyEventArgs e) + protected override void OnKeyDown(KeyEventArgs e) { switch (e.Key) { + case Key.Tab: + e.Handled = true; + break; case Key.Escape: Hide(); OnHideAction?.Invoke(); break; - case Key.Left: - viewModel.SelectLeftOne( - Width, - this.FindControl("PluginsScrollViewer") - ); - break; - case Key.Right: - viewModel.SelectRightOne( - Width, - this.FindControl("PluginsScrollViewer") - ); - break; - case Key.Up: - viewModel.SelectUpOne( - Width, - this.FindControl("PluginsScrollViewer") - ); - break; - case Key.Down: - viewModel.SelectDownOne( - Width, - this.FindControl("PluginsScrollViewer") - ); - break; - case Key.Enter: - viewModel.SelectPluginInfo(); + } + + switch (e.PhysicalKey) + { + case PhysicalKey.Backquote: + if (viewModel.SelectedPluginIndex == -1) + { + viewModel.SelectedPluginIndex = previousSelectedPluginIndex ?? 0; + + if (this.FindControl("PluginsScrollViewer") is ScrollViewer viewer) + viewer.Focus(); + } + else + { + previousSelectedPluginIndex = viewModel.SelectedPluginIndex; + + viewModel.SelectedPluginIndex = -1; + + if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) + box.Focus(); + } + e.Handled = true; break; } + + base.OnKeyDown(e); + } + + protected override void OnGotFocus(GotFocusEventArgs e) + { + base.OnGotFocus(e); + + //if (viewModel.SelectedPluginIndex == -1) + // if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) + // box.Focus(); } protected override void OnResized(WindowResizedEventArgs e) @@ -141,12 +197,12 @@ protected override void OnResized(WindowResizedEventArgs e) else Width = (oneLineCount + 1) * basicWidth + addonWidth; } + + base.OnResized(e); } protected override void OnClosing(WindowClosingEventArgs e) { - base.OnClosing(e); - if (!ConstantTable.Exiting) { e.Cancel = true; @@ -155,5 +211,7 @@ protected override void OnClosing(WindowClosingEventArgs e) OnHideAction?.Invoke(); } + + base.OnClosing(e); } } From eefe60fa283ab06bf464e9c2ad7ae6d6a043c1a8 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sun, 25 Feb 2024 19:10:37 +0800 Subject: [PATCH 26/27] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20The=20first=20time?= =?UTF-8?q?=20that=20dashboard=20invoke=20plugin=20function=20throw=20netw?= =?UTF-8?q?ork=20connection.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/PluginInfoConverters.cs | 4 +- .../Network/PluginsNetwork/PluginConnector.cs | 2 +- .../Network/PluginsNetwork/PluginsServer.cs | 13 + .../PluginsLaunchWindowViewModel.cs | 264 ++++++++++++++---- .../Views/PluginsLaunchWindow.axaml | 86 +++++- .../Views/PluginsLaunchWindow.axaml.cs | 124 ++++---- 6 files changed, 379 insertions(+), 114 deletions(-) diff --git a/KitX Dashboard/Converters/PluginInfoConverters.cs b/KitX Dashboard/Converters/PluginInfoConverters.cs index 8fefa5c1..2f7d26d4 100644 --- a/KitX Dashboard/Converters/PluginInfoConverters.cs +++ b/KitX Dashboard/Converters/PluginInfoConverters.cs @@ -54,11 +54,11 @@ public class PluginInfoSelectedConverter : IMultiValueConverter { public object? Convert(IList values, Type targetType, object? parameter, CultureInfo culture) { - if (values.Count != 2) return false; + if (values.Count != 3) return false; if (values[0] is string id1) if (values[1] is string id2) - return id1.Equals(id2); + return id1.Equals(id2) && (bool)values[2]!; return false; } diff --git a/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs b/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs index c5d9e33b..23f849c3 100644 --- a/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs +++ b/KitX Dashboard/Network/PluginsNetwork/PluginConnector.cs @@ -200,7 +200,7 @@ private void SendWorkingDetail() } } - private async void Request(Request request) + internal async void Request(Request request) { await _connection!.Send(JsonSerializer.Serialize(request, serializerOptions)); } diff --git a/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs b/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs index e1efe1eb..c1f3c5a5 100644 --- a/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs +++ b/KitX Dashboard/Network/PluginsNetwork/PluginsServer.cs @@ -1,6 +1,7 @@ using Fleck; using KitX.Dashboard.Configuration; using KitX.Dashboard.Services; +using KitX.Shared.Plugin; using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; @@ -50,6 +51,18 @@ public PluginsServer Run() return this; } + public PluginConnector? FindConnector(PluginInfo info) + { + var query = PluginConnectors.Where( + x => x.PluginInfo.HasValue && x.PluginInfo.Value.Equals(info) + ); + + if (query.Any()) + return query.First(); + else + return null; + } + public async Task Close() { await Task.Run(() => diff --git a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs index 9ebfd22a..6d6773ce 100644 --- a/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/PluginsLaunchWindowViewModel.cs @@ -1,12 +1,15 @@ using Avalonia; -using Avalonia.Controls; +using Common.BasicHelper.Utils.Extensions; +using KitX.Dashboard.Network.PluginsNetwork; using KitX.Dashboard.Views; using KitX.Shared.Plugin; +using KitX.Shared.WebCommand; using ReactiveUI; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Text.Json; namespace KitX.Dashboard.ViewModels; @@ -30,11 +33,15 @@ public override void InitEvents() { PluginsCount = $"{PluginInfos.Count}"; + CheckPluginIndex(); + this.RaisePropertyChanged(nameof(SearchItems)); + this.RaisePropertyChanged(nameof(SelectedPluginInfo)); + this.RaisePropertyChanged(nameof(SelectedFunction)); }; } - public string pluginsCount = $"0"; + public string pluginsCount = "0"; public string PluginsCount { @@ -49,7 +56,7 @@ public string PluginsCount public static double NoPlugins_TipHeight => PluginInfos.Count == 0 ? 40 : 0; - private int selectedPluginIndex = -1; + private int selectedPluginIndex = 0; public int SelectedPluginIndex { @@ -63,7 +70,7 @@ public int SelectedPluginIndex public PluginInfo? SelectedPluginInfo { - get => SelectedPluginIndexInRange(SelectedPluginIndex) ? PluginInfos[SelectedPluginIndex] : null; + get => PluginIndexInRange(SelectedPluginIndex) ? PluginInfos[SelectedPluginIndex] : null; set { if (value is null) return; @@ -78,32 +85,102 @@ public PluginInfo? SelectedPluginInfo public Function? SelectedFunction { - get => selectedFunction; - set => this.RaiseAndSetIfChanged(ref selectedFunction, value); + get + { + if (SelectedPluginInfo is null) selectedFunction = null; + + return selectedFunction; + } + + set + { + this.RaiseAndSetIfChanged(ref selectedFunction, value); + + this.RaisePropertyChanged(nameof(HavingParameters)); + } } - private Parameter? selectedParameter; + public static ObservableCollection PluginInfos => ViewInstances.PluginInfos; + + private bool isSelectingPlugin = true; - public Parameter? SelectedParameter + public bool IsSelectingPlugin { - get => selectedParameter; - set => this.RaiseAndSetIfChanged(ref selectedParameter, value); + get => isSelectingPlugin; + set + { + if (IsSelectingFunction) + IsSelectingFunction = false; + + this.RaiseAndSetIfChanged(ref isSelectingPlugin, value); + + if (value) + { + SearchingText = SelectedPluginInfo?.Name; + + this.RaisePropertyChanged(nameof(SearchItems)); + } + } } - public static ObservableCollection PluginInfos => ViewInstances.PluginInfos; + private bool isSelectingFunction = false; + + public bool IsSelectingFunction + { + get => isSelectingFunction; + set + { + if (IsSelectingPlugin) + IsSelectingPlugin = false; - public static IEnumerable SearchItems => PluginInfos.Select(x => x.Name).Distinct(); - //.Concat( - // PluginInfos.SelectMany( - // x => x.SimpleDescription.Select(x => x.Value) - // ) - //).Concat( - // PluginInfos.SelectMany( - // x => x.ComplexDescription.Select(x => x.Value) - // ) - //).Distinct(); + this.RaiseAndSetIfChanged(ref isSelectingFunction, value); - public string? SearchingText { get; set; } + + if (value) + { + SearchingText = SelectedFunction?.Name; + + this.RaisePropertyChanged(nameof(SearchItems)); + } + } + } + + public bool HavingParameters + { + get + { + if (SelectedFunction is null) return false; + + return SelectedFunction.Value.Parameters.Count != 0; + } + } + + public IEnumerable SearchItems + { + get + { + if (IsSelectingPlugin) + { + return PluginInfos.Select(x => x.Name).Distinct(); + } + else if (IsSelectingFunction) + { + return SelectedPluginInfo?.Functions.Select(f => f.Name) ?? []; + } + else return []; + } + } + + private string? searchingText; + + public string? SearchingText + { + get => searchingText; + set + { + this.RaiseAndSetIfChanged(ref searchingText, value); + } + } private Vector scrollViewerOffset = new(0, 0); @@ -113,13 +190,19 @@ public Vector ScrollViewerOffset set => this.RaiseAndSetIfChanged(ref scrollViewerOffset, value); } - private void BringSelectedButtonIntoView(int perLineButtonsCount, object? scrollvierwer) + private bool isInDirectSelectingMode = false; + + public bool IsInDirectSelectingMode { - if (scrollvierwer is not ScrollViewer viewer) return; + get => isInDirectSelectingMode; + set => this.RaiseAndSetIfChanged(ref isInDirectSelectingMode, value); + } - var viewerHeight = (int)Math.Floor(viewer?.DesiredSize.Height ?? 240); + private void BringSelectedButtonIntoView(int perLineButtonsCount, double scrollviewerHeight, double scrollviewerOffsetY) + { + var viewerHeight = (int)Math.Floor(scrollviewerHeight); - var viewerOffsetY = (int)Math.Floor(viewer?.Offset.Y ?? 0); + var viewerOffsetY = (int)Math.Floor(scrollviewerOffsetY); var lineIndex = SelectedPluginIndex / perLineButtonsCount; @@ -137,57 +220,60 @@ private void BringSelectedButtonIntoView(int perLineButtonsCount, object? scroll } } - private static bool SelectedPluginIndexInRange(int index) => index >= 0 && index < PluginInfos.Count; + private static bool PluginIndexInRange(int index) => index >= 0 && index < PluginInfos.Count; - internal void SelectRightOne(double WindowWidth, object? scrollviewer) + private void CheckPluginIndex() { - var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); - - if (SelectedPluginIndexInRange(SelectedPluginIndex + 1)) + if (PluginIndexInRange(SelectedPluginIndex) == false) { - SelectedPluginIndex++; - - BringSelectedButtonIntoView(perLineCount, scrollviewer); + if (SelectedPluginIndex >= PluginInfos.Count) + SelectedPluginIndex = PluginInfos.Count - 1; + else if (SelectedPluginIndex < 0) + SelectedPluginIndex = 0; } } - internal void SelectLeftOne(double WindowWidth, object? scrollviewer) + internal void SelectLeftOne(int perLineCount, double scrollviewerHeight, double scrollviewerOffsetY) { - var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); - - if (SelectedPluginIndexInRange(selectedPluginIndex - 1)) + if (PluginIndexInRange(selectedPluginIndex - 1)) { SelectedPluginIndex--; - BringSelectedButtonIntoView(perLineCount, scrollviewer); + BringSelectedButtonIntoView(perLineCount, scrollviewerHeight, scrollviewerOffsetY); } } - internal void SelectUpOne(double WindowWidth, object? scrollviewer) + internal void SelectRightOne(int perLineCount, double scrollviewerHeight, double scrollviewerOffsetY) { - var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); + if (PluginIndexInRange(SelectedPluginIndex + 1)) + { + SelectedPluginIndex++; + + BringSelectedButtonIntoView(perLineCount, scrollviewerHeight, scrollviewerOffsetY); + } + } + internal void SelectUpOne(int perLineCount, double scrollviewerHeight, double scrollviewerOffsetY) + { var targetIndex = SelectedPluginIndex - perLineCount; - if (SelectedPluginIndexInRange(targetIndex)) + if (PluginIndexInRange(targetIndex)) { SelectedPluginIndex = targetIndex; - BringSelectedButtonIntoView(perLineCount, scrollviewer); + BringSelectedButtonIntoView(perLineCount, scrollviewerHeight, scrollviewerOffsetY); } } - internal void SelectDownOne(double WindowWidth, object? scrollviewer) + internal void SelectDownOne(int perLineCount, double scrollviewerHeight, double scrollviewerOffsetY) { - var perLineCount = (int)Math.Floor((WindowWidth - 40) / 80); - var targetIndex = SelectedPluginIndex + perLineCount; - if (SelectedPluginIndexInRange(targetIndex)) + if (PluginIndexInRange(targetIndex)) { SelectedPluginIndex = targetIndex; - BringSelectedButtonIntoView(perLineCount, scrollviewer); + BringSelectedButtonIntoView(perLineCount, scrollviewerHeight, scrollviewerOffsetY); } else { @@ -196,17 +282,93 @@ internal void SelectDownOne(double WindowWidth, object? scrollviewer) if ((targetIndex / perLineCount) - (SelectedPluginIndex / perLineCount) == 0) return; - if (SelectedPluginIndexInRange(targetIndex)) + if (PluginIndexInRange(targetIndex)) { SelectedPluginIndex = targetIndex; - BringSelectedButtonIntoView(perLineCount, scrollviewer); + BringSelectedButtonIntoView(perLineCount, scrollviewerHeight, scrollviewerOffsetY); } } } - internal void SelectPluginInfo() + internal void SelectHomeOne(int perLineCount) + { + var currentLine = SelectedPluginIndex / perLineCount; + + var targetIndex = currentLine * perLineCount; + + if (PluginIndexInRange(targetIndex)) + SelectedPluginIndex = targetIndex; + } + + internal void SelectEndOne(int perLineCount) { + var currentLine = SelectedPluginIndex / perLineCount; + var targetIndex = ((currentLine + 1) * perLineCount) - 1; + + while (PluginIndexInRange(targetIndex) == false && targetIndex >= 0) + targetIndex--; + + if (PluginIndexInRange(targetIndex)) + SelectedPluginIndex = targetIndex; + } + + internal void SubmitSearchingText() + { + var text = SearchingText; + + if (IsSelectingPlugin) + { + var index = PluginInfos.IndexOf(x => x.Name.Equals(text)); + + if (index != -1) + { + SelectedPluginIndex = index; + + if (SelectedFunction is not null) SelectedFunction = null; + + IsSelectingFunction = true; + } + } + else if (IsSelectingFunction) + { + if (SelectedPluginInfo is not null) + foreach (var func in SelectedPluginInfo.Value.Functions) + if (func.Name.Equals(text)) + { + SelectedFunction = func; + + break; + } + + if (SelectedPluginInfo is not null && SelectedFunction is not null && (HavingParameters == false)) + { + var plugConnector = PluginsServer.Instance.FindConnector(SelectedPluginInfo.Value); + + if (plugConnector is not null) + { + var connector = new Connector() + .SetSerializer(x => JsonSerializer.Serialize(x)) + .SetSender(plugConnector.Request) + ; + + var request = connector.Request() + .ReceiveCommand() + .UpdateCommand(cmd => + { + cmd.FunctionName = SelectedFunction.Value.Name; + + return cmd; + }) + .Send() + ; + } + } + } + else + { + + } } } diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml b/KitX Dashboard/Views/PluginsLaunchWindow.axaml index 5c5ecc7e..2d38780f 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml @@ -10,10 +10,10 @@ xmlns:vm="using:KitX.Dashboard.ViewModels" Title="PluginsLaunchWindow" Width="600" - Height="330" + Height="360" MinWidth="600" - MinHeight="330" - d:DesignHeight="330" + MinHeight="360" + d:DesignHeight="360" d:DesignWidth="600" Background="Transparent" ExtendClientAreaChromeHints="NoChrome" @@ -30,9 +30,15 @@ - + + + + - + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -62,7 +110,24 @@ - + + + + + + + diff --git a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs index 816a7380..4d0ada3b 100644 --- a/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs +++ b/KitX Dashboard/Views/PluginsLaunchWindow.axaml.cs @@ -1,10 +1,8 @@ using Avalonia.Controls; using Avalonia.Input; -using Avalonia.Media; using Avalonia.Threading; using KitX.Dashboard.Services; using KitX.Dashboard.ViewModels; -using Serilog; using SharpHook.Native; using System; @@ -14,7 +12,7 @@ public partial class PluginsLaunchWindow : Window { private readonly PluginsLaunchWindowViewModel viewModel = new(); - private Action? OnHideAction; + private readonly Action? OnHideAction; private bool pluginsLaunchWindowDisplayed = false; @@ -22,8 +20,6 @@ public partial class PluginsLaunchWindow : Window public PluginsLaunchWindow() { - var location = $"{nameof(PluginsLaunchWindow)}.ctor"; - InitializeComponent(); DataContext = viewModel; @@ -32,31 +28,22 @@ public PluginsLaunchWindow() EventService.OnExiting += Close; - if (OperatingSystem.IsWindows() == false) - { - try - { - Background = Resources["ThemePrimaryAccent"] as SolidColorBrush; - } - catch (Exception ex) - { - Log.Warning(ex, $"In {location}: {ex.Message}"); - } - } + Initialize(); + } + private void Initialize() + { if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) { - //box.AttachedToVisualTree += (_, _) => box.Focus(); - //box.TextChanged += (_, _) => - //{ - // if (box.Text?.Equals("`") ?? false) - // box.Text = ""; - //}; - //box.KeyDown += (_, e) => - //{ - // if (e.PhysicalKey == PhysicalKey.Backquote) - // e.Handled = true; - //}; + box.KeyDown += (_, e) => + { + if (e.Key == Key.Enter) + { + viewModel.SubmitSearchingText(); + + e.Handled = true; + } + }; } if (this.FindControl("PluginsScrollViewer") is ScrollViewer viewer) @@ -73,22 +60,54 @@ private void PluginsScrollViewer_KeyDown(object? sender, KeyEventArgs e) if (viewer.IsFocused == false) return; + switch (e.Key) + { + case Key.Enter: + // ToDo: Select Plugin Info + return; + } + + var perLineCount = (int)Math.Floor((Width - 40) / 80); + + var viewerHeight = viewer.DesiredSize.Height; + + var viewerOffsetY = viewer.Offset.Y; + switch (e.Key) { case Key.Left: - viewModel.SelectLeftOne(Width, sender); + viewModel.SelectLeftOne( + perLineCount, + viewerHeight, + viewerOffsetY + ); break; case Key.Right: - viewModel.SelectRightOne(Width, sender); + viewModel.SelectRightOne( + perLineCount, + viewerHeight, + viewerOffsetY + ); break; case Key.Up: - viewModel.SelectUpOne(Width, sender); + viewModel.SelectUpOne( + perLineCount, + viewerHeight, + viewerOffsetY + ); break; case Key.Down: - viewModel.SelectDownOne(Width, sender); + viewModel.SelectDownOne( + perLineCount, + viewerHeight, + viewerOffsetY + ); break; - case Key.Enter: - viewModel.SelectPluginInfo(); + case Key.Home: + viewModel.SelectHomeOne(perLineCount); + break; + case Key.End: + viewModel.SelectEndOne(perLineCount); break; } } @@ -127,18 +146,26 @@ private void RegisterGlobalHotKey() }); } - protected override void OnPointerPressed(PointerPressedEventArgs e) - { - BeginMoveDrag(e); - - base.OnPointerPressed(e); - } - protected override void OnKeyDown(KeyEventArgs e) { + var box = this.FindControl("MainAutoCompleteBox"); + switch (e.Key) { case Key.Tab: + if (viewModel.IsInDirectSelectingMode == false) + { + if (e.KeyModifiers == KeyModifiers.Shift) + { + if (viewModel.IsSelectingFunction) + viewModel.IsSelectingPlugin = true; + } + else + { + if (viewModel.IsSelectingPlugin) + viewModel.IsSelectingFunction = true; + } + } e.Handled = true; break; case Key.Escape: @@ -150,9 +177,9 @@ protected override void OnKeyDown(KeyEventArgs e) switch (e.PhysicalKey) { case PhysicalKey.Backquote: - if (viewModel.SelectedPluginIndex == -1) + if (viewModel.IsInDirectSelectingMode == false) { - viewModel.SelectedPluginIndex = previousSelectedPluginIndex ?? 0; + viewModel.IsInDirectSelectingMode = true; if (this.FindControl("PluginsScrollViewer") is ScrollViewer viewer) viewer.Focus(); @@ -161,10 +188,9 @@ protected override void OnKeyDown(KeyEventArgs e) { previousSelectedPluginIndex = viewModel.SelectedPluginIndex; - viewModel.SelectedPluginIndex = -1; + viewModel.IsInDirectSelectingMode = false; - if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) - box.Focus(); + box?.Focus(); } e.Handled = true; break; @@ -173,13 +199,11 @@ protected override void OnKeyDown(KeyEventArgs e) base.OnKeyDown(e); } - protected override void OnGotFocus(GotFocusEventArgs e) + protected override void OnPointerPressed(PointerPressedEventArgs e) { - base.OnGotFocus(e); + BeginMoveDrag(e); - //if (viewModel.SelectedPluginIndex == -1) - // if (this.FindControl("MainAutoCompleteBox") is AutoCompleteBox box) - // box.Focus(); + base.OnPointerPressed(e); } protected override void OnResized(WindowResizedEventArgs e) From c3e8d9b0960f3633991dd34bb06c0c581ea6b2ee Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sun, 25 Feb 2024 23:36:24 +0800 Subject: [PATCH 27/27] =?UTF-8?q?=F0=9F=94=A7=20Fix(Dashboard):=20Fixed=20?= =?UTF-8?q?two=20inheritance-related=20issues.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs | 2 -- KitX Dashboard/ViewModels/MainWindowViewModel.cs | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs b/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs index bcfd6a5e..94e3b690 100644 --- a/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/AnouncementsWindowViewModel.cs @@ -14,8 +14,6 @@ internal class AnouncementsWindowViewModel : ViewModelBase, INotifyPropertyChang { public new event PropertyChangedEventHandler? PropertyChanged; - private static AppConfig AppConfig => Instances.ConfigManager.AppConfig; - public AnouncementsWindowViewModel() { InitCommands(); diff --git a/KitX Dashboard/ViewModels/MainWindowViewModel.cs b/KitX Dashboard/ViewModels/MainWindowViewModel.cs index 691a66f6..8b3da49c 100644 --- a/KitX Dashboard/ViewModels/MainWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/MainWindowViewModel.cs @@ -1,5 +1,4 @@ -using Avalonia; -using KitX.Dashboard.Configuration; +using KitX.Dashboard.Configuration; using KitX.Dashboard.Views; using ReactiveUI; using System.Reactive; @@ -8,8 +7,6 @@ namespace KitX.Dashboard.ViewModels; internal class MainWindowViewModel : ViewModelBase { - private static AppConfig AppConfig => Instances.ConfigManager.AppConfig; - public MainWindowViewModel() { InitCommands();