Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dend committed May 12, 2021
1 parent a23279f commit fcae21b
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/modules/espresso/Espresso/Core/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using Microsoft.Win32;
using NLog;

#pragma warning disable SA1116 // Split parameters should start on line after declaration

namespace Espresso.Shell.Core
{
[Flags]
Expand Down Expand Up @@ -40,7 +38,6 @@ public class APIHelper
private static CancellationTokenSource _tokenSource;
private static CancellationToken _threadToken;

// More details about the API used: https://docs.microsoft.com/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);

Expand All @@ -52,13 +49,14 @@ public class APIHelper
public static extern bool SetStdHandle(int nStdHandle, IntPtr hHandle);

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
[MarshalAs(UnmanagedType.U4)] uint access,
[MarshalAs(UnmanagedType.U4)] FileShare share,
IntPtr securityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
IntPtr templateFile);
public static extern IntPtr CreateFile(
[MarshalAs(UnmanagedType.LPTStr)] string filename,
[MarshalAs(UnmanagedType.U4)] uint access,
[MarshalAs(UnmanagedType.U4)] FileShare share,
IntPtr securityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
IntPtr templateFile);

static APIHelper()
{
Expand Down Expand Up @@ -96,17 +94,6 @@ private static bool SetAwakeState(EXECUTION_STATE state)
}
}

/// <summary>
/// Attempts to reset the current machine state to one where Espresso doesn't try to keep it awake.
/// This does not interfere with the state that can be potentially set by other applications.
/// </summary>
/// <returns>Status of the attempt. True is successful, false if not.</returns>
public static bool SetNormalKeepAwake()
{
_tokenSource.Cancel();
return SetAwakeState(EXECUTION_STATE.ES_CONTINUOUS);
}

public static void SetIndefiniteKeepAwake(Action<bool> callback, Action failureCallback, bool keepDisplayOn = true)
{
_tokenSource = new CancellationTokenSource();
Expand Down

0 comments on commit fcae21b

Please sign in to comment.