From 141f61751696269243ce5364e27e3109bdddebe9 Mon Sep 17 00:00:00 2001 From: Jigish Patel Date: Thu, 31 Jan 2013 13:51:39 -0800 Subject: [PATCH] [#206] fix crash --- Slate/RunningApplications.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Slate/RunningApplications.m b/Slate/RunningApplications.m index 7a19d10a..408b8758 100644 --- a/Slate/RunningApplications.m +++ b/Slate/RunningApplications.m @@ -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]; @@ -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]];