Skip to content

Commit

Permalink
fix UI bugs of Device Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Dec 29, 2023
1 parent f7349b8 commit 4a93204
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions Project-Aurora/Project-Aurora/Controls/Control_DeviceItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace Aurora.Controls;
public partial class Control_DeviceItem
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register(nameof(Device), typeof(DeviceContainer), typeof(Control_DeviceItem), new PropertyMetadata(DevicePropertyUpdated));
public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register(
nameof(Device), typeof(DeviceContainer), typeof(Control_DeviceItem), new PropertyMetadata(DevicePropertyUpdated)
);

private static void DevicePropertyUpdated(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand All @@ -33,6 +35,8 @@ private static void DevicePropertyUpdated(DependencyObject d, DependencyProperty

private readonly Timer _updateControlsTimer;

private bool _deviceRunning;

public DeviceContainer Device
{
get => (DeviceContainer)GetValue(DeviceProperty);
Expand Down Expand Up @@ -69,17 +73,20 @@ private void btnToggleOnOff_Click(object? sender, EventArgs e)
btnStart.Content = "Working...";
btnStart.IsEnabled = false;
var device = Device;
Task.Run(async () =>
if (device.Device.IsInitialized)
{
if (device.Device.IsInitialized)
Task.Run(async () =>
{
await device.DisableDevice();
}
else
});
}
else
{
Task.Run(async () =>
{
await device.EnableDevice();
}
});
});
}
}

private void btnToggleEnableDisable_Click(object? sender, EventArgs e)
Expand All @@ -93,21 +100,22 @@ private void btnToggleEnableDisable_Click(object? sender, EventArgs e)
{
Global.DeviceConfiguration.EnabledDevices.Remove(Device.Device.DeviceName);
}
btnStart.Content = "Working...";
btnStart.IsEnabled = false;
btnEnable.IsEnabled = false;
UpdateDynamic();

var device = Device;
Task.Run(async () =>
if (_deviceRunning)
{
if (deviceEnabled)
btnStart.Content = "Working...";
btnStart.IsEnabled = false;
btnEnable.IsEnabled = false;

var device = Device;
Task.Run(async () =>
{
await device.DisableDevice();
}
else
{
await device.EnableDevice();
}
});
}
Task.Run(() =>
{
ConfigManager.Save(Global.DeviceConfiguration, DeviceConfig.ConfigFile);
});
}
Expand Down Expand Up @@ -149,7 +157,7 @@ private void OnDeviceOnUpdated(object? o, EventArgs eventArgs)
private void UpdateStatic()
{
Beta.Visibility = Device.Device.Tooltips.Beta ? Visibility.Visible : Visibility.Hidden;

var infoTooltip = Device.Device.Tooltips.Info;
if (infoTooltip != null)
{
Expand Down Expand Up @@ -184,20 +192,23 @@ private void UpdateDynamic()
{
if (Device.Device.isDoingWork)
{
_deviceRunning = false;
btnStart.Content = "Working...";
btnStart.IsEnabled = false;
btnEnable.IsEnabled = false;
_updateControlsTimer.Start();
}
else if (Device.Device.IsInitialized)
{
_deviceRunning = true;
btnStart.Content = "Stop";
btnStart.IsEnabled = true;
btnEnable.IsEnabled = true;
_updateControlsTimer.Start();
}
else
{
_deviceRunning = false;
btnStart.Content = "Start";
btnStart.IsEnabled = true;
btnEnable.IsEnabled = true;
Expand Down Expand Up @@ -237,10 +248,7 @@ private void btnViewOptions_Click(object? sender, RoutedEventArgs e)
RegisteredVariables = Device.Device.RegisteredVariables
}
};
optionsWindow.Closing += (_, _) =>
{
ConfigManager.Save(Global.DeviceConfiguration, DeviceConfig.ConfigFile);
};
optionsWindow.Closing += (_, _) => { ConfigManager.Save(Global.DeviceConfiguration, DeviceConfig.ConfigFile); };

optionsWindow.ShowDialog();
}
Expand Down

0 comments on commit 4a93204

Please sign in to comment.