-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.axaml.cs
More file actions
811 lines (713 loc) · 26.1 KB
/
Copy pathMainWindow.axaml.cs
File metadata and controls
811 lines (713 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Platform.Storage;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
namespace SDRIQStreamer.App;
public partial class MainWindow : Window
{
private readonly AppSettingsSession _settingsSession;
private MainWindowViewModel? _subscribedVm;
private bool _firstInstallWizardShownThisSession;
private SmartDeckWindow? _smartDeck;
public MainWindow()
: this(new AppSettingsSession(new AppSettingsStore()))
{
}
public MainWindow(AppSettingsSession settingsSession)
{
_settingsSession = settingsSession;
InitializeComponent();
RestoreWindowPlacement();
DataContextChanged += OnDataContextChanged;
Opened += OnMainWindowOpened;
}
protected override void OnClosing(WindowClosingEventArgs e)
{
if (_subscribedVm is not null)
{
_subscribedVm.PropertyChanged -= OnViewModelPropertyChanged;
_subscribedVm.AudioIndexChangesDetected -= OnAudioIndexChangesDetected;
_subscribedVm.DaxStationConfirmRequested -= OnDaxStationConfirmRequested;
_subscribedVm.StopRunningAppsConfirmRequested -= OnStopRunningAppsConfirmRequested;
_subscribedVm = null;
}
// Close SmartDeck first: its Closing handler writes its own placement
// into the same settings object, and that has to happen before the save
// below rather than during owner-driven teardown afterwards.
_smartDeck?.Close();
_smartDeck = null;
(DataContext as MainWindowViewModel)?.Shutdown();
SaveWindowPlacement();
_settingsSession.Save();
base.OnClosing(e);
}
private void OnDataContextChanged(object? sender, EventArgs e)
{
if (_subscribedVm is not null)
{
_subscribedVm.PropertyChanged -= OnViewModelPropertyChanged;
_subscribedVm.AudioIndexChangesDetected -= OnAudioIndexChangesDetected;
_subscribedVm.DaxStationConfirmRequested -= OnDaxStationConfirmRequested;
_subscribedVm.StopRunningAppsConfirmRequested -= OnStopRunningAppsConfirmRequested;
}
_subscribedVm = DataContext as MainWindowViewModel;
if (_subscribedVm is not null)
{
_subscribedVm.PropertyChanged += OnViewModelPropertyChanged;
_subscribedVm.AudioIndexChangesDetected += OnAudioIndexChangesDetected;
_subscribedVm.DaxStationConfirmRequested += OnDaxStationConfirmRequested;
_subscribedVm.StopRunningAppsConfirmRequested += OnStopRunningAppsConfirmRequested;
}
}
private Task<DaxStationConfirmResult> OnDaxStationConfirmRequested(DaxStationConfirmRequest request)
=> Dispatcher.UIThread.InvokeAsync(() => ShowDaxStationConfirmDialogAsync(request));
private Task<bool> OnStopRunningAppsConfirmRequested(string message)
=> Dispatcher.UIThread.InvokeAsync(() => ShowStopRunningConfirmDialogAsync(message));
/// <summary>
/// Failure sink for the async-void event handlers (issue #50 Phase 3): an
/// exception escaping an async-void method is rethrown on the dispatcher
/// and can take the app down, so each handler catches and reports here
/// instead. Posted because some source events arrive off the UI thread.
/// </summary>
private void ReportHandlerFailure(string action, Exception ex)
{
Dispatcher.UIThread.Post(() =>
(DataContext as MainWindowViewModel)?.AddStreamerStatus($"{action} failed: {ex.Message}"));
}
private async void OnAudioIndexChangesDetected(IReadOnlyList<string> summary)
{
try
{
// Dispatch onto the UI thread; the VM raises on whichever thread the
// DAX-IQ event arrived on. Show the dialog after the current event
// pump tick so the launch sequence's other UI updates settle first.
await Dispatcher.UIThread.InvokeAsync(async () =>
{
if (DataContext is not MainWindowViewModel vm)
return;
await ShowAudioIndexChangedDialogAsync(vm, summary);
});
}
catch (Exception ex)
{
ReportHandlerFailure("Audio device change dialog", ex);
}
}
private async void OnMainWindowOpened(object? sender, EventArgs e)
{
try
{
await EnsureDaxRunningAsync();
TryShowFirstInstallWizard();
}
catch (Exception ex)
{
ReportHandlerFailure("Startup check", ex);
}
}
private async Task EnsureDaxRunningAsync()
{
while (true)
{
if (IsDaxRunning())
{
_subscribedVm?.AddStreamerStatus("DAX.exe is running.");
return;
}
_subscribedVm?.AddStreamerStatus("DAX.exe not found.");
bool retry = await ShowDaxNotRunningDialogAsync();
if (!retry)
return;
}
}
private static bool IsDaxRunning()
{
var procs = Process.GetProcessesByName("DAX");
try { return procs.Length > 0; }
finally { foreach (var p in procs) p.Dispose(); }
}
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(MainWindowViewModel.CwSkimmerExePath) ||
e.PropertyName == nameof(MainWindowViewModel.CwSkimmerIniPath))
{
TryShowFirstInstallWizard();
}
}
private void TryShowFirstInstallWizard()
{
if (_firstInstallWizardShownThisSession)
return;
if (DataContext is not MainWindowViewModel vm)
return;
var settings = _settingsSession.Settings;
if (settings.HasShownSkimmerSetupWizard)
return;
var exePath = vm.CwSkimmerExePath;
var iniPath = vm.CwSkimmerIniPath;
if (string.IsNullOrWhiteSpace(exePath) ||
string.IsNullOrWhiteSpace(iniPath) ||
!File.Exists(exePath) ||
!File.Exists(iniPath))
{
return;
}
if (vm.IsCwSkimmerRunning)
return;
_firstInstallWizardShownThisSession = true;
settings.HasShownSkimmerSetupWizard = true;
Dispatcher.UIThread.Post(async () =>
{
try
{
await ShowResetWizardAsync(vm);
}
catch
{
// Wizard is decorative on first launch; never block startup.
}
});
}
private async void OnBrowseCwSkimmer(object? sender, RoutedEventArgs e)
{
try
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return;
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Select CwSkimmer.exe",
AllowMultiple = false,
FileTypeFilter =
[
new FilePickerFileType("Executable") { Patterns = ["CwSkimmer.exe", "*.exe"] },
new FilePickerFileType("All files") { Patterns = ["*"] }
]
});
if (files.Count > 0 && DataContext is MainWindowViewModel vm)
vm.CwSkimmerExePath = files[0].Path.LocalPath;
}
catch (Exception ex)
{
ReportHandlerFailure("Browse for CwSkimmer.exe", ex);
}
}
private async void OnBrowseCwSkimmerIni(object? sender, RoutedEventArgs e)
{
try
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return;
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Select cwskimmer.ini",
AllowMultiple = false,
FileTypeFilter =
[
new FilePickerFileType("INI file") { Patterns = ["*.ini"] },
new FilePickerFileType("All files") { Patterns = ["*"] }
]
});
if (files.Count > 0 && DataContext is MainWindowViewModel vm)
vm.CwSkimmerIniPath = files[0].Path.LocalPath;
}
catch (Exception ex)
{
ReportHandlerFailure("Browse for cwskimmer.ini", ex);
}
}
private async void OnBrowseDigitalExe(object? sender, RoutedEventArgs e)
{
try
{
if (DataContext is not MainWindowViewModel vm) return;
var exeName = vm.ActiveEngineExeFileName;
var path = await BrowseForExeAsync($"Select {exeName}", exeName, vm.ActiveEngineExePath);
if (path is not null)
vm.ActiveEngineExePath = path;
}
catch (Exception ex)
{
ReportHandlerFailure("Browse for digital engine exe", ex);
}
}
private async Task<string?> BrowseForExeAsync(string title, string preferredExe, string currentPath)
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return null;
// Open the picker in the folder of the currently-configured exe (fixes
// the picker defaulting to Documents when a path is already set).
IStorageFolder? startFolder = null;
var startDir = string.IsNullOrWhiteSpace(currentPath) ? null : Path.GetDirectoryName(currentPath);
if (!string.IsNullOrWhiteSpace(startDir) && Directory.Exists(startDir))
startFolder = await topLevel.StorageProvider.TryGetFolderFromPathAsync(startDir);
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = title,
AllowMultiple = false,
SuggestedStartLocation = startFolder,
FileTypeFilter =
[
new FilePickerFileType("Executable") { Patterns = [preferredExe, "*.exe"] },
new FilePickerFileType("All files") { Patterns = ["*"] }
]
});
return files.Count > 0 ? files[0].Path.LocalPath : null;
}
private void OnOpenSpotTextColorMenu(object? sender, RoutedEventArgs e)
{
OpenSpotColorMenu(sender as Control, isBackground: false);
}
private void OnOpenSpotBackgroundColorMenu(object? sender, RoutedEventArgs e)
{
OpenSpotColorMenu(sender as Control, isBackground: true);
}
private void OpenSpotColorMenu(Control? anchor, bool isBackground)
{
if (anchor is null || DataContext is not MainWindowViewModel vm)
return;
var options = isBackground ? vm.SpotBackgroundColorOptions : vm.SpotColorOptions;
var swatchPanel = new UniformGrid
{
Columns = 4,
Rows = 2,
Margin = new Thickness(1)
};
foreach (var option in options)
{
var selectedOption = option;
var button = new Button
{
Content = CreateColorSwatchHeader(selectedOption.Hex),
Width = 22,
Height = 20,
Padding = new Thickness(0),
Margin = new Thickness(1, 1, 1, 2),
HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Center
};
button.Click += (_, _) =>
{
if (isBackground)
vm.SpotSelectedBackgroundColorOption = selectedOption;
else
vm.SpotSelectedColorOption = selectedOption;
if (FlyoutBase.GetAttachedFlyout(anchor) is Flyout currentFlyout)
currentFlyout.Hide();
};
swatchPanel.Children.Add(button);
}
var flyout = new Flyout
{
Content = swatchPanel,
Placement = PlacementMode.BottomEdgeAlignedLeft
};
flyout.FlyoutPresenterClasses.Add("compact-swatch-flyout");
FlyoutBase.SetAttachedFlyout(anchor, flyout);
flyout.ShowAt(anchor);
}
private static Control CreateColorSwatchHeader(string hex)
{
var fill = Color.TryParse(hex, out var parsed)
? (IBrush)new SolidColorBrush(parsed)
: Brushes.Transparent;
return new Border
{
Width = 18,
Height = 12,
Background = fill,
BorderBrush = Brushes.DimGray,
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(2),
Margin = new Thickness(0),
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
};
}
private void RestoreWindowPlacement()
{
var settings = _settingsSession.Settings;
if (settings.MainWindowWidth is > 0 && settings.MainWindowHeight is > 0)
{
SizeToContent = SizeToContent.Manual;
Width = settings.MainWindowWidth.Value;
Height = settings.MainWindowHeight.Value;
}
if (settings.MainWindowX.HasValue && settings.MainWindowY.HasValue)
{
Position = new PixelPoint(
(int)Math.Round(settings.MainWindowX.Value),
(int)Math.Round(settings.MainWindowY.Value));
}
}
private void SaveWindowPlacement()
{
if (WindowState != WindowState.Normal) return;
var settings = _settingsSession.Settings;
settings.MainWindowX = Position.X;
settings.MainWindowY = Position.Y;
settings.MainWindowWidth = Bounds.Width;
settings.MainWindowHeight = Bounds.Height;
}
// Issue #59: one SmartDeck window per session, reactivated rather than
// duplicated if the operator clicks the button again.
private void OnOpenSmartDeck(object? sender, RoutedEventArgs e)
{
if (_smartDeck is not null)
{
_smartDeck.Activate();
return;
}
if (DataContext is not MainWindowViewModel vm) return;
var deck = new SmartDeckWindow(vm.CreateSmartDeckViewModel(_settingsSession.Settings), _settingsSession.Settings);
deck.Closed += (_, _) => _smartDeck = null;
_smartDeck = deck;
deck.Show(this);
}
// One button rather than a Light/Dark pair or a dropdown: two options with
// no "follow the OS" third state is a toggle, and the Launch header row is
// tight. Applied live via DynamicResource, so every open window (SmartDeck
// included) repaints on the press; the setting is written to the same
// in-memory session everything else uses and saved on shutdown.
private void OnToggleTheme(object? sender, RoutedEventArgs e)
{
var settings = _settingsSession.Settings;
settings.ThemeMode = settings.ThemeMode == AppTheme.Dark ? AppTheme.Light : AppTheme.Dark;
App.ApplyTheme(settings.ThemeMode);
}
private void OnOpenSetupWizard(object? sender, RoutedEventArgs e)
{
var viewer = new SetupWizardWindow();
if (VisualRoot is Window owner)
viewer.Show(owner);
else
viewer.Show();
}
private void OnOpenSupport(object? sender, RoutedEventArgs e)
{
const string issuesUrl = "https://github.com/cdub89/SmartStreamer4/issues";
try
{
Process.Start(new ProcessStartInfo
{
FileName = issuesUrl,
UseShellExecute = true
});
}
catch
{
// Ignore browser launch failures to avoid disrupting app flow.
}
}
private async void OnResetChannelConfigRequested(object? sender, RoutedEventArgs e)
{
try
{
if (DataContext is not MainWindowViewModel vm)
return;
if (vm.IsCwSkimmerRunning)
{
await ShowResetBlockedDialogAsync();
return;
}
await ShowResetWizardAsync(vm);
}
catch (Exception ex)
{
ReportHandlerFailure("Reset channel config", ex);
}
}
private async Task ShowResetWizardAsync(MainWindowViewModel vm)
{
var wizard = new ResetSkimmerWizardWindow(vm, _settingsSession.Settings);
await wizard.ShowDialog(this);
}
private async Task ShowResetBlockedDialogAsync()
{
var message = new TextBlock
{
Text = "CW Skimmer is currently running.\n\nStop all CW Skimmer instances before resetting channel INI files.",
TextWrapping = TextWrapping.Wrap,
MaxWidth = 400
};
var okButton = new Button
{
Content = "OK",
MinWidth = 80,
IsDefault = true
};
var dialog = new Window
{
Title = "Reset Blocked",
Width = 440,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = new StackPanel
{
Margin = new Thickness(16),
Spacing = 14,
Children =
{
message,
new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
Children = { okButton }
}
}
}
};
okButton.Click += (_, _) => dialog.Close();
await dialog.ShowDialog(this);
}
private async Task<bool> ShowDaxNotRunningDialogAsync()
{
var message = new TextBlock
{
Text = "Please start or ensure DAX is running",
TextWrapping = TextWrapping.Wrap,
MaxWidth = 400
};
bool retryClicked = false;
var retryButton = new Button
{
Content = "Retry",
MinWidth = 80
};
var ignoreButton = new Button
{
Content = "Ignore",
MinWidth = 80,
IsDefault = true,
IsCancel = true
};
var dialog = new Window
{
Title = "Dax.exe Not Running Error",
Width = 440,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = new StackPanel
{
Margin = new Thickness(16),
Spacing = 14,
Children =
{
message,
new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
Spacing = 8,
Children = { retryButton, ignoreButton }
}
}
}
};
retryButton.Click += (_, _) =>
{
retryClicked = true;
dialog.Close();
};
ignoreButton.Click += (_, _) => dialog.Close();
await dialog.ShowDialog(this);
return retryClicked;
}
private async Task ShowAudioIndexChangedDialogAsync(MainWindowViewModel vm, IReadOnlyList<string> changeSummary)
{
var lines = new List<string>
{
"Audio Device Numbers may have changed:",
string.Empty
};
lines.AddRange(changeSummary.Select(s => " " + s));
lines.AddRange(new[]
{
string.Empty,
"Please rerun the CW Skimmer Config Setup Wizard.",
string.Empty,
"Note: WDM index changes are not auto-detected. If you've upgraded SmartSDR or DAX, re-verify WDM values in the wizard too."
});
var message = new TextBlock
{
Text = string.Join(Environment.NewLine, lines),
TextWrapping = TextWrapping.Wrap,
MaxWidth = 460
};
var setupWizardButton = new Button
{
Content = "Set Up Wizard",
MinWidth = 120
};
var ignoreButton = new Button
{
Content = "Ignore",
MinWidth = 80,
IsDefault = true,
IsCancel = true
};
var dialog = new Window
{
Title = "Audio device numbers changed",
Width = 520,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = new StackPanel
{
Margin = new Thickness(16),
Spacing = 14,
Children =
{
message,
new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
Spacing = 8,
Children = { setupWizardButton, ignoreButton }
}
}
}
};
bool setupWizardClicked = false;
setupWizardButton.Click += (_, _) =>
{
setupWizardClicked = true;
dialog.Close();
};
ignoreButton.Click += (_, _) => dialog.Close();
await dialog.ShowDialog(this);
if (!setupWizardClicked)
return;
// Stop CW Skimmer as a convenience — the wizard refuses to run while
// Skimmer is up (channel INIs are being held open). The operator
// already signalled intent by clicking "Set Up Wizard"; saving them
// a manual stop-each-channel round trip.
vm.StopAllCwSkimmerInstances();
await ShowResetWizardAsync(vm);
}
private async Task<bool> ShowStopRunningConfirmDialogAsync(string messageText)
{
var message = new TextBlock
{
Text = messageText,
TextWrapping = TextWrapping.Wrap,
MaxWidth = 400
};
var switchButton = new Button { Content = "Stop & Continue", MinWidth = 120 };
var cancelButton = new Button { Content = "Cancel", MinWidth = 80, IsDefault = true, IsCancel = true };
var dialog = new Window
{
Title = "Confirm",
Width = 440,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = new StackPanel
{
Margin = new Thickness(16),
Spacing = 14,
Children =
{
message,
new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
Spacing = 8,
Children = { switchButton, cancelButton }
}
}
}
};
var proceed = false;
switchButton.Click += (_, _) => { proceed = true; dialog.Close(); };
cancelButton.Click += (_, _) => dialog.Close();
await dialog.ShowDialog(this);
return proceed;
}
private async Task<DaxStationConfirmResult> ShowDaxStationConfirmDialogAsync(DaxStationConfirmRequest request)
{
// Issue #39 (2026-05-18): same-radio multi-station with same DAX-IQ
// channel produces silently-wrong audio at CW Skimmer when DAX-the-app
// is bound to the wrong station. We cannot query DAX's binding via
// FlexLib so we ask the operator to verify it manually before launching.
var messageText = string.Join(Environment.NewLine, new[]
{
$"DAX-IQ ch {request.DaxIqChannel} also assigned to {request.OtherStation}.",
string.Empty,
$"In the SmartSDR DAX application, select {request.OwnStation} to launch CW Skimmer properly.",
string.Empty,
"Click Start once you have updated the station in the SmartSDR DAX application.",
});
var message = new TextBlock
{
Text = messageText,
TextWrapping = TextWrapping.Wrap,
MaxWidth = 460,
FontSize = 13
};
var startButton = new Button
{
Content = "Start",
MinWidth = 80
};
var cancelButton = new Button
{
Content = "Cancel",
MinWidth = 80,
IsDefault = true,
IsCancel = true
};
var dialog = new Window
{
Title = "DAX-IQ Channel Conflict",
Width = 520,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = new StackPanel
{
Margin = new Thickness(16),
Spacing = 14,
Children =
{
message,
new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
Spacing = 8,
Children = { startButton, cancelButton }
}
}
}
};
var result = DaxStationConfirmResult.Cancel;
startButton.Click += (_, _) =>
{
result = DaxStationConfirmResult.Start;
dialog.Close();
};
cancelButton.Click += (_, _) =>
{
result = DaxStationConfirmResult.Cancel;
dialog.Close();
};
await dialog.ShowDialog(this);
return result;
}
}