Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled auto-pause on low disk space as a default setting with a thre…
…shold of 1GB. This prevents you from running out of space which can cause other system problems and result in a confusing error message. Added status messages for auto-pause and resume. Made status messages wait until the user is active to display.
- Loading branch information
1 parent
7cdb3eb
commit f2f5ec8
Showing
11 changed files
with
231 additions
and
18 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VidCoder.Services | ||
{ | ||
/// <summary> | ||
/// Tracks if the user is active on the application | ||
/// </summary> | ||
public class ActivityService | ||
{ | ||
private bool active = true; | ||
|
||
private TaskCompletionSource<object> activeTcs; | ||
|
||
/// <summary> | ||
/// Waits for the program to become active. | ||
/// </summary> | ||
public Task WaitForActiveAsync() | ||
{ | ||
bool hasInputRecently = SystemInputTracker.GetTimeSinceLastInput() < TimeSpan.FromSeconds(30); | ||
if (active && hasInputRecently) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
if (!active) | ||
{ | ||
// If the app is not active, we just need to wait until we're reactivated. | ||
if (activeTcs == null) | ||
{ | ||
activeTcs = new TaskCompletionSource<object>(); | ||
} | ||
|
||
return activeTcs.Task; | ||
} | ||
|
||
// The app is active, but we have not seen user input in a while. We need to poll for it. | ||
return this.WaitForInput(); | ||
} | ||
|
||
public void ReportActivated() | ||
{ | ||
active = true; | ||
this.activeTcs?.TrySetResult(null); | ||
} | ||
|
||
public void ReportDeactivated() | ||
{ | ||
active = false; | ||
} | ||
|
||
private async Task WaitForInput() | ||
{ | ||
while (true) | ||
{ | ||
await Task.Delay(2000); | ||
if (SystemInputTracker.GetTimeSinceLastInput() < TimeSpan.FromSeconds(30)) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VidCoder | ||
{ | ||
public static class SystemInputTracker | ||
{ | ||
[DllImport("user32.dll")] | ||
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); | ||
|
||
public static TimeSpan GetTimeSinceLastInput() | ||
{ | ||
int systemUptime = Environment.TickCount, | ||
idleTicks = 0; | ||
|
||
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO(); | ||
lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo); | ||
lastInputInfo.dwTime = 0; | ||
|
||
if (GetLastInputInfo(ref lastInputInfo)) | ||
{ | ||
idleTicks = systemUptime - (int)lastInputInfo.dwTime; | ||
} | ||
|
||
return new TimeSpan(0, 0, 0, 0, idleTicks); | ||
} | ||
|
||
private struct LASTINPUTINFO | ||
{ | ||
public uint cbSize; | ||
public uint dwTime; | ||
} | ||
} | ||
} |
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