Skip to content
This repository
Browse code

Adds ability to prevent display sleep from happening, just like Caffe…

…ine used to
  • Loading branch information...
commit b02294d31e69ee9806b4e83e02f145dca42bd055 1 parent e395198
Dustin Rue authored
12 ControlPlane.xcodeproj/project.pbxproj
@@ -78,6 +78,7 @@
78 78 8DFA46170CC33E46003EAC16 /* QuitApplicationAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFA46150CC33E46003EAC16 /* QuitApplicationAction.m */; };
79 79 8DFD0DA60CEBBC8A00E79049 /* UnmountAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFD0DA40CEBBC8A00E79049 /* UnmountAction.m */; };
80 80 DA04D57215DC119E004B9E1C /* ToggleContextStickinessAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DA04D57115DC119E004B9E1C /* ToggleContextStickinessAction.m */; };
  81 + DA0CAE6516C4813600EDE2C5 /* PreventDisplaySleepAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DA0CAE6416C4813600EDE2C5 /* PreventDisplaySleepAction.m */; };
81 82 DA0E648615EC665000E77ABF /* AttachedPowerAdapterEvidenceSource.m in Sources */ = {isa = PBXBuildFile; fileRef = DA0E648515EC665000E77ABF /* AttachedPowerAdapterEvidenceSource.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
82 83 DA16392613D4B14A00E3F421 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = DA16392513D4B14A00E3F421 /* dsa_pub.pem */; };
83 84 DA1E59D21673A039002D256D /* Growl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA1E59D11673A039002D256D /* Growl.framework */; };
@@ -122,6 +123,7 @@
122 123 DAAF16B61413174400F5D915 /* ToggleTimeMachineAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DAAF16B51413174400F5D915 /* ToggleTimeMachineAction.m */; };
123 124 DAAF16B714131CDE00F5D915 /* CPHelperToolCommon.c in Sources */ = {isa = PBXBuildFile; fileRef = DA5B020B1412BDEF00E19C50 /* CPHelperToolCommon.c */; };
124 125 DAB1A7E215C3776D00CF65E8 /* CPNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB1A7E115C3776D00CF65E8 /* CPNotifications.m */; };
  126 + DABE3F6A16C44236004F5E63 /* OpenAndHideAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DABE3F6916C44236004F5E63 /* OpenAndHideAction.m */; };
