Modules
This commit is contained in:
10
ModuleWeather/MainWindow.axaml
Normal file
10
ModuleWeather/MainWindow.axaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="ModuleWeather.WeatherView">
|
||||||
|
<StackPanel Margin="20" Spacing="10" Background="#2b2b2b">
|
||||||
|
<TextBlock Name="StatusText" Text="Введите город:" Foreground="White"/>
|
||||||
|
<TextBox Name="CityInput" Watermark="Например: Москва"/>
|
||||||
|
<Button Content="Узнать погоду" Click="GetWeatherButton_Click"
|
||||||
|
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
22
ModuleWeather/MainWindow.axaml.cs
Normal file
22
ModuleWeather/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
|
namespace ModuleWeather;
|
||||||
|
|
||||||
|
public partial class WeatherView : UserControl
|
||||||
|
{
|
||||||
|
public WeatherView() => InitializeComponent();
|
||||||
|
|
||||||
|
private void GetWeatherButton_Click(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var city = this.FindControl<TextBox>("CityInput")?.Text;
|
||||||
|
var status = this.FindControl<TextBlock>("StatusText");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(city)) {
|
||||||
|
status.Text = "Ошибка: введите город";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
status.Text = $"В городе {city} сейчас +20°C"; // Тут могла быть логика API
|
||||||
|
}
|
||||||
|
}
|
||||||
40
ModuleWeather/Module.cs
Normal file
40
ModuleWeather/Module.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace ModuleWeather;
|
||||||
|
|
||||||
|
public class WeatherModule
|
||||||
|
{
|
||||||
|
public string Name => "Прогноз Погоды";
|
||||||
|
|
||||||
|
public string[] GetCommands() => new[] { "ShowWeather", "Ping" };
|
||||||
|
|
||||||
|
public object Execute(string command, object[] args)
|
||||||
|
{
|
||||||
|
switch (command)
|
||||||
|
{
|
||||||
|
case "ShowWeather":
|
||||||
|
// args[0] — это родительское окно из Ядра
|
||||||
|
var parentWindow = args != null && args.Length > 0 ? args[0] as Window : null;
|
||||||
|
|
||||||
|
var win = new Window
|
||||||
|
{
|
||||||
|
Title = "Окно Погоды",
|
||||||
|
Content = new WeatherView(), // Вставляем наш контрол
|
||||||
|
Width = 350,
|
||||||
|
Height = 250,
|
||||||
|
WindowStartupLocation = WindowStartupLocation.CenterOwner
|
||||||
|
};
|
||||||
|
|
||||||
|
if (parentWindow != null) win.Show(parentWindow);
|
||||||
|
else win.Show();
|
||||||
|
|
||||||
|
return "Окно открыто успешно";
|
||||||
|
|
||||||
|
case "Ping":
|
||||||
|
return "Pong! Модуль погоды активен.";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Команда не найдена";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
ModuleWeather/ModuleWeather.csproj
Normal file
24
ModuleWeather/ModuleWeather.csproj
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\VisionAsist.SDK\VisionAsist.SDK.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="MainWindow.axaml.cs">
|
||||||
|
<DependentUpon>MainWindow.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||||
|
<PackageReference Include="Avalonia.Desktop" Version="11.3.12" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
8
VisionAsist.SDK/IModule.cs
Normal file
8
VisionAsist.SDK/IModule.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VisionAsist.SDK;
|
||||||
|
|
||||||
|
public interface IModule
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
string[] GetCommands();
|
||||||
|
object Execute(string command, object[] args);
|
||||||
|
}
|
||||||
9
VisionAsist.SDK/VisionAsist.SDK.csproj
Normal file
9
VisionAsist.SDK/VisionAsist.SDK.csproj
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionAsist", "VisionAsist\VisionAsist.csproj", "{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionAsist", "VisionAsist\VisionAsist.csproj", "{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionAsist.SDK", "VisionAsist.SDK\VisionAsist.SDK.csproj", "{9E547157-DA01-40FB-9DB1-67A1C310E3F1}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleWeather", "ModuleWeather\ModuleWeather.csproj", "{5103146A-34FD-4431-856E-AB78EF523C03}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -12,5 +16,13 @@ Global
|
|||||||
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C5BD9C58-AE7A-4BBA-8700-1E71F48DBCA0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9E547157-DA01-40FB-9DB1-67A1C310E3F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9E547157-DA01-40FB-9DB1-67A1C310E3F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9E547157-DA01-40FB-9DB1-67A1C310E3F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9E547157-DA01-40FB-9DB1-67A1C310E3F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{5103146A-34FD-4431-856E-AB78EF523C03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5103146A-34FD-4431-856E-AB78EF523C03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5103146A-34FD-4431-856E-AB78EF523C03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5103146A-34FD-4431-856E-AB78EF523C03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using VisionAsist.SDK;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
namespace VisionAsist.Models;
|
namespace VisionAsist.Models;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Core
|
public class Core
|
||||||
{
|
{
|
||||||
public static TrigerCore triger = new();
|
public static TrigerCore triger = new();
|
||||||
@@ -17,8 +21,7 @@ public class Core
|
|||||||
// Подписываемся на событие новых слов
|
// Подписываемся на событие новых слов
|
||||||
triger.OnRecognized += word =>
|
triger.OnRecognized += word =>
|
||||||
{
|
{
|
||||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
|
||||||
Console.InputEncoding = System.Text.Encoding.UTF8;
|
|
||||||
Console.WriteLine(word); // печатаем сразу, как распознано
|
Console.WriteLine(word); // печатаем сразу, как распознано
|
||||||
TextAsist = triger.RecognizedText;
|
TextAsist = triger.RecognizedText;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using VisionAsist.Models;
|
||||||
|
using VisionAsist.SDK;
|
||||||
|
|
||||||
namespace VisionAsist.ViewModels;
|
namespace VisionAsist.ViewModels;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -39,6 +43,29 @@ public class SettingsViewModel : ViewModelBase
|
|||||||
|
|
||||||
private void OpenSettings(string moduleName)
|
private void OpenSettings(string moduleName)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Нажата кнопка модуля: {moduleName}");
|
string dllPath = Path.Combine(AppContext.BaseDirectory, "Modules", moduleName, "Module.dll");
|
||||||
|
if (File.Exists(dllPath))
|
||||||
|
{
|
||||||
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||||
|
Console.InputEncoding = System.Text.Encoding.UTF8;
|
||||||
|
Assembly assembly = Assembly.LoadFrom(dllPath);
|
||||||
|
var type = assembly.GetTypes().FirstOrDefault(t =>
|
||||||
|
typeof(IModule).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
// 4. Создаем экземпляр класса (WeatherModule)
|
||||||
|
var module = (IModule)Activator.CreateInstance(type)!;
|
||||||
|
Console.WriteLine($"Успешно загружен модуль: {module.Name}");
|
||||||
|
|
||||||
|
// 5. Запускаем команду и передаем текущее окно (this) в качестве родителя
|
||||||
|
var result = module.Execute("ShowWeather", new object[] { this });
|
||||||
|
Console.WriteLine($"Ответ модуля: {result}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("В DLL не найден класс, реализующий VisionAsist.SDK.IModule!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.3.11"/>
|
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.11"/>
|
<PackageReference Include="Avalonia.Desktop" Version="11.3.12" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.11"/>
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.12" />
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.11"/>
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.12" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.11">
|
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.12">
|
||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -25,4 +25,8 @@
|
|||||||
<PackageReference Include="NAudio" Version="2.3.0" />
|
<PackageReference Include="NAudio" Version="2.3.0" />
|
||||||
<PackageReference Include="Vosk" Version="0.3.38" />
|
<PackageReference Include="Vosk" Version="0.3.38" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\VisionAsist.SDK\VisionAsist.SDK.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user