committed by
GitHub
23 changed files with 304 additions and 88 deletions
@ -0,0 +1,39 @@ |
|||||
|
#include "common.h" |
||||
|
|
||||
|
namespace |
||||
|
{ |
||||
|
id<NSObject> s_inhibitAppSleepHandle{}; |
||||
|
} |
||||
|
|
||||
|
class PlatformBehaviorInhibition : public ComSingleObject<IAvnPlatformBehaviorInhibition, &IID_IAvnCursorFactory> |
||||
|
{ |
||||
|
public: |
||||
|
FORWARD_IUNKNOWN() |
||||
|
|
||||
|
virtual void SetInhibitAppSleep(bool inhibitAppSleep, char* reason) override |
||||
|
{ |
||||
|
START_COM_CALL; |
||||
|
|
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
if (inhibitAppSleep && s_inhibitAppSleepHandle == nullptr) |
||||
|
{ |
||||
|
NSActivityOptions options = NSActivityUserInitiatedAllowingIdleSystemSleep; |
||||
|
s_inhibitAppSleepHandle = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:[NSString stringWithUTF8String: reason]]; |
||||
|
} |
||||
|
|
||||
|
if (!inhibitAppSleep) |
||||
|
{ |
||||
|
s_inhibitAppSleepHandle = nullptr; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
extern IAvnPlatformBehaviorInhibition* CreatePlatformBehaviorInhibition() |
||||
|
{ |
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
return new PlatformBehaviorInhibition(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Avalonia.Platform |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Allows to inhibit platform specific behavior.
|
||||
|
/// </summary>
|
||||
|
public interface IPlatformBehaviorInhibition |
||||
|
{ |
||||
|
Task SetInhibitAppSleep(bool inhibitAppSleep, string reason); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace Avalonia.Controls |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A platform specific behavior that can be inhibited.
|
||||
|
/// </summary>
|
||||
|
public enum PlatformInhibitionType |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// When inhibited, prevents the app from being put to sleep or being given a lower priority when not in focus.
|
||||
|
/// </summary>
|
||||
|
AppSleep |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia.Native.Interop; |
||||
|
using Avalonia.Platform; |
||||
|
|
||||
|
namespace Avalonia.Native |
||||
|
{ |
||||
|
internal class PlatformBehaviorInhibition : IPlatformBehaviorInhibition |
||||
|
{ |
||||
|
readonly IAvnPlatformBehaviorInhibition _native; |
||||
|
|
||||
|
internal PlatformBehaviorInhibition(IAvnPlatformBehaviorInhibition native) |
||||
|
=> _native = native; |
||||
|
|
||||
|
public Task SetInhibitAppSleep(bool inhibitAppSleep, string reason) |
||||
|
{ |
||||
|
_native.SetInhibitAppSleep(inhibitAppSleep ? 1 : 0, reason); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue