Skip to content

Instantly share code, notes, and snippets.

@torarnv
Last active April 29, 2016 16:08
Show Gist options
  • Save torarnv/0a4b6b4509bad7682b2dc0c561ec4437 to your computer and use it in GitHub Desktop.
Save torarnv/0a4b6b4509bad7682b2dc0c561ec4437 to your computer and use it in GitHub Desktop.
Finder progress POC
#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