Merge pull request #1580 from bettse/ARC_support

ARC support for AppNap toggle
This commit is contained in:
Iceman 2022-02-03 17:46:50 +01:00 committed by GitHub
commit bab5fbf9c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,10 +27,41 @@
#import <AppKit/NSApplication.h>
#endif
#if !defined(USING_ARC)
# if __has_feature(objc_arc)
# define USING_ARC 1
# else
# define USING_ARC 0
# endif
#elif EMPTY_DEFINE(USING_ARC)
# undef USING_ARC
# define USING_ARC 1
#endif
static id activity = nil;
//OS X Version 10.10 is defined in OS X 10.10 and later
#if defined(MAC_OS_X_VERSION_10_10)
#if USING_ARC
@implementation AppDelegate {
id <NSObject> activity;
}
void disableAppNap(const char* reason) {
if(activity == nil) {
//NSLog(@"disableAppNap: %@", @(reason));
activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityBackground reason:@(reason)];
}
}
void enableAppNap() {
if(activity != nil) {
//NSLog(@"enableAppNap");
[[NSProcessInfo processInfo] endActivity:activity];
activity = nil;
}
}
@end
#else
void disableAppNap(const char* reason) {
if(activity == nil) {
//NSLog(@"disableAppNap: %@", @(reason));
@ -47,6 +78,7 @@ void enableAppNap() {
activity = nil;
}
}
#endif
#else
void disableAppNap(const char* reason) { }
@ -68,4 +100,4 @@ void makeFocusable() {
#else
void makeUnfocusable() { }
void makeFocusable() { }
#endif
#endif