125 127 DAC45F2014CDEC170007F5EF /* TimeMachineDestinationAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC45F1F14CDEC170007F5EF /* TimeMachineDestinationAction.m */; };
126 128 DAC672FE152235E800F1C7A1 /* ToggleWebSharingAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC672FD152235E800F1C7A1 /* ToggleWebSharingAction.m */; };
127 129 DAC817B1159BF95A0012ED43 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAC817B0159BF95A0012ED43 /* ServiceManagement.framework */; };
@@ -426,6 +428,8 @@
426 428 8DFD0DA40CEBBC8A00E79049 /* UnmountAction.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UnmountAction.m; path = Source/UnmountAction.m; sourceTree = "<group>"; };
427 429 DA04D57015DC119E004B9E1C /* ToggleContextStickinessAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToggleContextStickinessAction.h; path = Source/ToggleContextStickinessAction.h; sourceTree = "<group>"; };
428 430 DA04D57115DC119E004B9E1C /* ToggleContextStickinessAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ToggleContextStickinessAction.m; path = Source/ToggleContextStickinessAction.m; sourceTree = "<group>"; };
  431 + DA0CAE6316C4813600EDE2C5 /* PreventDisplaySleepAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PreventDisplaySleepAction.h; path = Source/PreventDisplaySleepAction.h; sourceTree = "<group>"; };
  432 + DA0CAE6416C4813600EDE2C5 /* PreventDisplaySleepAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PreventDisplaySleepAction.m; path = Source/PreventDisplaySleepAction.m; sourceTree = "<group>"; };
429 433 DA0E648515EC665000E77ABF /* AttachedPowerAdapterEvidenceSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AttachedPowerAdapterEvidenceSource.m; path = Source/AttachedPowerAdapterEvidenceSource.m; sourceTree = "<group>"; };
430 434 DA0E648715EC707300E77ABF /* AttachedPowerAdapterEvidenceSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AttachedPowerAdapterEvidenceSource.h; path = Source/AttachedPowerAdapterEvidenceSource.h; sourceTree = "<group>"; };
431 435 DA1204DA13D0E5C800CDA091 /* ControlPlane.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ControlPlane.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -497,6 +501,8 @@
497 501 DAAF16B51413174400F5D915 /* ToggleTimeMachineAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ToggleTimeMachineAction.m; path = Source/ToggleTimeMachineAction.m; sourceTree = "<group>"; };
498 502 DAB1A7E015C3776D00CF65E8 /* CPNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CPNotifications.h; path = Source/CPNotifications.h; sourceTree = "<group>"; };
499 503 DAB1A7E115C3776D00CF65E8 /* CPNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CPNotifications.m; path = Source/CPNotifications.m; sourceTree = "<group>"; };
  504 + DABE3F6816C44236004F5E63 /* OpenAndHideAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenAndHideAction.h; path = Source/OpenAndHideAction.h; sourceTree = "<group>"; };
  505 + DABE3F6916C44236004F5E63 /* OpenAndHideAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OpenAndHideAction.m; path = Source/OpenAndHideAction.m; sourceTree = "<group>"; };
500 506 DAC45F1E14CDEC170007F5EF /* TimeMachineDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimeMachineDestinationAction.h; path = Source/TimeMachineDestinationAction.h; sourceTree = "<group>"; };
501 507 DAC45F1F14CDEC170007F5EF /* TimeMachineDestinationAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TimeMachineDestinationAction.m; path = Source/TimeMachineDestinationAction.m; sourceTree = "<group>"; };
502 508 DAC672FC152235E800F1C7A1 /* ToggleWebSharingAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToggleWebSharingAction.h; path = Source/ToggleWebSharingAction.h; sourceTree = "<group>"; };
@@ -1019,6 +1025,8 @@
1019 1025 DAA9AC1A15961CDF00B84B05 /* MessagesAction.m */,
1020 1026 8DD790AA0BC28A9F00705346 /* OpenAction.h */,
1021 1027 8DD790AB0BC28A9F00705346 /* OpenAction.m */,
  1028 + DABE3F6816C44236004F5E63 /* OpenAndHideAction.h */,
  1029 + DABE3F6916C44236004F5E63 /* OpenAndHideAction.m */,
1022 1030 DD8274F414116CC80098FA6E /* OpenURLAction.h */,
1023 1031 DD8274F514116CC80098FA6E /* OpenURLAction.m */,
1024 1032 8DFA46140CC33E46003EAC16 /* QuitApplicationAction.h */,
@@ -1056,6 +1064,8 @@
1056 1064 8DC4E7F90C178917007E7E41 /* MuteAction.m */,
1057 1065 8D6762140C3B8D8D000B63EC /* NetworkLocationAction.h */,
1058 1066 8D6762150C3B8D8D000B63EC /* NetworkLocationAction.m */,
  1067 + DA0CAE6316C4813600EDE2C5 /* PreventDisplaySleepAction.h */,
  1068 + DA0CAE6416C4813600EDE2C5 /* PreventDisplaySleepAction.m */,
1059 1069 8D71CB760C17C01700E56526 /* ScreenSaverPasswordAction.h */,
1060 1070 8D71CB770C17C01700E56526 /* ScreenSaverPasswordAction.m */,
1061 1071 8D3C85120CDD8546009DBCD9 /* ScreenSaverStartAction.h */,
@@ -1459,6 +1469,8 @@
1459 1469 DA04D57215DC119E004B9E1C /* ToggleContextStickinessAction.m in Sources */,
1460 1470 DA0E648615EC665000E77ABF /* AttachedPowerAdapterEvidenceSource.m in Sources */,
1461 1471 DA9957EA160D4BA300AB3C7A /* StressTestEvidenceSource.m in Sources */,
  1472 + DABE3F6A16C44236004F5E63 /* OpenAndHideAction.m in Sources */,
  1473 + DA0CAE6516C4813600EDE2C5 /* PreventDisplaySleepAction.m in Sources */,
