Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ - (NSImage *)imageTintedWithColor:(NSColor *)tint
@end


@implementation AppDelegate
@implementation AppDelegate {
IOPMAssertionID _userActivityAssertion;
}

#pragma mark Launch and Termination

Expand Down Expand Up @@ -242,6 +244,26 @@ - (void)fixTimedQuitMenuItem

#pragma mark Jiggling

- (void)declareUserActivity
{
// Release any previous assertion before creating a new one
if (_userActivityAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(_userActivityAssertion);
_userActivityAssertion = kIOPMNullAssertionID;
}

// Create a short-lived "user is active" assertion to reset system idle timer
IOReturn result = IOPMAssertionDeclareUserActivity(
CFSTR("Jiggler Zen Jiggle Activity"),
kIOPMUserActiveLocal,
&_userActivityAssertion
);

if (result != kIOReturnSuccess) {
NSLog(@"[Jiggler] Failed to declare user activity (IOReturn = 0x%x)", result);
}
}

- (BOOL)isInAScreen:(NSPoint)point
{
NSArray *screens = [NSScreen screens];
Expand Down Expand Up @@ -857,18 +879,21 @@ - (void)jiggleMouse:(id)unused
// BCH 8 February 2015: UpdateSystemActivity() is officially deprecated beginning in 10.8. I am going
// to continue using it until it actually goes away.
// BCH 19 May 2016: Added weak linking protection to this, just in case Apple actually removes it...
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (UpdateSystemActivity != NULL)
UpdateSystemActivity(UsrActivity);
#pragma clang diagnostic pop
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// if (UpdateSystemActivity != NULL)
// UpdateSystemActivity(UsrActivity);
//#pragma clang diagnostic pop

// BCH 19 May 2016: Adding the new IOKit call IOPMAssertionDeclareUserActivity(), which appears to be equivalent
// to UpdateSystemActivity(UsrActivity). It may have slightly different effects, so I'm keeping the call to
// UpdateSystemActivity(UsrActivity) above as well, just to try to ensure the most complete coverage possible.
static IOPMAssertionID assertionID = kIOPMNullAssertionID;
// static IOPMAssertionID assertionID = kIOPMNullAssertionID;

IOPMAssertionDeclareUserActivity(CFSTR("Jiggler"), kIOPMUserActiveLocal, &assertionID);
// IOPMAssertionDeclareUserActivity(CFSTR("Jiggler"), kIOPMUserActiveLocal, &assertionID);

// Replace the old UpdateSystemActivity() + IOPMAssertionDeclareUserActivity()
[self declareUserActivity];

[timeOfLastJiggle release];
timeOfLastJiggle = [[NSDate alloc] init];
Expand Down