Last active
April 29, 2016 16:08
-
-
Save torarnv/0a4b6b4509bad7682b2dc0c561ec4437 to your computer and use it in GitHub Desktop.
Finder progress POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang progress.mm -framework Cocoa -o progress | |
// ./progress | |
int main (int argc, const char * argv[]) | |
{ | |
NSString *program = [[[NSProcessInfo processInfo] arguments] firstObject]; | |
NSDictionary* userInfo = @{ | |
NSProgressFileOperationKindKey : NSProgressFileOperationKindReceiving, | |
NSProgressFileURLKey : [NSURL fileURLWithPath:program], | |
}; | |
NSProgress *progress = [[NSProgress alloc] initWithParent:nil userInfo:userInfo]; | |
progress.kind = NSProgressKindFile; | |
progress.pausable = NO; | |
progress.cancellable = YES; | |
progress.totalUnitCount = 10; | |
[progress publish]; | |
for (NSUInteger completedUnits = 0; completedUnits < progress.totalUnitCount; ++completedUnits) { | |
if ([progress isCancelled]) { | |
NSLog(@"Cancelled!"); | |
break; | |
} | |
sleep(1); | |
NSLog(@"Progress..."); | |
[progress setCompletedUnitCount:(completedUnits + 1)]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment