Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Defer Canon SDK calls until later in application launch
Browse files Browse the repository at this point in the history
  • Loading branch information
bangnoise committed Aug 15, 2017
1 parent 848d7b1 commit 09acf9b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Camera Live/SyPCanonDSLR.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,24 @@ @implementation SyPCanonDSLR

+ (void)load
{
EdsInitializeSDK();
EdsSetCameraAddedHandler(SyPCanonDSLRHandleCameraAdded, NULL);
SyPCanonDSLRHandleCameraAdded(NULL);
}

__attribute__((destructor)) static void finalizer()
{
EdsTerminateSDK();
[[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationDidFinishLaunchingNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
EdsInitializeSDK();
EdsSetCameraAddedHandler(SyPCanonDSLRHandleCameraAdded, NULL);
SyPCanonDSLRHandleCameraAdded(NULL);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillTerminateNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
NSMutableSet *remove = [NSMutableSet setWithCapacity:1];
for (SyPCamera *camera in [SyPCamera cameras]) {
if ([camera isKindOfClass:[SyPCanonDSLR class]])
{
[remove addObject:camera];
}
}
for (SyPCamera *camera in remove) {
[SyPCamera removeCamera:camera];
}
EdsTerminateSDK();
}];
}

+ (NSError *)errorForEDSError:(EdsError)code
Expand Down

0 comments on commit 09acf9b

Please sign in to comment.