mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-17 00:29:21 +00:00
Present buttons in notifications, reopen last document when none was open and user clicks on notification.
This commit is contained in:
@@ -51,4 +51,6 @@ APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
|||||||
|
|
||||||
- (void)lockAllDocuments;
|
- (void)lockAllDocuments;
|
||||||
|
|
||||||
|
- (void)showWelcomeWindow;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -125,13 +125,13 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
|||||||
|
|
||||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
||||||
if(!flag) {
|
if(!flag) {
|
||||||
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
BOOL reopen = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||||
BOOL showWelcomeScreen = YES;
|
BOOL showWelcomeScreen = YES;
|
||||||
if(reopen) {
|
if(reopen) {
|
||||||
showWelcomeScreen = ![self _reopenLastDocument];
|
showWelcomeScreen = ![((MPDocumentController *)NSDocumentController.sharedDocumentController) reopenLastDocument];
|
||||||
}
|
}
|
||||||
if(showWelcomeScreen) {
|
if(showWelcomeScreen) {
|
||||||
[self _showWelcomeWindow];
|
[self showWelcomeWindow];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
@@ -248,6 +248,11 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)showWelcomeWindow {
|
||||||
|
[self _loadWelcomeWindow];
|
||||||
|
[self.welcomeWindow makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)clearRememberdKeyFiles:(id)sender {
|
- (void)clearRememberdKeyFiles:(id)sender {
|
||||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
||||||
}
|
}
|
||||||
@@ -284,18 +289,13 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
|||||||
BOOL reopen = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
BOOL reopen = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||||
BOOL showWelcomeScreen = !restoredWindows && !_shouldOpenFile;
|
BOOL showWelcomeScreen = !restoredWindows && !_shouldOpenFile;
|
||||||
if(reopen && !restoredWindows && !_shouldOpenFile) {
|
if(reopen && !restoredWindows && !_shouldOpenFile) {
|
||||||
showWelcomeScreen = ![self _reopenLastDocument];
|
showWelcomeScreen = ![((MPDocumentController *)NSDocumentController.sharedDocumentController) reopenLastDocument];
|
||||||
}
|
}
|
||||||
if(showWelcomeScreen) {
|
if(showWelcomeScreen) {
|
||||||
[self _showWelcomeWindow];
|
[self showWelcomeWindow];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_showWelcomeWindow {
|
|
||||||
[self _loadWelcomeWindow];
|
|
||||||
[self.welcomeWindow makeKeyAndOrderFront:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)_loadWelcomeWindow {
|
- (void)_loadWelcomeWindow {
|
||||||
if(!_welcomeWindow) {
|
if(!_welcomeWindow) {
|
||||||
NSArray *topLevelObject;
|
NSArray *topLevelObject;
|
||||||
@@ -303,40 +303,4 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)_reopenLastDocument {
|
|
||||||
if(NSDocumentController.sharedDocumentController.documents.count > 0) {
|
|
||||||
return YES; // The document is already open
|
|
||||||
}
|
|
||||||
NSArray *recentDocuments = NSDocumentController.sharedDocumentController.recentDocumentURLs;
|
|
||||||
NSURL *documentUrl = nil;
|
|
||||||
if(recentDocuments.count > 0) {
|
|
||||||
documentUrl = recentDocuments.firstObject;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSString *lastPath = [NSUserDefaults.standardUserDefaults stringForKey:kMPSettingsKeyLastDatabasePath];
|
|
||||||
documentUrl =[NSURL URLWithString:lastPath];
|
|
||||||
}
|
|
||||||
BOOL isFileURL = documentUrl.fileURL;
|
|
||||||
if(isFileURL) {
|
|
||||||
[NSDocumentController.sharedDocumentController openDocumentWithContentsOfURL:documentUrl
|
|
||||||
display:YES
|
|
||||||
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
|
|
||||||
|
|
||||||
if(error != nil){
|
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
|
||||||
alert.messageText = NSLocalizedString(@"FILE_OPEN_ERROR", "Error while reopening last known documents");
|
|
||||||
alert.informativeText = error.localizedDescription;
|
|
||||||
alert.alertStyle = NSCriticalAlertStyle;
|
|
||||||
[alert runModal];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(document == nil){
|
|
||||||
[self _showWelcomeWindow];
|
|
||||||
}
|
|
||||||
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
return isFileURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -193,10 +193,12 @@ static MPAutotypeDaemon *_sharedInstance;
|
|||||||
notification.title = NSApp.applicationName;
|
notification.title = NSApp.applicationName;
|
||||||
notification.informativeText = NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_DOCUMENTS", "Notification: Autotype failed, no documents are open");
|
notification.informativeText = NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_DOCUMENTS", "Notification: Autotype failed, no documents are open");
|
||||||
notification.actionButtonTitle = NSLocalizedString(@"OPEN_DOCUMENT", "Action button in Notification to open a document");
|
notification.actionButtonTitle = NSLocalizedString(@"OPEN_DOCUMENT", "Action button in Notification to open a document");
|
||||||
//notification.showsButtons = YES;
|
notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeOpenDocumentRequest };
|
||||||
|
notification.showsButtons = YES;
|
||||||
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
|
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
|
||||||
MPDocument *document = evaluatedObject;
|
MPDocument *document = evaluatedObject;
|
||||||
return !document.encrypted;}];
|
return !document.encrypted;}];
|
||||||
@@ -219,7 +221,7 @@ static MPAutotypeDaemon *_sharedInstance;
|
|||||||
if(!entryOrNil) {
|
if(!entryOrNil) {
|
||||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||||
notification.title = NSApp.applicationName;
|
notification.title = NSApp.applicationName;
|
||||||
notification.userInfo = @{ kMPUserNotificationInfoKeyNotificationType: kMPUserNotificationTypeAutotype };
|
notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeFeedback };
|
||||||
if(context) {
|
if(context) {
|
||||||
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@", "Notification: Autotype found a single match for %@ (string placeholder)."), self.targetWindowTitle];
|
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@", "Notification: Autotype found a single match for %@ (string placeholder)."), self.targetWindowTitle];
|
||||||
}
|
}
|
||||||
@@ -320,8 +322,6 @@ static MPAutotypeDaemon *_sharedInstance;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_presentSelectionWindow:(NSArray *)candidates {
|
- (void)_presentSelectionWindow:(NSArray *)candidates {
|
||||||
|
|
||||||
|
|
||||||
if(!self.matchSelectionWindow) {
|
if(!self.matchSelectionWindow) {
|
||||||
self.matchSelectionWindow = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
self.matchSelectionWindow = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
||||||
styleMask:NSWindowStyleMaskNonactivatingPanel|NSWindowStyleMaskTitled
|
styleMask:NSWindowStyleMaskNonactivatingPanel|NSWindowStyleMaskTitled
|
||||||
|
|||||||
@@ -27,4 +27,6 @@
|
|||||||
- (IBAction)toggleAllowAllFiles:(id)sender;
|
- (IBAction)toggleAllowAllFiles:(id)sender;
|
||||||
- (IBAction)toggleShowHiddenFiles:(id)sender;
|
- (IBAction)toggleShowHiddenFiles:(id)sender;
|
||||||
|
|
||||||
|
- (BOOL)reopenLastDocument;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#import "MPDocumentController.h"
|
#import "MPDocumentController.h"
|
||||||
#import "MPConstants.h"
|
#import "MPConstants.h"
|
||||||
|
#import "MPSettingsHelper.h"
|
||||||
|
#import "MPAppDelegate.h"
|
||||||
|
|
||||||
#import "HNHUi/HNHUi.h"
|
#import "HNHUi/HNHUi.h"
|
||||||
|
|
||||||
@@ -76,4 +78,38 @@
|
|||||||
return [super typeForContentsOfURL:url error:outError];
|
return [super typeForContentsOfURL:url error:outError];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)reopenLastDocument {
|
||||||
|
if(self.documents.count > 0) {
|
||||||
|
return YES; // The document is already open
|
||||||
|
}
|
||||||
|
NSURL *documentUrl = nil;
|
||||||
|
if(self.recentDocumentURLs.count > 0) {
|
||||||
|
documentUrl = self.recentDocumentURLs.firstObject;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSString *lastPath = [NSUserDefaults.standardUserDefaults stringForKey:kMPSettingsKeyLastDatabasePath];
|
||||||
|
documentUrl =[NSURL URLWithString:lastPath];
|
||||||
|
}
|
||||||
|
BOOL isFileURL = documentUrl.fileURL;
|
||||||
|
if(isFileURL) {
|
||||||
|
[self openDocumentWithContentsOfURL:documentUrl
|
||||||
|
display:YES
|
||||||
|
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
|
||||||
|
|
||||||
|
if(error != nil){
|
||||||
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
|
alert.messageText = NSLocalizedString(@"FILE_OPEN_ERROR", "Error while reopening last known documents");
|
||||||
|
alert.informativeText = error.localizedDescription;
|
||||||
|
alert.alertStyle = NSCriticalAlertStyle;
|
||||||
|
[alert runModal];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(document == nil){
|
||||||
|
[(MPAppDelegate *)NSApp.delegate showWelcomeWindow];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
return isFileURL;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
FOUNDATION_EXTERN NSString *const kMPUserNotificationInfoKeyNotificationType;
|
FOUNDATION_EXTERN NSString *const MPUserNotificationTypeKey;
|
||||||
FOUNDATION_EXTERN NSString *const kMPUserNotificationTypeAutotype;
|
FOUNDATION_EXTERN NSString *const MPUserNotificationTypeAutotypeFeedback;
|
||||||
|
FOUNDATION_EXTERN NSString *const MPUserNotificationTypeAutotypeOpenDocumentRequest;
|
||||||
|
|
||||||
@interface MPUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
|
@interface MPUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "MPUserNotificationCenterDelegate.h"
|
#import "MPUserNotificationCenterDelegate.h"
|
||||||
|
#import "MPDocumentController.h"
|
||||||
|
|
||||||
NSString *const kMPUserNotificationInfoKeyNotificationType = @"kMPUserNotificationInfoKeyNotificationType";
|
NSString *const MPUserNotificationTypeKey = @"MPUserNotificationTypeKey";
|
||||||
NSString *const kMPUserNotificationTypeAutotype = @"kMPUserNotificationTypeAutotype";
|
NSString *const MPUserNotificationTypeAutotypeFeedback = @"MPUserNotificationTypeAutotypeFeedback";
|
||||||
|
NSString *const MPUserNotificationTypeAutotypeOpenDocumentRequest = @"MPUserNotificationTypeAutotypeOpenDocumentRequest";
|
||||||
|
|
||||||
@implementation MPUserNotificationCenterDelegate
|
@implementation MPUserNotificationCenterDelegate
|
||||||
|
|
||||||
@@ -36,16 +38,14 @@ NSString *const kMPUserNotificationTypeAutotype = @"kMPUserNotificationTypeAutot
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
|
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
|
||||||
NSLog(@"%@", notification);
|
NSDictionary *userInfo = notification.userInfo;
|
||||||
|
if([userInfo[MPUserNotificationTypeKey] isEqualToString:MPUserNotificationTypeAutotypeOpenDocumentRequest]) {
|
||||||
|
[((MPDocumentController*)NSDocumentController.sharedDocumentController) reopenLastDocument];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
||||||
NSDictionary *userInfo = notification.userInfo;
|
return [notification.userInfo[MPUserNotificationTypeKey] isEqualToString:MPUserNotificationTypeAutotypeFeedback];
|
||||||
if(!userInfo) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
NSString *value = userInfo[kMPUserNotificationInfoKeyNotificationType];
|
|
||||||
return [value isEqualToString:kMPUserNotificationTypeAutotype];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"ALERT_MERGE_CONTINUE" = "Daten synchronisieren.";
|
"ALERT_MERGE_CONTINUE" = "Daten synchronisieren.";
|
||||||
|
|
||||||
/* Informative text displayed when merging KDB files */
|
/* Informative text displayed when merging KDB files */
|
||||||
"ALERT_MERGE_KDB_FILE_INFO_TEXT" = "KDB Datenbanken enthalten nicht alle notwendigen Informationen für eine eindeutige Synchronisatione. Die Synchronisation der Daten von Einträgen erfolgt korrekt, jedoch können Gruppen nur anhand des Namens zugeordnet werden, was möglicherweise zu unerwarteten Ergebnissen führen kann. Soll mit der Synchronisation fortgefahren werden?";
|
"ALERT_MERGE_KDB_FILE_INFO_TEXT" = "KDB Datenbanken enthalten nicht alle notwendigen Informationen für eine eindeutige Synchronisation. Einzelne Einträgen werden korrekt synchronisiert. Gruppen werden jedoch nur durch den Namens zugeordnet werden, was zu unerwarteten Ergebnissen führen kann. Etwa können lokal bewegte Einträge wieder in alte Gruppen geschoben werden, unbenannte Gruppen können leer werden und die Einträge unter einer Gruppe mit dem vorherigen Namen wieder auftauchen. Weiterhin können gelöschte Einträge wieder auftauchen, da keine Informationen über diese gespeichert wird. Soll mit der Synchronisation fortgefahren werden?";
|
||||||
|
|
||||||
/* Alert message warning user about KDB file merge */
|
/* Alert message warning user about KDB file merge */
|
||||||
"ALERT_MERGE_KDB_FILE_MESSAGE" = "Es werden KDB Datenbanken synchronisiert! ";
|
"ALERT_MERGE_KDB_FILE_MESSAGE" = "Es werden KDB Datenbanken synchronisiert! ";
|
||||||
|
|||||||
Reference in New Issue
Block a user