1462 1474 );
1463 1475 runOnlyForDeploymentPostprocessing = 0;
1464 1476 };
3  Source/Action.m
@@ -236,6 +236,7 @@ - (NSArray *)executeAppleScriptReturningListOfStrings:(NSString *)script
236 236 #import "OpenAction.h"
237 237 #import "OpenAndHideAction.h"
238 238 #import "OpenURLAction.h"
  239 +#import "PreventDisplaySleepAction.h"
239 240 #import "QuitApplicationAction.h"
240 241 #import "ScreenSaverPasswordAction.h"
241 242 #import "ScreenSaverStartAction.h"
@@ -298,6 +299,7 @@ - (id)init
298 299 [OpenAndHideAction class],
299 300 [OpenURLAction class],
300 301 [QuitApplicationAction class],
  302 + [PreventDisplaySleepAction class],
301 303 [ScreenSaverPasswordAction class],
302 304 [ScreenSaverStartAction class],
303 305 [ScreenSaverTimeAction class],
@@ -379,6 +381,7 @@ - (id)init
379 381 NSLocalizedString(@"Open", @"Action type");
380 382 NSLocalizedString(@"OpenAndHide", @"Action type");
381 383 NSLocalizedString(@"OpenURL", @"Action type");
  384 + NSLocalizedString(@"Prevent Display Sleep", @"Action type");
