mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 08:49:42 +00:00
dedicated delegate for user interaction with notifications
This commit is contained in:
@@ -81,19 +81,19 @@ static MPAutotypeDaemon *_sharedInstance;
|
||||
_enabled = NO;
|
||||
_targetPID = -1;
|
||||
[self bind:NSStringFromSelector(@selector(enabled))
|
||||
toObject:[NSUserDefaultsController sharedUserDefaultsController]
|
||||
toObject:NSUserDefaultsController.sharedUserDefaultsController
|
||||
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype]
|
||||
options:nil];
|
||||
|
||||
[self bind:NSStringFromSelector(@selector(hotKeyData))
|
||||
toObject:[NSUserDefaultsController sharedUserDefaultsController]
|
||||
toObject:NSUserDefaultsController.sharedUserDefaultsController
|
||||
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]
|
||||
options:nil];
|
||||
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
|
||||
selector:@selector(_didDeactivateApplication:)
|
||||
name:NSWorkspaceDidDeactivateApplicationNotification
|
||||
object:nil];
|
||||
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self
|
||||
selector:@selector(_didDeactivateApplication:)
|
||||
name:NSWorkspaceDidDeactivateApplicationNotification
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -164,13 +164,14 @@ static MPAutotypeDaemon *_sharedInstance;
|
||||
}
|
||||
|
||||
/* find autotype documents */
|
||||
NSArray *documents = [NSApp orderedDocuments];
|
||||
NSArray *documents = NSApp.orderedDocuments;
|
||||
/* No open document, inform the user and return without any action */
|
||||
if(documents.count == 0) {
|
||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||
notification.title = NSApp.applicationName;
|
||||
notification.informativeText = NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_DOCUMENTS", "Notification: Autotype failed, no documents are open");
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
|
||||
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
||||
return;
|
||||
}
|
||||
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
|
||||
@@ -183,7 +184,7 @@ static MPAutotypeDaemon *_sharedInstance;
|
||||
[NSApp.mainWindow makeKeyAndOrderFront:self];
|
||||
/* show the actual document window to the user */
|
||||
[documents.firstObject showWindows];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
|
||||
return; // wait for the unlock to happen
|
||||
}
|
||||
|
||||
@@ -201,7 +202,7 @@ static MPAutotypeDaemon *_sharedInstance;
|
||||
else {
|
||||
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH_FOR_%@", "Noticiation: Autotype failed to find a match for %@ (string placeholder)"), self.targetWindowTitle];
|
||||
}
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
||||
}
|
||||
[self _performAutotypeForContext:context];
|
||||
}
|
||||
|
||||
13
MacPass/MPUserNotificationCenterDelegate.h
Normal file
13
MacPass/MPUserNotificationCenterDelegate.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// MPUserNotificationCenterDelegate.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 05.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MPUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
|
||||
|
||||
@end
|
||||
21
MacPass/MPUserNotificationCenterDelegate.m
Normal file
21
MacPass/MPUserNotificationCenterDelegate.m
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// MPUserNotificationCenterDelegate.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 05.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPUserNotificationCenterDelegate.h"
|
||||
|
||||
@implementation MPUserNotificationCenterDelegate
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13529"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -66,7 +66,7 @@
|
||||
<rect key="frame" x="1" y="1" width="118" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField identifier="DataCell" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ADN-XZ-Lq7">
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ADN-XZ-Lq7">
|
||||
<rect key="frame" x="0.0" y="0.0" width="118" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="e8U-mE-mZh">
|
||||
@@ -125,7 +125,7 @@
|
||||
<rect key="frame" x="1" y="255" width="432" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="b5D-WW-IPI">
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="b5D-WW-IPI">
|
||||
<rect key="frame" x="224" y="17" width="15" height="102"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
|
||||
Reference in New Issue
Block a user