Avalonia-Grundgeruest: plattformneutrale App laeuft (Shell + erstes Fenster)
Neues Projekt src/PolyTrader.App.Avalonia (net10.0, Avalonia 12.1.1, LiveCharts2 2.0.5) - laeuft unter Windows und Linux aus derselben Quelle. Enthalten: - Program.cs mit bewusst getrenntem Aufbau: BuildHost() stellt Persistenz, Dienste und Module ohne jeden UI-Bezug zusammen, erst Main haengt Avalonia daran. Damit ist der kopflose Linux-Betrieb (--headless, Stufe L2) ohne Umbau erreichbar - der Schalter ist bereits drin. - AvaloniaUiHost als IModuleUiHost: gleiche Semantik wie die WinForms-Shell (ein Fenster je View, offene nach vorn holen, alles maximiert). - Fenster-Menueleiste vollstaendig DEKLARATIV (Controls/WindowMenuBar.axaml + ItemsSource auf WindowMenuModel.Entries). Loest die alte Fassung ab, die menu.Items zur Laufzeit leerte und neu befuellte - genau der Punkt, den die neue Layout-Regel verbietet. - ViewIcons fuer Avalonia: dieselben Schluessel und dieselben PNGs wie zuvor, Core und Module bleiben unveraendert. - LauncherWindow, JobsWindow, ShutdownConfirmWindow (inkl. der 10-Sekunden-Sperre). - --smoke-ui als Nachfolger der WinForms-Konstruktionspruefung; startet den Host bewusst NICHT, damit ein reiner UI-Test nicht die Trading-Engine gegen echte Endpunkte anwirft. Dabei aufgeraeumt: - JobManager.Jobs: BindingList -> ObservableCollection. BindingList implementiert kein INotifyCollectionChanged; neu registrierte Jobs waeren in Avalonia unsichtbar geblieben. - StartupHydrationService aufgeteilt in CoreStateHydrationService (Core: Accounts + Demo-Positionen) und CopyTradingHydrationService (Modul: Settings + Trader). Behebt einen latenten Fehler: bei deaktiviertem Copytrading-Modul waeren die Accounts gar nicht mehr hydriert worden, obwohl sie zum Core gehoeren. Verifiziert: Solution baut, 442 Tests gruen, --smoke-ui gruen, die App laeuft real mit Fenster und allen Trading-Diensten (Market-Sync, Master-Trader-Analyse, RF-Scanner), und publisht fuer linux-x64. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PolyTrader.App.Avalonia.Shell;
|
||||
using PolyTrader.Core.Modularity;
|
||||
using PolyTraderSharp;
|
||||
|
||||
namespace PolyTrader.App.Avalonia.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// „Startleiste" der Anwendung – Gegenstück zur bisherigen LauncherForm. Öffnet die Fenster,
|
||||
/// spiegelt deren Offen-Status und zeigt die Kernkennzahlen in der Statusleiste.
|
||||
/// Layout vollständig in LauncherWindow.axaml.
|
||||
/// </summary>
|
||||
public partial class LauncherWindow : Window
|
||||
{
|
||||
private readonly AvaloniaUiHost _uiHost;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly TradingState _state;
|
||||
private readonly DispatcherTimer _statusTimer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||
private readonly ObservableCollection<WindowMenuEntry> _windowButtons = new();
|
||||
|
||||
public LauncherWindow() => AvaloniaXamlLoader.Load(this);
|
||||
|
||||
public LauncherWindow(AvaloniaUiHost uiHost, IServiceProvider services) : this()
|
||||
{
|
||||
_uiHost = uiHost;
|
||||
_services = services;
|
||||
_state = services.GetRequiredService<TradingState>();
|
||||
|
||||
// currentViewId == null => dies ist der Launcher (rechte Menueaktion "Beenden").
|
||||
this.FindControl<Controls.WindowMenuBar>("menuBar")!.Attach(uiHost, null, this);
|
||||
|
||||
this.FindControl<ItemsControl>("windowButtons")!.ItemsSource = _windowButtons;
|
||||
RebuildWindowButtons();
|
||||
_uiHost.OpenStateChanged += OnOpenStateChanged;
|
||||
|
||||
this.FindControl<Button>("btnLiveTrading")!.Click += (_, _) =>
|
||||
{
|
||||
_state.LiveTradingMode = Next(_state.LiveTradingMode);
|
||||
UpdateTradingToggles();
|
||||
};
|
||||
this.FindControl<Button>("btnDemoTrading")!.Click += (_, _) =>
|
||||
{
|
||||
_state.DemoTradingMode = Next(_state.DemoTradingMode);
|
||||
UpdateTradingToggles();
|
||||
};
|
||||
|
||||
_statusTimer.Tick += (_, _) => UpdateStatus();
|
||||
_statusTimer.Start();
|
||||
UpdateStatus();
|
||||
|
||||
// Schliessen des Launchers laeuft ueber dieselbe Sicherheitsabfrage wie "Beenden".
|
||||
Closing += (_, e) =>
|
||||
{
|
||||
if (_uiHost.ShutdownConfirmed) return;
|
||||
e.Cancel = true;
|
||||
Dispatcher.UIThread.Post(_uiHost.RequestShutdown);
|
||||
};
|
||||
Closed += (_, _) =>
|
||||
{
|
||||
_statusTimer.Stop();
|
||||
_uiHost.OpenStateChanged -= OnOpenStateChanged;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Dreistufiger Wechsel wie bisher: Inactive -> SellOnly -> Active -> Inactive.</summary>
|
||||
private static TradingMode Next(TradingMode mode) => mode switch
|
||||
{
|
||||
TradingMode.Inactive => TradingMode.SellOnly,
|
||||
TradingMode.SellOnly => TradingMode.Active,
|
||||
_ => TradingMode.Inactive
|
||||
};
|
||||
|
||||
private void OnOpenStateChanged()
|
||||
{
|
||||
if (Dispatcher.UIThread.CheckAccess()) RebuildWindowButtons();
|
||||
else Dispatcher.UIThread.Post(RebuildWindowButtons);
|
||||
}
|
||||
|
||||
private void RebuildWindowButtons()
|
||||
{
|
||||
_windowButtons.Clear();
|
||||
foreach (var view in _uiHost.Views.OrderBy(v => v.Order).ThenBy(v => v.Title))
|
||||
{
|
||||
string id = view.Id;
|
||||
bool open = _uiHost.IsOpen(id);
|
||||
_windowButtons.Add(new WindowMenuEntry
|
||||
{
|
||||
Title = view.Title,
|
||||
Icon = ViewIcons.Resolve(view.IconKey),
|
||||
IsCurrent = open,
|
||||
IsChecked = open,
|
||||
Command = new RelayCommand(() => _uiHost.OpenView(id))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTradingToggles()
|
||||
{
|
||||
Apply(this.FindControl<Button>("btnLiveTrading")!, "LiveTrading", _state.LiveTradingMode);
|
||||
Apply(this.FindControl<Button>("btnDemoTrading")!, "DemoTrading", _state.DemoTradingMode);
|
||||
|
||||
// Farbgebung aus der WinForms-Oberflaeche uebernommen (LightGreen/Orange/IndianRed).
|
||||
static void Apply(Button btn, string label, TradingMode mode)
|
||||
{
|
||||
(string text, Color color) = mode switch
|
||||
{
|
||||
TradingMode.Active => ($"{label} (AKTIV)", Colors.LightGreen),
|
||||
TradingMode.SellOnly => ($"{label} (SELL-ONLY)", Colors.Orange),
|
||||
_ => ($"{label} (DEAKTIVIERT)", Colors.IndianRed)
|
||||
};
|
||||
btn.Content = text;
|
||||
btn.Background = new SolidColorBrush(color);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStatus()
|
||||
{
|
||||
string trading = _state.GlobalTradingPaused
|
||||
? "Pausiert"
|
||||
: $"Live={_state.LiveTradingMode} / Demo={_state.DemoTradingMode}";
|
||||
this.FindControl<TextBlock>("lblTrading")!.Text = $"Trading: {trading}";
|
||||
|
||||
int moduleCount = _services.GetServices<IPolyTraderModule>().Count();
|
||||
this.FindControl<TextBlock>("lblModules")!.Text = $"Module: {moduleCount}";
|
||||
|
||||
this.FindControl<TextBlock>("lblRatelimit")!.Text =
|
||||
$"API: {(_state.IsAlchemyHealthy ? "WSS aktiv" : "Polling")}";
|
||||
|
||||
UpdateTradingToggles();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user