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
This commit is contained in:
Julius Zint
2021-02-21 12:43:57 +01:00
parent 4aa812740f
commit 3c54cd9d7a

View File

@@ -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];
}