Restore application if an error occurs.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 13 Mar 2013 11:56:47 +0000 (12:56 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 13 Mar 2013 11:56:47 +0000 (12:56 +0100)
Classes/EnjoyableApplicationDelegate.m
Classes/NJDeviceController.m
Classes/NJHIDManager.m
Info.plist

index 6ccfc0f..f151399 100644 (file)
                                                object:self];
 }
 
+- (void)applicationWillBecomeActive:(NSNotification *)notification {
+    [self restoreToForeground:notification];
+}
+
 - (void)transformIntoElement:(id)sender {
     ProcessSerialNumber psn = { 0, kCurrentProcess };
     TransformProcessType(&psn, kProcessTransformToUIElementApplication);
index 610c07b..2f1736b 100644 (file)
@@ -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];
     }
 }
index 2a139df..5245bf5 100644 (file)
@@ -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);
index 04d4b4b..be1810b 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>228</string>
+       <string>244</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>