fix keyboard catch, fix loading

refactoring
This commit is contained in:
Alex Bezdieniezhnykh
2024-11-25 13:03:46 +02:00
parent b61bed3b51
commit 30b9b9aa80
18 changed files with 88 additions and 117 deletions
+37 -27
View File
@@ -1,7 +1,7 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Azaion.Annotator;
@@ -13,7 +13,6 @@ using Azaion.Common.DTO.Config;
using Azaion.Common.Extensions;
using Azaion.Common.Services;
using Azaion.Dataset;
using Azaion.Suite.Services.DTO;
using CommandLine;
using LibVLCSharp.Shared;
using MediatR;
@@ -33,24 +32,28 @@ public partial class App
private readonly ILogger<App> _logger;
private readonly IMediator _mediator;
private static readonly List<string> EncryptedResources =
[
"Azaion.Annotator.dll",
"Azaion.Dataset.dll"
];
private static readonly IResourceLoader? ResourceLoader = new ResourceLoader("", "", null!, null!);
//Authorize to api and
private static readonly IResourceLoader ResourceLoader;
static App()
{
//Load encrypted dlls
var result = Parser.Default.ParseArguments<SuiteCommandLineOptions>(Environment.GetCommandLineArgs());
new ConfigUpdater().CheckConfig();
var result = Parser.Default.ParseArguments<ApiCredentials>(Environment.GetCommandLineArgs());
if (result.Errors.Any())
return;
return;
var apiCreds = result.Value;
ResourceLoader = new ResourceLoader(CreateApiClient(apiCreds), apiCreds);
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResourceLoader.LoadAssembly(args.Name);
}
private static AzaionApiClient CreateApiClient(ApiCredentials credentials)
{
ApiConfig apiConfig;
try
{
if (File.Exists(Constants.CONFIG_PATH))
if (!File.Exists(Constants.CONFIG_PATH))
throw new FileNotFoundException(Constants.CONFIG_PATH);
var configStr = File.ReadAllText(Constants.CONFIG_PATH);
apiConfig = JsonConvert.DeserializeObject<AppConfig>(configStr)!.ApiConfig;
@@ -70,19 +73,9 @@ public partial class App
BaseAddress = new Uri(apiConfig.Url),
Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds)
});
var email = result.Value.Email;
var password = result.Value.Password;
api.Login(email, password);
ResourceLoader = new ResourceLoader(email, password, api, new HardwareService());
foreach (var resource in EncryptedResources)
{
var stream = ResourceLoader.Load(resource).GetAwaiter().GetResult();
Assembly.Load(stream.ToArray());
}
new ConfigUpdater().CheckConfig();
api.EnterCredentials(credentials);
return api;
}
public App()
@@ -104,7 +97,7 @@ public partial class App
{
services.AddSingleton<MainSuite>();
services.AddSingleton<IHardwareService, HardwareService>();
services.AddSingleton<IResourceLoader>(ResourceLoader!);
services.AddSingleton(ResourceLoader);
services.Configure<AppConfig>(context.Configuration);
services.ConfigureSection<ApiConfig>(context.Configuration);
@@ -170,10 +163,27 @@ public partial class App
private void GlobalClick(object sender, RoutedEventArgs e)
{
var args = (KeyEventArgs)e;
var keyEvent = new KeyEvent(sender, args, (sender as FrameworkElement).GetParentWindow());
var windowEnum = GetParentWindow(sender as FrameworkElement);
if (windowEnum == WindowEnum.None)
return;
var keyEvent = new KeyEvent(sender, args, windowEnum);
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
}
private WindowEnum GetParentWindow(FrameworkElement? element)
{
while (element != null && element is not TabItem)
{
element = element.Parent as FrameworkElement;
}
if (element is not TabItem || element.Tag == null)
return WindowEnum.None;
return (WindowEnum)element.Tag;
}
protected override async void OnExit(ExitEventArgs e)
{
base.OnExit(e);
+1 -1
View File
@@ -7,4 +7,4 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
)]
+1 -1
View File
@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Title="MainSuite" Height="450" Width="800">
Title="Azaion Оператор" Height="450" Width="800">
<Grid Background="Black">
<TabControl Name="MainTabControl"
TabStripPlacement="Left"
+6 -1
View File
@@ -57,6 +57,10 @@ public partial class MainSuite
foreach (var azaionModule in _modules)
{
var window = (_sp.GetRequiredService(azaionModule.MainWindowType) as Window)!;
window.Height = 0;
window.Width = 0;
window.Show();
window.Hide();
_openedWindows.Add(window);
var icon = new SvgViewbox
{
@@ -78,7 +82,8 @@ public partial class MainSuite
Content = window.Content,
Background = Brushes.Black,
Foreground = Brushes.White,
Cursor = Cursors.Hand
Cursor = Cursors.Hand,
Tag = azaionModule.WindowEnum
};
MainTabControl.Items.Add(tabItem);
}
-12
View File
@@ -1,12 +0,0 @@
using CommandLine;
namespace Azaion.Suite.Services.DTO;
public class SuiteCommandLineOptions
{
[Option('e', "email", Required = true, HelpText = "The email for authorization.")]
public string Email { get; set; } = null!;
[Option('p', "password", Required = true, HelpText = "The password for authorization.")]
public string Password { get; set; } = null!;
}