From e145d677ef4d1f03bbbc9944829d95f4d4cdc1bb Mon Sep 17 00:00:00 2001 From: Daniele Cattaneo Date: Sat, 31 Aug 2019 16:29:54 +0200 Subject: [PATCH] Do not randomly disconnect switch pro controllers when closing a game. Also, fix a comment which erroneously contradicted the code --- .../OESwitchProControllerHIDDeviceHandler.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/OpenEmuSystem/OESwitchProControllerHIDDeviceHandler.m b/OpenEmuSystem/OESwitchProControllerHIDDeviceHandler.m index e71387b..16bb787 100644 --- a/OpenEmuSystem/OESwitchProControllerHIDDeviceHandler.m +++ b/OpenEmuSystem/OESwitchProControllerHIDDeviceHandler.m @@ -257,16 +257,21 @@ static OEHACProControllerStickCalibration OEHACConvertCalibration( [self _setPlayerLights:0x0F]; [self _requestCalibrationData]; + + if ([[[NSBundle mainBundle] bundleIdentifier] isEqual:@"org.openemu.OpenEmu"]) { + /* we don't want to disconnect the controller every time the helper app terminates, + * just when OpenEmu closes */ + NSNotificationCenter * __weak nc = [NSNotificationCenter defaultCenter]; + id __block token = [nc addObserverForName:NSApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { + [self _setPowerState:OEHACPowerStateSleep]; + [nc removeObserver:token]; + }]; + } + return YES; } -- (void)disconnect -{ - [self _setPowerState:OEHACPowerStateSleep]; -} - - #pragma mark - Calibration @@ -332,7 +337,7 @@ static OEHACProControllerStickCalibration OEHACConvertCalibration( res /= (CGFloat)(selectedCalibration->max - selectedCalibration->zero); } - /* the factory calibration is a bit conservative at the edges; compensate for that */ + /* the factory calibration is a bit generous at the edges; compensate for that */ res /= 0.90; return MAX(-1, MIN(res, 1));