Skip to content

Commit

Permalink
stanby
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyeao committed Mar 27, 2024
1 parent 4e1c945 commit d98a265
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions MqttService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System.Timers;
using System.Linq.Expressions;
using System.Windows;
using System.Windows.Forms;


namespace PC2MQTT
{
Expand Down Expand Up @@ -684,7 +686,7 @@ private void PerformShutdown()
if (_settings.UseSafeCommands)
{
// Use Dispatcher to ensure the dialog is opened on the UI thread
Application.Current.Dispatcher.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
ConfirmationDialog dialog = new ConfirmationDialog("Shutdown Confirmation", "Are you sure you want to Shutdown the computer?");
if (dialog.ShowDialog() == true)
Expand Down Expand Up @@ -714,18 +716,20 @@ private void PerformStandby()
if (_settings.UseSafeCommands)
{
// Use Dispatcher to ensure the dialog is opened on the UI thread
Application.Current.Dispatcher.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
ConfirmationDialog dialog = new ConfirmationDialog("Standby Confirmation", "Are you sure you want to put the computer to standby?");
if (dialog.ShowDialog() == true)
{
Log.Information("User confirmed the standby command.");
System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, true, true);
// Proceed with the standby
// Note: There's no direct command for standby in Windows, handled by hardware
}
else
{
Log.Information("User cancelled the standby command.");
System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, true, true);
}
});
}
Expand All @@ -742,7 +746,7 @@ private void PerformHibernate()
if (_settings.UseSafeCommands)
{
// Use Dispatcher to ensure the dialog is opened on the UI thread
Application.Current.Dispatcher.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
ConfirmationDialog dialog = new ConfirmationDialog("Standby Confirmation", "Are you sure you want to hibernate the computer?");
if (dialog.ShowDialog() == true)
Expand Down Expand Up @@ -792,7 +796,7 @@ private void PerformReboot()
if (_settings.UseSafeCommands)
{
// Use Dispatcher to ensure the dialog is opened on the UI thread
Application.Current.Dispatcher.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
ConfirmationDialog dialog = new ConfirmationDialog("Standby Confirmation", "Are you sure you want to reboot the computer?");
if (dialog.ShowDialog() == true)
Expand Down

0 comments on commit d98a265

Please sign in to comment.