Extended password input API to allow for custom messages.

Autotype now dispays an info message when the database needs to be unlocked
This commit is contained in:
Michael Starke
2018-11-05 18:38:16 +01:00
parent c260202924
commit 0ff6597487
6 changed files with 23 additions and 6 deletions

View File

@@ -152,7 +152,7 @@ Gw
<constraint firstItem="d8O-Ha-rrS" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="vxq-YP-UhR"/>
<constraint firstItem="2" firstAttribute="leading" secondItem="2pb-ZG-spA" secondAttribute="trailing" constant="12" id="ytJ-5Z-5rT"/>
</constraints>
<point key="canvasLocation" x="-43" y="-59"/>
<point key="canvasLocation" x="77" y="-2"/>
</customView>
</objects>
<resources>

View File

@@ -22,6 +22,7 @@
#import "MPAutotypeDaemon.h"
#import "MPDocument.h"
#import "MPDocumentWindowController.h"
#import "MPAutotypeCommand.h"
#import "MPAutotypeContext.h"
#import "MPAutotypePaste.h"
@@ -208,7 +209,10 @@ static MPAutotypeDaemon *_sharedInstance;
[NSApp activateIgnoringOtherApps:YES];
[NSApp.mainWindow makeKeyAndOrderFront:self];
/* show the actual document window to the user */
[documents.firstObject showWindows];
MPDocument *document = documents.firstObject;
[document showWindows];
MPDocumentWindowController *wc = document.windowControllers.firstObject;
[wc showPasswordInputWithMessage:NSLocalizedString(@"AUTOTYPE_MESSAGE_UNLOCK_DATABASE", @"Message displayed to the user to unlock the database to perform global autotype")];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
return; // wait for the unlock to happen
}

View File

@@ -44,6 +44,7 @@
- (void)showEntries;
- (void)showPasswordInput;
- (void)showPasswordInputWithMessage:(NSString *)message;
- (void)editPasswordWithCompetionHandler:(void (^)(NSInteger result))handler;
#pragma mark Actions

View File

@@ -285,7 +285,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
if(![menuItem.representedObject isKindOfClass:NSDictionary.class]) {
return;
}
NSWindow *sheetWindow = ((MPDocument *)self.document).windowForSheet;
if(!sheetWindow) {
return;
@@ -323,15 +323,19 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
}
- (void)showPasswordInput {
[self showPasswordInputWithMessage:nil];
}
- (void)showPasswordInputWithMessage:(NSString *)message {
if(!self.passwordInputController) {
self.passwordInputController = [[MPPasswordInputController alloc] init];
}
[self _setContentViewController:self.passwordInputController];
[self.passwordInputController requestPasswordWithCompletionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL cancel, NSError *__autoreleasing *error) {
if(cancel) {
[self.passwordInputController requestPasswordWithMessage:message cancelLabel:nil completionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
if(didCancel) {
return NO;
}
return [((MPDocument *)self.document) unlockWithPassword:password keyFileURL:keyURL error:error];
}];
}

View File

@@ -153,8 +153,12 @@
self.messageInfoTextField.hidden = (nil == self.message);
if(self.message) {
self.messageInfoTextField.stringValue = self.message;
self.messageImageView.image = [NSImage imageNamed:NSImageNameInfo];
}
self.messageImageView.hidden = (nil == self.message);;
else {
self.messageImageView.image = [NSImage imageNamed:NSImageNameCaution];
}
self.messageImageView.hidden = (nil == self.message);
self.cancelButton.hidden = (nil == self.cancelLabel);
if(self.cancelLabel) {
self.cancelButton.stringValue = self.cancelLabel;
@@ -172,6 +176,7 @@
self.messageInfoTextField.stringValue = error.descriptionForErrorCode;
}
self.messageImageView.hidden = NO;
self.messageImageView.image = [NSImage imageNamed:NSImageNameCaution];
self.messageInfoTextField.hidden = NO;
}

View File

@@ -74,6 +74,9 @@
/* Inherit autotype settings menu item */
"AUTOTYPE_INHERIT" = "Inherit Autotype Settings";
/* Message displayed to the user to unlock the database to perform global autotype */
"AUTOTYPE_MESSAGE_UNLOCK_DATABASE" = "Please unlock the database to use Global Autotype";
/* Disable autotype menu item */
"AUTOTYPE_NO" = "Disable Autotype";