mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
update sleep prevention
This commit is contained in:
parent
85a9363c78
commit
9807448fce
@ -97,7 +97,7 @@ namespace MediaBrowser.Providers.People
|
|||||||
|
|
||||||
var requestCount = _requestCount;
|
var requestCount = _requestCount;
|
||||||
|
|
||||||
if (requestCount >= 30)
|
if (requestCount >= 40)
|
||||||
{
|
{
|
||||||
//_logger.Debug("Throttling Tmdb people");
|
//_logger.Debug("Throttling Tmdb people");
|
||||||
|
|
||||||
|
@ -69,6 +69,11 @@ namespace MediaBrowser.Server.Mono.Native
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AllowSystemStandby()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<Assembly> GetAssembliesWithParts()
|
public List<Assembly> GetAssembliesWithParts()
|
||||||
{
|
{
|
||||||
var list = new List<Assembly>();
|
var list = new List<Assembly>();
|
||||||
|
@ -27,28 +27,27 @@ namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
|||||||
_timer = new PeriodicTimer(obj =>
|
_timer = new PeriodicTimer(obj =>
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
var nativeApp = ((ApplicationHost)_appHost).NativeApp;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
KeepAlive();
|
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
||||||
|
{
|
||||||
|
nativeApp.PreventSystemStandby();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nativeApp.AllowSystemStandby();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error resetting system standby timer", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KeepAlive()
|
|
||||||
{
|
|
||||||
var nativeApp = ((ApplicationHost)_appHost).NativeApp;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
nativeApp.PreventSystemStandby();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error resetting system standby timer", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (_timer != null)
|
if (_timer != null)
|
||||||
|
@ -93,6 +93,8 @@ namespace MediaBrowser.Server.Startup.Common
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void PreventSystemStandby();
|
void PreventSystemStandby();
|
||||||
|
|
||||||
|
void AllowSystemStandby();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the power management.
|
/// Gets the power management.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -321,6 +321,11 @@ namespace MediaBrowser.ServerApplication
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Invoke(Action action)
|
||||||
|
{
|
||||||
|
_serverNotifyIcon.Invoke(action);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the service.
|
/// Starts the service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace MediaBrowser.ServerApplication.Native
|
namespace MediaBrowser.ServerApplication.Native
|
||||||
{
|
{
|
||||||
@ -7,11 +8,33 @@ namespace MediaBrowser.ServerApplication.Native
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Standby
|
public static class Standby
|
||||||
{
|
{
|
||||||
public static void PreventSystemStandby()
|
public static void PreventSleepAndMonitorOff()
|
||||||
{
|
{
|
||||||
SystemHelper.ResetStandbyTimer();
|
NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED | NativeMethods.ES_DISPLAY_REQUIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void PreventSleep()
|
||||||
|
{
|
||||||
|
NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear EXECUTION_STATE flags to allow the system to sleep and turn off monitor normally
|
||||||
|
public static void AllowSleep()
|
||||||
|
{
|
||||||
|
NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class NativeMethods
|
||||||
|
{
|
||||||
|
// Import SetThreadExecutionState Win32 API and necessary flags
|
||||||
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
|
public static extern uint SetThreadExecutionState(uint esFlags);
|
||||||
|
public const uint ES_CONTINUOUS = 0x80000000;
|
||||||
|
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
|
||||||
|
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
internal enum EXECUTION_STATE : uint
|
internal enum EXECUTION_STATE : uint
|
||||||
{
|
{
|
||||||
ES_NONE = 0,
|
ES_NONE = 0,
|
||||||
@ -21,16 +44,5 @@ namespace MediaBrowser.ServerApplication.Native
|
|||||||
ES_AWAYMODE_REQUIRED = 0x00000040,
|
ES_AWAYMODE_REQUIRED = 0x00000040,
|
||||||
ES_CONTINUOUS = 0x80000000
|
ES_CONTINUOUS = 0x80000000
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SystemHelper
|
|
||||||
{
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
||||||
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
|
|
||||||
|
|
||||||
public static void ResetStandbyTimer()
|
|
||||||
{
|
|
||||||
EXECUTION_STATE es = SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using MediaBrowser.ServerApplication.Networking;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Windows.Forms;
|
||||||
using CommonIO;
|
using CommonIO;
|
||||||
using MediaBrowser.Controller.Power;
|
using MediaBrowser.Controller.Power;
|
||||||
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
||||||
@ -134,7 +135,12 @@ namespace MediaBrowser.ServerApplication.Native
|
|||||||
|
|
||||||
public void PreventSystemStandby()
|
public void PreventSystemStandby()
|
||||||
{
|
{
|
||||||
Standby.PreventSystemStandby();
|
MainStartup.Invoke(Standby.PreventSleep);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AllowSystemStandby()
|
||||||
|
{
|
||||||
|
MainStartup.Invoke(Standby.AllowSleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPowerManagement GetPowerManagement()
|
public IPowerManagement GetPowerManagement()
|
||||||
|
@ -36,10 +36,15 @@ namespace MediaBrowser.ServerApplication
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
Action act = () => notifyIcon1.Visible = false;
|
Action act = () => notifyIcon1.Visible = false;
|
||||||
contextMenuStrip1.Invoke(act);
|
Invoke(act);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Invoke(Action action)
|
||||||
|
{
|
||||||
|
contextMenuStrip1.Invoke(action);
|
||||||
|
}
|
||||||
|
|
||||||
public ServerNotifyIcon(ILogManager logManager,
|
public ServerNotifyIcon(ILogManager logManager,
|
||||||
IServerApplicationHost appHost,
|
IServerApplicationHost appHost,
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user