using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; using Avalonia.Platform.Storage; using Avalonia.Threading; namespace Lumi.Companion.App; public partial class MainWindow : Window { private readonly CompanionRuntime _runtime; private readonly CompanionSettingsStore _settings; private bool _allowExit; private bool _testPassed; private bool _renderingSources; public MainWindow() : this(CreateDefaultServices()) { } private MainWindow((CompanionRuntime Runtime, CompanionSettingsStore Settings) services) : this(services.Runtime, services.Settings) { } public MainWindow(CompanionRuntime runtime, CompanionSettingsStore settings) { _runtime = runtime; _settings = settings; InitializeComponent(); WireActions(); RenderState(runtime.State); RenderTestStages(runtime.TestStages); Closing += OnClosing; runtime.StateChanged += state => Dispatcher.UIThread.Post(() => RenderState(state)); runtime.TestStagesChanged += stages => Dispatcher.UIThread.Post(() => RenderTestStages(stages)); runtime.ObsSourcesChanged += sources => Dispatcher.UIThread.Post(() => RenderSources(sources)); runtime.CaptionReceived += (text, simulated) => Dispatcher.UIThread.Post(() => { if (simulated) SimulatedCaption.Text = text; }); runtime.LogAdded += line => Dispatcher.UIThread.Post(() => AddLog(line)); settings.Changed += value => Dispatcher.UIThread.Post(() => RenderSettings(value)); } private void WireActions() { foreach (var button in Navigation.Children.OfType