-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab6c4d7
commit 34de5e8
Showing
12 changed files
with
148 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...pModeStopper/Tools/NAudioSoundAnalyser.cs → ...in/AudioManagement/NAudioSoundAnalyser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
SpotifySleepModeStopper/Domain/MessageManagement/DummyMessageDisplayer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using SpotifyTools.Contracts; | ||
|
||
namespace SpotifyTools.Domain.MessageManagement | ||
{ | ||
public class DummyMessageDisplayer : IMessageDisplayer | ||
{ | ||
public void OutputMessage(string mess) | ||
{ | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...leepModeStopper/Tools/MessageDisplayer.cs → ...ain/MessageManagement/MessageDisplayer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
SpotifySleepModeStopper/Domain/PowerManagement/SetThreadExecutionStateHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using SpotifyTools.Contracts; | ||
using SpotifyTools.Tools; | ||
|
||
namespace SpotifyTools.Domain.PowerManagement | ||
{ | ||
public class SetThreadExecutionStateHandler : IPreventSleepScreen | ||
{ | ||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
private static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags); | ||
|
||
[Flags] | ||
private enum ExecutionState : uint | ||
{ | ||
EsAwaymodeRequired = 0x00000040, | ||
EsContinuous = 0x80000000, | ||
EsDisplayRequired = 0x00000002, | ||
EsSystemRequired = 0x00000001 | ||
} | ||
|
||
public static void PreventSleep() | ||
{ | ||
SetThreadExecutionState(ExecutionState.EsDisplayRequired | ExecutionState.EsContinuous | ExecutionState.EsSystemRequired); | ||
} | ||
|
||
public static void AllowSleep() | ||
{ | ||
SetThreadExecutionState(ExecutionState.EsContinuous); | ||
} | ||
|
||
private Task _keepScreenUp; | ||
private CancellationTokenSource _cToken; | ||
|
||
public void EnableConstantDisplayAndPower(bool enableConstantDisplayAndPower) | ||
{ | ||
if (enableConstantDisplayAndPower) | ||
{ | ||
_cToken?.Cancel(); | ||
_cToken = new CancellationTokenSource(); | ||
|
||
Repeat.Interval(TimeSpan.FromSeconds(10), PreventSleep, _cToken.Token); | ||
} | ||
else | ||
{ | ||
_cToken?.Cancel(); | ||
AllowSleep(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpotifyTools.Tools | ||
{ | ||
internal static class Repeat | ||
{ | ||
public static Task Interval( | ||
TimeSpan pollInterval, | ||
Action action, | ||
CancellationToken token) | ||
{ | ||
// We don't use Observable.Interval: | ||
// If we block, the values start bunching up behind each other. | ||
return Task.Factory.StartNew( | ||
() => | ||
{ | ||
for (;;) | ||
{ | ||
if (token.WaitHandle.WaitOne(pollInterval)) | ||
break; | ||
|
||
action(); | ||
} | ||
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters