From 3c54cd9d7a64277db885f330459854bacbfa3618 Mon Sep 17 00:00:00 2001 From: Julius Zint Date: Sun, 21 Feb 2021 12:43:57 +0100 Subject: [PATCH] Code refactoring to implement suggestions from the code review. Binding the touchIdEnabled Buttons state directly to the userdefaults value. Fixed bug that disabled the TouchIdEnabled button on an unsucessfull TouchId unlock --- MacPass/MPPasswordInputController.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index ed481ac7..679aae9d 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -29,6 +29,7 @@ #import "MPTouchBarButtonCreator.h" #import "MPSettingsHelper.h" #import "MPConstants.h" +#import "MPSettingsHelper.h" #import "HNHUi/HNHUi.h" @@ -90,10 +91,11 @@ static NSMutableDictionary* touchIDSecuredPasswords; [self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil]; [self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil]; [self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil]; + NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; + [self.touchIdEnabledButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEntryTouchIdEnabled] options:nil]; self.touchIdEnabledButton.hidden = true; if (@available(macOS 10.13.4, *)) { self.touchIdEnabledButton.hidden = false; - self.touchIdEnabledButton.state = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled]; [self _touchIdUpdateToolTip]; } [self _reset]; @@ -371,12 +373,11 @@ static NSMutableDictionary* touchIDSecuredPasswords; if(success) { return; } - [self.touchIdEnabledButton setEnabled:false]; + [self.touchIdButton setEnabled:false]; [self _showError:error]; } - (IBAction)touchIdEnabledChanged:(id)sender { - [NSUserDefaults.standardUserDefaults setInteger: self.touchIdEnabledButton.state forKey:kMPSettingsKeyEntryTouchIdEnabled]; [self _touchIdUpdateToolTip]; }