From: Joe Wreschnig Date: Wed, 13 Mar 2013 11:56:47 +0000 (+0100) Subject: Restore application if an error occurs. X-Git-Tag: version-1.1~36 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=bda2aa3a8897f574b97c0bd125e84374087017a9;p=enjoyable.git Restore application if an error occurs. --- diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 6ccfc0f..f151399 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -67,6 +67,10 @@ object:self]; } +- (void)applicationWillBecomeActive:(NSNotification *)notification { + [self restoreToForeground:notification]; +} + - (void)transformIntoElement:(id)sender { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToUIElementApplication); diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 610c07b..2f1736b 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -210,11 +210,23 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { } - (void)hidManager:(NJHIDManager *)manager didError:(NSError *)error { - [outlineView.window presentError:error - modalForWindow:outlineView.window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + // Since the error shows the window, it can trigger another attempt + // to re-open the HID manager, which will also probably fail and error, + // so don't bother repeating ourselves. + if (!outlineView.window.attachedSheet) { + [NSApplication.sharedApplication activateIgnoringOtherApps:YES]; + [outlineView.window makeKeyAndOrderFront:nil]; + [outlineView.window presentError:error + modalForWindow:outlineView.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; + } + self.translatingEvents = NO; + if (manager.running) + [self hidManagerDidStart:manager]; + else + [self hidManagerDidStop:manager]; } - (void)hidManagerDidStart:(NJHIDManager *)manager { @@ -313,7 +325,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn if (!translatingEvents && !NSApplication.sharedApplication.isActive) [self stopHid]; - else if (translatingEvents || NSApplication.sharedApplication.isActive) + else [self startHid]; } } diff --git a/Classes/NJHIDManager.m b/Classes/NJHIDManager.m index 2a139df..5245bf5 100644 --- a/Classes/NJHIDManager.m +++ b/Classes/NJHIDManager.m @@ -55,6 +55,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD IOHIDManagerClose(manager, kIOHIDOptionsTypeNone); CFRelease(manager); [self.delegate hidManager:self didError:error]; + NSLog(@"Error starting HID manager: %@.", error); } else { _manager = manager; IOHIDManagerScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); diff --git a/Info.plist b/Info.plist index 04d4b4b..be1810b 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 228 + 244 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright