4
4
#import " NSError+InfoAccess.h"
5
5
#import " NSInvocation+Quick.h"
6
6
#import " NSInvocation+Nesting.h"
7
-
7
+ # import " NSDate+NiceFormats.h "
8
8
9
9
NSString * const SSYOperationQueueDidEndWorkNotification = @" SSYOperationQueueDidEndWorkNotification" ;
10
10
NSString * const SSYOperationQueueDidBeginWorkNotification = @" SSYOperationQueueDidBeginWorkNotification" ;
17
17
NSString * const constKeySSYOperationQueueKeepWithNext = @" SSYOperationQueueKeepWithNext" ;
18
18
NSString * const constKeySSYOperationGroup = @" SSYOperationGroup" ;
19
19
20
+ @interface SSYOperationQueue ()
20
21
21
- // No longer needed since override of -[SSYOperationQueue setError:] does this. @implementation NSError (SSYOperationQueueExtras)
22
-
23
- // No longer needed since override of -[SSYOperationQueue setError:] does this. - (NSError*)errorByAddingOperationGroupFromInfo:(NSDictionary*)info {
24
- // No longer needed since override of -[SSYOperationQueue setError:] does this. return [self errorByAddingUserInfoObject:[info objectForKey:constKeySSYOperationGroup]
25
- // No longer needed since override of -[SSYOperationQueue setError:] does this. forKey:constKeySSYOperationGroup] ;
26
- // No longer needed since override of -[SSYOperationQueue setError:] does this. }
27
-
28
- // No longer needed since override of -[SSYOperationQueue setError:] does this. @end
22
+ @property (retain ) id noAppNapActivity ;
29
23
24
+ @end
30
25
31
26
32
27
@implementation SSYOperationQueue
33
28
34
29
@synthesize scriptCommand = m_scriptCommand ;
35
30
@synthesize scriptResult = m_scriptResult ;
36
31
@synthesize skipOperationsExceptGroups = m_skipOperationsExceptGroups ;
32
+ @synthesize noAppNapActivity = m_noAppNapActivity ;
37
33
38
34
- (BOOL )shouldSkipOperationsInGroup : (NSString *)group {
39
35
NSSet * skipOperationsExceptGroups = [self skipOperationsExceptGroups ] ;
@@ -132,6 +128,7 @@ - (void)dealloc {
132
128
[m_scriptResult release ] ;
133
129
[m_errorRetryInvocations release ] ;
134
130
[m_skipOperationsExceptGroups release ] ;
131
+ [m_noAppNapActivity release ] ;
135
132
136
133
[super dealloc ] ;
137
134
}
@@ -231,6 +228,15 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
231
228
else {
232
229
owner = self ;
233
230
}
231
+
232
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
233
+ // Being built with Mac OS X 10.9 or later SDK
234
+ id activity = [self noAppNapActivity ] ;
235
+ if (activity) {
236
+ [[NSProcessInfo processInfo ] endActivity: activity];
237
+ /* SSYDBL*/ NSLog (@" Ended no-app-nap activity=%@ " , activity) ;
238
+ }
239
+ #endif
234
240
235
241
// It is stated in the documentation of NSOperationQueue (in the
236
242
// introduction, not in -operations) that KVO notifications
@@ -252,6 +258,33 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
252
258
// when the count jumps from 0 to, say, 5. Apparently,
253
259
// KVO notifications are coalesced.
254
260
261
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
262
+ #warning "Built for 10.9"
263
+ // Being built with Mac OS X 10.9 or later SDK
264
+ if ([[NSProcessInfo processInfo ] respondsToSelector: @selector (beginActivityWithOptions:reason: )]) {
265
+ // Running in Mac OS X 10.9 or later
266
+ NSString * groupName = nil ;
267
+ if ([[self operations ] count ] > 0 ) {
268
+ SSYOperation* firstOperation = [[self operations ] objectAtIndex: 0 ] ;
269
+ if ([firstOperation respondsToSelector: @selector (info )]) {
270
+ NSDictionary * info = [firstOperation info ] ;
271
+ groupName = [info objectForKey: constKeySSYOperationGroup] ;
272
+ }
273
+ }
274
+ if (!groupName) {
275
+ groupName = @" ?**?" ;
276
+ }
277
+ NSString * reason = [NSString stringWithFormat:
278
+ @" SSYOperations beginning with group %@ at %@ " ,
279
+ groupName,
280
+ [[NSDate date ] geekDateTimeString ]] ;
281
+ id activity = [[NSProcessInfo processInfo ] beginActivityWithOptions: NSActivityAutomaticTerminationDisabled
282
+ reason: reason] ;
283
+ /* SSYDBL*/ NSLog (@" Suspended app nap with activity=%@ for reason: %@ " , activity, reason) ;
284
+ [self setNoAppNapActivity: activity] ;
285
+ }
286
+ #endif
287
+
255
288
NSOperation <SSYOwnee> * operation = [[self operations ] objectAtIndex: 0 ] ;
256
289
id owner ;
257
290
if ([operation respondsToSelector: @selector (owner )]) {
0 commit comments