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 6ccfc0f0d06f9f53998dea4fa8d8104114b0547d..f1513996c2d8687d8a3c47d9e97d60012f04a35c 100644 (file)
                                                object:self];
 }
 
+- (void)applicationWillBecomeActive:(NSNotification *)notification {
+    [self restoreToForeground:notification];
+}
+
 - (void)transformIntoElement:(id)sender {
     ProcessSerialNumber psn = { 0, kCurrentProcess };
     TransformProcessType(&psn, kProcessTransformToUIElementApplication);
index 610c07b5a4f29c925572a850209c3b4e3d6bfc9d..2f1736b4b2e2ebd12fc50943fadb83ebc369b664 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 2a139df2a0678bd1ec9755204aa79b1601cc953b..5245bf562c41bf749dd30ea269bf5f644d95c8fc 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 04d4b4b396751ef47abdd00b9817b648eea6c347..be1810b5d843ca8f96b543033f99c40e9e520aee 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>