Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions memoryio/memoryio/TSAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

[self subscribeDisplayNotifications];
[self subscribePowerNotifications];
[self subscribeDistributedNotifications];

//put startup stuff here //NSUserDefaults standarduserdefaults boolforkey
BOOL startedAtLogin = NO;
Expand All @@ -130,6 +131,7 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification

[self unsubscribeDisplayNotifications];
[self unsubscribePowerNotifications];
[self unsubscribeDistributedNotifications];
}

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
Expand Down Expand Up @@ -323,4 +325,43 @@ - (void) takePhotoWithDelay: (float) delay {

}

// mainly for screensaver wakeup
- (void) callbackDistributedNotifications: (NSNotification*) note
{
NSLog(@"callbackDistributedNotifications: %@", [note name]);
[self takeBlockedImage];
}

// mainly for screensaver wakeup
- (void) subscribeDistributedNotifications
{
// Distribured Notification are everything that happens in the system.. Window change etc
// Here we could bind to other things as well, such as Spaces switch, or iTunes song change, etc.
// We're going to bind to the screensaver "did stop", that happens after you successfully unlock and close the scrensaver
NSLog(@"subscribeDistributedNotifications: subscribing");
NSNotificationCenter *center;

center = [NSDistributedNotificationCenter
notificationCenterForType: NSLocalNotificationCenterType];

[center addObserver: self
selector: @selector(callbackDistributedNotifications:)
name: @"com.apple.screensaver.didstop"
// name: nil // This would show us everything. Good for debug. Don't uncomment unless you comment out above image taking function in receiveDistributedNote
object: nil];

}

// mainly for screensaver wakeup
- (void) unsubscribeDistributedNotifications
{
NSLog(@"unsubscribeDistributedNotifications: unsubscribing");
NSNotificationCenter *center;

center = [NSDistributedNotificationCenter
notificationCenterForType: NSLocalNotificationCenterType];
[center removeObserver: self];

}

@end