382 385 NSLocalizedString(@"QuitApplication", @"Action type");
383 386 NSLocalizedString(@"ScreenSaverPassword", @"Action type");
384 387 NSLocalizedString(@"ScreenSaverStart", @"Action type");
2  Source/CPController.m
@@ -363,7 +363,7 @@ - (BOOL) importMarcoPoloSettings {
363 363 }
364 364
365 365 - (void)awakeFromNib {
366   -
  366 + NSLog(@"did super awake from nib");
367 367 // Configures the crash reporter
368 368 [[BWQuincyManager sharedQuincyManager] setSubmissionURL:[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CPCrashReportURL"]];
369 369 [[BWQuincyManager sharedQuincyManager] setCompanyName:@"ControlPlane developers"];
29 Source/PreventDisplaySleepAction.h
... ... @@ -0,0 +1,29 @@
  1 +//
  2 +// PreventDisplaySleepAction.h
  3 +// ControlPlane
  4 +//
  5 +// Created by Dustin Rue on 2/7/13.
  6 +//
  7 +//
  8 +
  9 +#import "ToggleableAction.h"
  10 +#import <IOKit/pwr_mgt/IOPMLib.h>
  11 +
  12 +@interface PreventDisplaySleepAction : ToggleableAction
  13 +
  14 +- (NSString *)description;
  15 +- (BOOL)execute:(NSString **)errorString;
  16 ++ (NSString *)helpText;
  17 ++ (NSString *)creationHelpText;
  18 +
  19 ++ (NSArray *)limitedOptions;
  20 +
  21 +@end
  22 +
  23 +@interface PreventDisplaySleepActionStorage : NSObject
  24 +
  25 +@property (assign) IOPMAssertionID assertionID;
  26 +
  27 ++ (id) sharedStorage;
  28 +
  29 +@end
139 Source/PreventDisplaySleepAction.m
... ... @@ -0,0 +1,139 @@
  1 +//
  2 +// PreventDisplaySleepAction.m
  3 +// ControlPlane
  4 +//
  5 +// Created by Dustin Rue on 2/7/13.
  6 +//
  7 +//
  8 +
  9 +#import "PreventDisplaySleepAction.h"
  10 +#import <IOKit/pwr_mgt/IOPMLib.h>
  11 +
  12 +@implementation PreventDisplaySleepAction
  13 +
  14 +
  15 +- (NSString *) description {
  16 + if (turnOn)
  17 + return NSLocalizedString(@"Preventing display sleep.", @"");
  18 + else
  19 + return NSLocalizedString(@"Allowing display sleep.", @"");
  20 +}
  21 +
  22 +- (BOOL) execute: (NSString **) errorString {
  23 + IOPMAssertionID assertionID;
  24 + IOReturn success = kIOReturnError;
  25 + // kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
  26 + // kIOPMAssertionTypeNoIdleSleep prevents idle sleep
  27 +
  28 + PreventDisplaySleepActionStorage *assertionIdStorage = [PreventDisplaySleepActionStorage sharedStorage];
  29 +
  30 +
  31 + if (turnOn) {
  32 + // NOTE: IOPMAssertionCreateWithName limits the string to 128 characters.
  33 + CFStringRef reasonForActivity= CFSTR("Display sleep disallowed by ControlPlane");
  34 +
  35 +
  36 +
  37 + success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
  38 + kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
  39 +
  40 + [assertionIdStorage setAssertionID:assertionID];
  41 + }
  42 + else {
  43 + assertionID = [assertionIdStorage assertionID];
  44 +
  45 + if (assertionID)
  46 + success = IOPMAssertionRelease(assertionID);
  47 + }
  48 +
  49 +
  50 + if (success == kIOReturnSuccess)
  51 + {
  52 +
  53 + //Add the work you need to do without
  54 + // the system sleeping here.
  55 +
  56 +
  57 + //The system will be able to sleep again.
  58 + }
  59 +
  60 +
  61 + // result
  62 + if (success != kIOReturnSuccess) {
  63 + *errorString = @"Unable to enable/disable display sleep.";
  64 + return NO;
  65 + } else
  66 + return YES;
  67 +}
  68 +
  69 ++ (NSString *) helpText {
  70 + return NSLocalizedString(@"The parameter for Prevent Display Sleep action is either \"1\" to prevent "
  71 + "display sleep or \"0\" to allow display sleep.", @"");
  72 +}
  73 +
  74 ++ (NSString *) creationHelpText {
  75 + // FIXME: is there some useful text we could use?
  76 + return NSLocalizedString(@"Toggle prevention of display sleep", @"");
  77 +}
  78 +
  79 ++ (NSArray *) limitedOptions {
  80 + return [NSArray arrayWithObjects:
  81 + [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], @"option",
  82 + NSLocalizedString(@"Allow Display Sleep", @""), @"description", nil],
  83 + [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"option",
  84 + NSLocalizedString(@"Disallow Display Sleep", @""), @"description", nil],
  85 + nil];
  86 +}
  87 +
  88 +
  89 +
  90 ++ (NSString *) friendlyName {
  91 + return NSLocalizedString(@"Prevent Display Sleep", @"");
  92 +}
  93 +
  94 ++ (NSString *)menuCategory {
  95 + return NSLocalizedString(@"System Preferences", @"");
  96 +}
  97 +
  98 +@end
  99 +
  100 +static PreventDisplaySleepActionStorage *sharedStorage;
  101 +
  102 +@implementation PreventDisplaySleepActionStorage
  103 +
  104 ++ (id) sharedStorage {
  105 + @synchronized(self) {
  106 + if(sharedStorage == nil)
  107 + sharedStorage = [[super allocWithZone:NULL] init];
  108 + }
  109 + return sharedStorage;
  110 +}
  111 +
  112 ++ (id) allocWithZone:(NSZone *)zone {
  113 + return [[self sharedStorage] retain];
  114 +}
  115 +
  116 +- (id) copyWithZone:(NSZone *)zone {
  117 + return self;
  118 +}
  119 +- (id) retain {
  120 + return self;
  121 +}
  122 +- (NSUInteger)retainCount {
  123 + return UINT_MAX; //denotes an object that cannot be released
  124 +}
  125 +- (oneway void)release {
  126 + // never release
  127 +}
  128 +
  129 +- (id)autorelease {
  130 + return self;
  131 +}
  132 +
  133 +- (id)init {
  134 + self = [super init];
  135 +
  136 + return self;
  137 +}
  138 +
  139 +@end

0 comments on commit b02294d

Please sign in to comment.
Something went wrong with that request. Please try again.