Skip to content

Commit

Permalink
Addressed #157
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Nov 8, 2021
1 parent 5b48b2d commit 11efb4a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 6 additions & 1 deletion DSHMC/MVVM/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public MainViewModel()
/// <summary>
/// Is it possible to edit the selected device.
/// </summary>
public bool IsEditable => IsElevated && HasDeviceSelected;
public bool IsEditable => IsElevated && HasDeviceSelected && !IsRestarting;

/// <summary>
/// Is the selected device in the process of getting restarted.
/// </summary>
public bool IsRestarting { get; set; } = false;

/// <summary>
/// Version to display in window title.
Expand Down
4 changes: 3 additions & 1 deletion DSHMC/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
mc:Ignorable="d"
Title="DsHidMini Control"
Height="620" Width="800"
ResizeMode="CanMinimize"
MinHeight="620" MinWidth="800"
MaxHeight="768" MaxWidth="1024"
ResizeMode="CanResize"
WindowStartupLocation="CenterScreen">
<controls:AdonisWindow.TitleBarContent>
<!-- Window title bar content -->
Expand Down
24 changes: 19 additions & 5 deletions DSHMC/UI/Devices/DeviceDetailsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Windows.Controls;
using Nefarius.DsHidMini.MVVM;
using Nefarius.DsHidMini.Util;
using MessageBox = AdonisUI.Controls.MessageBox;
using MessageBoxButton = AdonisUI.Controls.MessageBoxButton;
using MessageBoxImage = AdonisUI.Controls.MessageBoxImage;

namespace Nefarius.DsHidMini.UI.Devices
{
Expand All @@ -19,26 +22,37 @@ public DeviceDetailsView()

private async void ApplyChanges_Click(object sender, RoutedEventArgs e)
{
var tb = (Button) e.OriginalSource;
var vm = (MainViewModel) tb.DataContext;
var tb = (Button)e.OriginalSource;
var vm = (MainViewModel)tb.DataContext;

await Task.Run(() =>
{
try
{
vm.IsRestarting = true;
vm.SelectedDevice.ApplyChanges();
}
catch
{
// TODO: handle better
Dispatcher.Invoke(() => MessageBox.Show(
"Failed to restart device. The settings have been saved, but couldn't be applied. " +
"Please manually reconnect the device for the changes to become active.",
"Device restart failed",
MessageBoxButton.OK,
MessageBoxImage.Exclamation
));
}
finally
{
vm.IsRestarting = false;
}
});
}

private void DeviceDisconnect_OnClick(object sender, RoutedEventArgs e)
{
var tb = (Button) e.OriginalSource;
var vm = (MainViewModel) tb.DataContext;
var tb = (Button)e.OriginalSource;
var vm = (MainViewModel)tb.DataContext;

var mac = PhysicalAddress.Parse(vm.SelectedDevice.DeviceAddress);

Expand Down

0 comments on commit 11efb4a

Please sign in to comment.