mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 19:22:25 +00:00
changed plugin APIs for entryAcitonPlugins and customAttributePlugins.
Internal housekeeping on MPPluginHost to allow for better access to certain plugins Still pending: menu action to plugin delegation
This commit is contained in:
@@ -65,13 +65,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
MacPass will call you back via -[MPPlugin performActionFroMenuItem:withEntries:]
|
||||
*/
|
||||
@protocol MPEntryActionPlugin <NSObject>
|
||||
@optional
|
||||
- (NSMenuItem * _Nullable)menuItemForEntry;
|
||||
@required
|
||||
- (NSArray<NSMenuItem *> *)menuItemsForEntries:(NSArray< KPKEntry *>*)entries;
|
||||
- (void)performActionForMenuItem:(NSMenuItem *)item withEntries:(NSArray <KPKEntry *>*)entries;
|
||||
@end
|
||||
|
||||
@protocol MPCustomAttributePlugin <NSObject>
|
||||
@optional
|
||||
@required
|
||||
/* Supply a list of attribute keys that will get suggested for autocompletion as well as added to the extend add for custom fields */
|
||||
@property (nonatomic,copy) NSArray<NSString *>* attributeKeys;
|
||||
/*
|
||||
|
||||
@@ -30,6 +30,7 @@ FOUNDATION_EXPORT NSString *const MPPluginHostDidLoadPlugin;
|
||||
FOUNDATION_EXPORT NSString *const MPPluginHostPluginBundleIdentifiyerKey;
|
||||
|
||||
@class MPPlugin;
|
||||
@class KPKEntry;
|
||||
|
||||
@interface MPPluginHost : NSObject
|
||||
|
||||
@@ -50,4 +51,5 @@ FOUNDATION_EXPORT NSString *const MPPluginHostPluginBundleIdentifiyerKey;
|
||||
- (NSArray <MPPlugin __kindof*>*)autotypePlugins;
|
||||
- (NSArray <MPPlugin __kindof*>*)entryContextMenuPlugins;
|
||||
*/
|
||||
- (NSArray *)menuItemsForEntries:(NSArray <KPKEntry *>*)entries;
|
||||
@end
|
||||
|
||||
@@ -40,6 +40,10 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
||||
|
||||
@interface MPPluginHost ()
|
||||
@property (strong) NSMutableArray<MPPlugin __kindof *> *mutablePlugins;
|
||||
@property (strong) NSPointerArray *entryActionPlugins;
|
||||
@property (strong) NSPointerArray *customAttributePlugins;
|
||||
|
||||
|
||||
@property (nonatomic) BOOL loadUnsecurePlugins;
|
||||
@property (copy) NSArray<NSString *> *disabledPlugins;
|
||||
|
||||
@@ -70,6 +74,9 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
||||
_mutablePlugins = [[NSMutableArray alloc] init];
|
||||
_disabledPlugins = [[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyLoadUnsecurePlugins];
|
||||
_loadUnsecurePlugins = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyLoadUnsecurePlugins];
|
||||
_entryActionPlugins = [NSPointerArray weakObjectsPointerArray];
|
||||
_customAttributePlugins = [NSPointerArray weakObjectsPointerArray];
|
||||
|
||||
[self _loadPlugins];
|
||||
|
||||
[self bind:NSStringFromSelector(@selector(loadUnsecurePlugins))
|
||||
@@ -205,7 +212,7 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPPluginHostWillLoadPlugin
|
||||
object:self
|
||||
userInfo:@{ MPPluginHostPluginBundleIdentifiyerKey : plugin.identifier }];
|
||||
[self.mutablePlugins addObject:plugin];
|
||||
[self _addPlugin:plugin];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPPluginHostDidLoadPlugin
|
||||
object:self
|
||||
userInfo:@{ MPPluginHostPluginBundleIdentifiyerKey : plugin.identifier }];
|
||||
@@ -222,7 +229,7 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
||||
plugin.bundle = bundle;
|
||||
plugin.enabled = NO;
|
||||
plugin.errorMessage = errorMessage;
|
||||
[self.mutablePlugins addObject:plugin];
|
||||
[self _addPlugin:plugin];
|
||||
}
|
||||
|
||||
- (BOOL)_validateUniqueBundle:(NSBundle *)bundle {
|
||||
@@ -286,4 +293,28 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)_addPlugin:(MPPlugin *)plugin {
|
||||
[self.mutablePlugins addObject:plugin];
|
||||
if([plugin conformsToProtocol:@protocol(MPEntryActionPlugin)]) {
|
||||
[self.entryActionPlugins addPointer:(__bridge void * _Nullable)(plugin)];
|
||||
}
|
||||
if([plugin conformsToProtocol:@protocol(MPCustomAttributePlugin)]) {
|
||||
[self.customAttributePlugins addPointer:(__bridge void * _Nullable)(plugin)];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Action Plugins
|
||||
|
||||
- (NSArray *)menuItemsForEntries:(NSArray<KPKEntry *> *)entries {
|
||||
NSMutableArray *items = [[NSMutableArray alloc] init];
|
||||
for(id<MPEntryActionPlugin> plugin in self.entryActionPlugins) {
|
||||
if(plugin) {
|
||||
[items addObjectsFromArray:[plugin menuItemsForEntries:entries]];
|
||||
}
|
||||
}
|
||||
return [items copy];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user