Skip to content

Commit

Permalink
Merge pull request #28 from Crequency/dev=main
Browse files Browse the repository at this point in the history
[Pull Request] More features, more interfaces, some optimizations
  • Loading branch information
Dynesshely authored Jun 29, 2023
2 parents 663cc7a + 26bd227 commit c939260
Show file tree
Hide file tree
Showing 18 changed files with 490 additions and 176 deletions.
12 changes: 6 additions & 6 deletions Data/GlobalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ internal static class GlobalInfo

internal const string UpdateSavePath = "./Update/";

internal const string configFilePath = $"{ConfigPath}config.json";
internal const string IconBase64FileName = "KitX.Base64.txt";

internal const string pluginsListConfigFilePath = $"{ConfigPath}plugins.json";
internal const int LastBreakAfterExit = 2000;

internal const string activitiesDataBaseFilePath = $"{DataPath}Activities.db";
private const string configFilePath = $"{ConfigPath}config.json";

internal const string thirdPartLicenseFilePath = $"{AssetsPath}ThirdPartLicense.md";
private const string pluginsListConfigFilePath = $"{ConfigPath}plugins.json";

internal const string IconBase64FileName = "KitX.Base64.txt";
private const string activitiesDataBaseFilePath = $"{DataPath}Activities.db";

internal const int LastBreakAfterExit = 2000;
private const string thirdPartLicenseFilePath = $"{AssetsPath}ThirdPartLicense.md";

internal static string ConfigFilePath => configFilePath.GetFullPath();

Expand Down
21 changes: 20 additions & 1 deletion Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Common.BasicHelper.IO;
using Avalonia.Threading;
using Common.BasicHelper.IO;
using Common.BasicHelper.Utils.Extensions;
using KitX_Dashboard.Data;
using KitX_Dashboard.Managers;
Expand Down Expand Up @@ -172,6 +173,24 @@ public static void StartUpCheck()

#endregion

#region 初始化热键系统

Program.HotKeyManager = new HotKeyManager().Hook();

#endregion

#region 初始化持久的窗口

Program.SignalTasksManager.SignalRun(nameof(SignalsNames.MainWindowInitSignal), () =>
{
Dispatcher.UIThread.Post(() =>
{
Program.PluginsLaunchWindow = new();
});
});

#endregion

}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions KitX Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>Assets\KitX-Icon-256x.ico</ApplicationIcon>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>

<PropertyGroup>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version>3.23.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-06-06"))).TotalDays)</Version>
Expand All @@ -19,10 +21,6 @@
<DefineConstants>IsBuild4WindowsPlatform</DefineConstants>
</PropertyGroup>

<!--<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" />
</ItemGroup>-->

<!--用于将依赖移动到 Libraries 目录, 使根目录更加整洁-->
<PropertyGroup>
<BeautySharedRuntimeMode>False</BeautySharedRuntimeMode>
Expand Down Expand Up @@ -57,6 +55,9 @@
<AvaloniaXaml Remove="Languages\ru-ru.axaml" />
<AvaloniaXaml Remove="Languages\zh-cn.axaml" />
<AvaloniaXaml Remove="Languages\zh-tw.axaml" />
</ItemGroup>

<ItemGroup>
<AvaloniaXaml Remove="FakesAssemblies\**" />
<Compile Remove="FakesAssemblies\**" />
<EmbeddedResource Remove="FakesAssemblies\**" />
Expand Down Expand Up @@ -102,6 +103,7 @@
<PackageReference Include="nulastudio.NetBeauty" Version="2.1.2.1" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SharpHook" Version="4.2.0" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.5.1" />
</ItemGroup>
<ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions Managers/HotKeyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Common.BasicHelper.Utils.Extensions;
using SharpHook;
using SharpHook.Native;
using System;
using System.Collections.Generic;

namespace KitX_Dashboard.Managers;

internal class HotKeyManager
{
private const int keysLimitation = 5;

private readonly Queue<KeyCode>? keyPressed;

private readonly Dictionary<string, Action<KeyCode[]>>? hotKeyHandlers;

public HotKeyManager()
{
keyPressed = new();

hotKeyHandlers = new();
}

public HotKeyManager Hook()
{
var hook = new TaskPoolGlobalHook();

hook.KeyPressed += (_, args) =>
{
keyPressed!.Enqueue(args.Data.KeyCode);

if (keyPressed!.Count > keysLimitation)
_ = keyPressed.Dequeue();

VerifyKeys();
};

hook.RunAsync();

return this;
}

private void VerifyKeys()
{
var index = 0;

var tmpList = new KeyCode[keysLimitation];

keyPressed!.ForEach(x =>
{
tmpList[index] = x;

++index;

}, true);

foreach (var handler in hotKeyHandlers!.Values)
handler.Invoke(tmpList);
}

public HotKeyManager RegisterHotKeyHandler(string name, Action<KeyCode[]> handler)
{
hotKeyHandlers!.Add(name, handler);

return this;
}

public HotKeyManager UnregisterHotKeyHandler(string name)
{
if (hotKeyHandlers!.TryGetValue(name, out _))
{
hotKeyHandlers.Remove(name);
}

return this;
}
}
13 changes: 6 additions & 7 deletions Managers/WebManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Common.BasicHelper.Core.TaskSystem;
using KitX_Dashboard.Network;
using KitX_Dashboard.Network;
using Serilog;
using System;
using System.Collections.ObjectModel;
Expand All @@ -9,16 +8,16 @@ namespace KitX_Dashboard.Managers;

public class WebManager : IDisposable
{
public WebManager()
{
NetworkInterfaceRegistered = new();
}

internal PluginsServer? pluginsServer;
internal DevicesDiscoveryServer? devicesDiscoveryServer;

internal ObservableCollection<string>? NetworkInterfaceRegistered;

public WebManager()
{
NetworkInterfaceRegistered = new();
}

/// <summary>
/// 开始执行网络相关服务
/// </summary>
Expand Down
Loading

0 comments on commit c939260

Please sign in to comment.