From cc029121641c4bfd0b077d89cb0a1a53a168c873 Mon Sep 17 00:00:00 2001 From: Pete Brown Date: Mon, 17 Feb 2025 00:59:14 -0500 Subject: [PATCH 1/2] More settings app work --- .../Endpoints/APP/EndpointsAppViewModel.cs | 2 +- .../BLE10/EndpointsBle10ViewModel.cs | 2 +- .../Endpoints/DIAG/EndpointsDiagViewModel.cs | 2 +- .../Endpoints/KS/EndpointsKSViewModel.cs | 2 +- .../Endpoints/KSA/EndpointsKsaViewModel.cs | 2 +- .../Endpoints/LOOP/EndpointsLoopPage.xaml | 11 ++-- .../Endpoints/LOOP/EndpointsLoopPage.xaml.cs | 59 ++++++++++++++++--- .../Endpoints/LOOP/EndpointsLoopViewModel.cs | 33 +++++++++++ .../NET2UDP/EndpointsNet2UdpViewModel.cs | 2 +- .../SingleTransportEndpointViewModelBase.cs | 12 +--- .../ViewModels/HomeViewModel.cs | 30 ++++++++-- .../Views/HomePage.xaml | 8 ++- 12 files changed, 130 insertions(+), 35 deletions(-) diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/APP/EndpointsAppViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/APP/EndpointsAppViewModel.cs index 06d22127..0a8fea69 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/APP/EndpointsAppViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/APP/EndpointsAppViewModel.cs @@ -15,7 +15,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsAppViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsAppViewModel : SingleTransportEndpointViewModelBase { public EndpointsAppViewModel(INavigationService navigationService) : base("APP", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/BLE10/EndpointsBle10ViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/BLE10/EndpointsBle10ViewModel.cs index df1fef36..b1995217 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/BLE10/EndpointsBle10ViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/BLE10/EndpointsBle10ViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsBle10ViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsBle10ViewModel : SingleTransportEndpointViewModelBase { public EndpointsBle10ViewModel(INavigationService navigationService) : base("BLE10MS", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/DIAG/EndpointsDiagViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/DIAG/EndpointsDiagViewModel.cs index 8133561e..5a8725d9 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/DIAG/EndpointsDiagViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/DIAG/EndpointsDiagViewModel.cs @@ -15,7 +15,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsDiagViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsDiagViewModel : SingleTransportEndpointViewModelBase { public EndpointsDiagViewModel(INavigationService navigationService) : base("DIAG", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KS/EndpointsKSViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KS/EndpointsKSViewModel.cs index 4da5bb3d..7a992f64 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KS/EndpointsKSViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KS/EndpointsKSViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsKSViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsKSViewModel : SingleTransportEndpointViewModelBase { public EndpointsKSViewModel(INavigationService navigationService) : base("KS", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KSA/EndpointsKsaViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KSA/EndpointsKsaViewModel.cs index 3b6e6428..eb9e1dd3 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KSA/EndpointsKsaViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/KSA/EndpointsKsaViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsKsaViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsKsaViewModel : SingleTransportEndpointViewModelBase { public EndpointsKsaViewModel(INavigationService navigationService) : base("KSA", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml index ce5f57a0..5433b147 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml @@ -39,11 +39,11 @@ Click="CreateNewLoopbackPair_Click"/> - + - + @@ -68,6 +68,8 @@ + + 800 800 - + - + @@ -153,6 +155,7 @@ + diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml.cs index 8b0f7775..407b7380 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopPage.xaml.cs @@ -15,6 +15,8 @@ using Microsoft.Midi.Settings.Contracts.Services; using Microsoft.Midi.Settings.Controls; using Microsoft.Midi.Settings.ViewModels; +using Microsoft.Midi.Settings.Contracts.ViewModels; +using Microsoft.UI.Dispatching; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -40,29 +42,72 @@ public EndpointsLoopPage() ViewModel = App.GetService(); _loggingService = App.GetService(); - Loaded += DevicesPage_Loaded; + ViewModel.ShowCreateDialog += ViewModel_ShowCreateDialog; + + Loaded += Page_Loaded; + Unloaded += Page_Unloaded; InitializeComponent(); } - private void DevicesPage_Loaded(object sender, RoutedEventArgs e) + bool m_showCreateDialog = false; + + private void ViewModel_ShowCreateDialog(object? sender, EventArgs e) + { + m_showCreateDialog = true; + } + + + private void Page_Unloaded(object sender, RoutedEventArgs e) + { + ViewModel.ShowCreateDialog -= ViewModel_ShowCreateDialog; + } + private void Page_Loaded(object sender, RoutedEventArgs e) { ViewModel.DispatcherQueue = this.DispatcherQueue; ViewModel.RefreshDeviceCollection(); - } + if (m_showCreateDialog) + { + // showing the dialog fails if it is attempted before Loaded has completed + // as a result, we set a flag in the event from the VM and then + // show it here, in loaded. Not my favorite code. + + DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, async () => + { + var result = await Dialog_CreateLoopbackEndpoints.ShowAsync(); + }); + + m_showCreateDialog = false; + } - // work around WinUI binding bug - private void MidiEndpointDeviceListItemControl_Loaded(object sender, RoutedEventArgs e) - { - ((MidiEndpointDeviceListItemControl)sender).ViewDeviceDetailsCommand = ViewModel.ViewDeviceDetailsCommand; } private async void CreateNewLoopbackPair_Click(object sender, RoutedEventArgs e) { var result = await Dialog_CreateLoopbackEndpoints.ShowAsync(); } + + + + //public void OnNavigatedFrom() + //{ + //} + + //public void OnNavigatedTo(object parameter) + //{ + // if (parameter != null && ((string)parameter).ToLower() == "create") + // { + // DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, async () => + // { + // var result = await Dialog_CreateLoopbackEndpoints.ShowAsync(); + // }); + // } + //} + + + } } diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopViewModel.cs index a24424d9..91c026bf 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/LOOP/EndpointsLoopViewModel.cs @@ -6,6 +6,7 @@ using Microsoft.Midi.Settings.Services; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Markup; using Microsoft.Windows.Devices.Midi2.Endpoints.Loopback; using System; using System.Collections.Generic; @@ -29,6 +30,11 @@ public partial class EndpointsLoopViewModel : SingleTransportEndpointViewModelBa { private IMidiConfigFileService m_midiConfigFileService; + public ICommand ShowCreateLoopbackPairsDialogCommand + { + get; private set; + } + public ICommand CreateLoopbackPairsCommand { get; private set; @@ -265,6 +271,33 @@ public EndpointsLoopViewModel(INavigationService navigationService, IMidiConfigF CreateNewLoopbackEndpoints(); }); + + //ShowCreateLoopbackPairsDialogCommand = new RelayCommand( + // async () => + // { + // //var dialog = new Dialog_CreateLoopbackEndpoints(); + + // var dialog = new ContentDialog(); + // dialog.Content = XamlReader.Load() + + // await dialog.ShowAsync(); + // }); + } + + + + public void OnNavigatedFrom() + { + } + + public event EventHandler ShowCreateDialog; + + public void OnNavigatedTo(object parameter) + { + if (parameter != null && ((string)parameter).ToLower() == "create") + { + ShowCreateDialog?.Invoke(this, new EventArgs()); + } } } diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/NET2UDP/EndpointsNet2UdpViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/NET2UDP/EndpointsNet2UdpViewModel.cs index 0208c30a..4a4903bd 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/NET2UDP/EndpointsNet2UdpViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/NET2UDP/EndpointsNet2UdpViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class EndpointsNet2UdpViewModel : SingleTransportEndpointViewModelBase, INavigationAware + public partial class EndpointsNet2UdpViewModel : SingleTransportEndpointViewModelBase { public EndpointsNet2UdpViewModel(INavigationService navigationService) : base("NET2UDP", navigationService) { diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/SingleTransportEndpointViewModelBase.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/SingleTransportEndpointViewModelBase.cs index 0802618c..1809990e 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/SingleTransportEndpointViewModelBase.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Sections/Endpoints/SingleTransportEndpointViewModelBase.cs @@ -14,7 +14,7 @@ namespace Microsoft.Midi.Settings.ViewModels { - public partial class SingleTransportEndpointViewModelBase : ObservableRecipient, INavigationAware + public partial class SingleTransportEndpointViewModelBase : ObservableRecipient { private readonly INavigationService _navigationService; @@ -86,15 +86,5 @@ public void RefreshDeviceCollection() } - - - public void OnNavigatedFrom() - { - } - - - public void OnNavigatedTo(object parameter) - { - } } } diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/ViewModels/HomeViewModel.cs b/src/user-tools/midi-settings/Microsoft.Midi.Settings/ViewModels/HomeViewModel.cs index 790323be..248970f5 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/ViewModels/HomeViewModel.cs +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/ViewModels/HomeViewModel.cs @@ -17,11 +17,22 @@ public class HomeViewModel : ObservableRecipient, INavigationAware private readonly INavigationService _navigationService; private readonly IMidiConfigFileService m_configFileService; - public ICommand LaunchFirstRunExperience + public ICommand LaunchFirstRunExperienceCommand { get; private set; } + public ICommand CommonTaskCreateLoopbackEndpointsCommand + { + get; private set; + } + + public ICommand CommonTaskSendSysExCommand + { + get; private set; + } + + public string SystemTimerCurrentResolutionFormattedMilliseconds { get; set; @@ -113,13 +124,24 @@ public HomeViewModel(INavigationService navigationService, IMidiConfigFileServic _navigationService = navigationService; m_configFileService = midiConfigFileService; - LaunchFirstRunExperience = new RelayCommand( + LaunchFirstRunExperienceCommand = new RelayCommand( () => { - System.Diagnostics.Debug.WriteLine("View Device Details Command exec"); - _navigationService.NavigateTo(typeof(FirstRunExperienceViewModel).FullName!); }); + + CommonTaskCreateLoopbackEndpointsCommand = new RelayCommand( + () => + { + _navigationService.NavigateTo(typeof(EndpointsLoopViewModel).FullName!, "create"); + }); + + CommonTaskSendSysExCommand = new RelayCommand( + () => + { + _navigationService.NavigateTo(typeof(ToolsSysExViewModel).FullName!, "send"); + }); + } public void OnNavigatedFrom() diff --git a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Views/HomePage.xaml b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Views/HomePage.xaml index 6cbeba4e..16e3a3cc 100644 --- a/src/user-tools/midi-settings/Microsoft.Midi.Settings/Views/HomePage.xaml +++ b/src/user-tools/midi-settings/Microsoft.Midi.Settings/Views/HomePage.xaml @@ -44,7 +44,7 @@ >