Skip to content

Commit

Permalink
[#206] fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jigish Patel committed Jan 31, 2013
1 parent fd6c58c commit 141f617
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Slate/RunningApplications.m
Expand Up @@ -380,9 +380,16 @@ - (void)applicationLaunched:(id)notification {
AXUIElementRef sendingApp = AXUIElementCreateApplication([launchedApp processIdentifier]);
AXObserverRef observer;
err = AXObserverCreate([launchedApp processIdentifier], windowCallback, &observer);
if (err != kAXErrorSuccess) return;
err = AXObserverAddNotification(observer, sendingApp, kAXWindowCreatedNotification, (__bridge void *)self);
err = AXObserverAddNotification(observer, sendingApp, kAXFocusedWindowChangedNotification, (__bridge void *)self);
err = AXObserverAddNotification(observer, sendingApp, kAXTitleChangedNotification, (__bridge void *)self);
if (err != kAXErrorSuccess) {
AXObserverRemoveNotification(observer, AXUIElementCreateApplication([launchedApp processIdentifier]), kAXWindowCreatedNotification);
AXObserverRemoveNotification(observer, AXUIElementCreateApplication([launchedApp processIdentifier]), kAXFocusedWindowChangedNotification);
AXObserverRemoveNotification(observer, AXUIElementCreateApplication([launchedApp processIdentifier]), kAXTitleChangedNotification);
return;
}
CFRunLoopAddSource ([[NSRunLoop currentRunLoop] getCFRunLoop], AXObserverGetRunLoopSource(observer), kCFRunLoopDefaultMode);
[pidToObserver setObject:[NSValue valueWithPointer:observer] forKey:[NSNumber numberWithInteger:[launchedApp processIdentifier]]];
[self bringAppToFront:launchedApp];
Expand All @@ -397,6 +404,8 @@ - (void)applicationKilled:(id)notification {
NSNumber *appPID = [NSNumber numberWithInteger:[app processIdentifier]];
[appToWindows removeObjectForKey:appPID];
AXObserverRemoveNotification([[pidToObserver objectForKey:[NSNumber numberWithInteger:[app processIdentifier]]] pointerValue], AXUIElementCreateApplication([app processIdentifier]), kAXWindowCreatedNotification);
AXObserverRemoveNotification([[pidToObserver objectForKey:[NSNumber numberWithInteger:[app processIdentifier]]] pointerValue], AXUIElementCreateApplication([app processIdentifier]), kAXFocusedWindowChangedNotification);
AXObserverRemoveNotification([[pidToObserver objectForKey:[NSNumber numberWithInteger:[app processIdentifier]]] pointerValue], AXUIElementCreateApplication([app processIdentifier]), kAXTitleChangedNotification);
[pidToObserver removeObjectForKey:[NSNumber numberWithInteger:[app processIdentifier]]];
[self pruneWindows];
[self bringAppToFront:[self currentApplication]];
Expand Down

0 comments on commit 141f617

Please sign in to comment.