Moved plugin loading into initialzation of plugin host again.

This commit is contained in:
Michael Starke
2019-02-05 09:32:35 +01:00
parent e5ad0728cc
commit f95819ab98
3 changed files with 39 additions and 27 deletions

View File

@@ -184,11 +184,10 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
#if defined(NO_SPARKLE)
NSLog(@"Sparkle explicitly disabled!!!");
#endif
/* Daemon instanziieren */
/* Initalizes Global Daemons */
[MPLockDaemon defaultDaemon];
[MPAutotypeDaemon defaultDaemon];
/* Create Plugin Manager */
[MPPluginHost.sharedHost loadPlugins];
[MPPluginHost sharedHost];
#if !defined(DEBUG) && !defined(NO_SPARKLE)
/* Disable updates if in debug or nosparkle */
[SUUpdater sharedUpdater];

View File

@@ -48,8 +48,6 @@ FOUNDATION_EXPORT NSString *const MPPluginHostPluginBundleIdentifiyerKey;
- (void)disablePlugin:(MPPlugin *)plugin;
- (void)enablePlugin:(MPPlugin *)plugin;
- (void)loadPlugins;
- (MPPlugin *)pluginWithBundleIdentifier:(NSString *)identifer;
- (NSArray *)avilableMenuItemsForEntries:(NSArray <KPKEntry *>*)entries;
@end

View File

@@ -75,6 +75,16 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
_mutablePlugins = [[NSMutableArray alloc] init];
_entryActionPluginIdentifiers = [[NSMutableArray alloc] init];
_customAttributePluginIdentifiers = [[NSMutableArray alloc] init];
if(MPPluginRepository.defaultRepository.isInitialized) {
[self _loadPlugins];
}
else {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(_didUpdateAvailablePlugins:)
name:MPPluginRepositoryDidUpdateAvailablePluginsNotification
object:MPPluginRepository.defaultRepository];
}
}
return self;
}
@@ -142,18 +152,6 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
#pragma mark - Plugin Loading
- (void)loadPlugins {
if(MPPluginRepository.defaultRepository.isInitialized) {
[self _loadPlugins];
}
else {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(_didUpdateAvailablePlugins:)
name:MPPluginRepositoryDidUpdateAvailablePluginsNotification
object:MPPluginRepository.defaultRepository];
}
}
- (void)_didUpdateAvailablePlugins:(NSNotification *)notification {
[NSNotificationCenter.defaultCenter removeObserver:self
name:MPPluginRepositoryDidUpdateAvailablePluginsNotification
@@ -188,7 +186,7 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
NSLog(@"No internal plugins found!");
}
NSArray *pluginURLs = [externalPluginsURLs arrayByAddingObjectsFromArray:internalPluginsURLs];
NSMutableArray *incompatiblePlugins = [[NSMutableArray alloc] init];
for(NSURL *pluginURL in pluginURLs) {
if(![self _isValidPluginURL:pluginURL]) {
NSLog(@"Skipping %@. No valid plugin file.", pluginURL.path);
@@ -202,7 +200,9 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
}
if([self _isDisabledPluginBundle:pluginBundle]) {
[self _addPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_DISABLED_PLUGIN", "Error for a plugin that is disabled.")];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_DISABLED_PLUGIN", "Error for a plugin that is disabled.")];
[self _addPlugin:plugin];
continue;
}
if(![self _isSignedPluginURL:pluginURL]) {
@@ -211,7 +211,8 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
NSLog(@"Loading unsecure Plugin at %@.", pluginURL.path);
}
else {
[self _addPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_UNSECURE_PLUGIN", "Error for a plugin that was not signed properly")];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_UNSECURE_PLUGIN", "Error for a plugin that was not signed properly")];
[self _addPlugin:plugin];
continue;
}
}
@@ -219,7 +220,8 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
NSError *error;
if(![pluginBundle preflightAndReturnError:&error]) {
NSLog(@"Preflight Error %@ %@", error.localizedDescription, error.localizedFailureReason );
[self _addPluginForBundle:pluginBundle error:error.localizedDescription];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:error.localizedDescription];
[self _addPlugin:plugin];
continue;
};
@@ -230,19 +232,23 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
if(![self _isCompatiblePluginBundle:pluginBundle error:&error]) {
NSLog(@"Plugin %@ is not compatible with host!", pluginBundle.bundleIdentifier);
[self _addPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_HOST_VERSION_NOT_SUPPORTED", "Plugin is not with this version of MacPass")];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_HOST_VERSION_NOT_SUPPORTED", "Plugin is not with this version of MacPass")];
[self _addPlugin:plugin];
[incompatiblePlugins addObject:plugin];
continue;
}
if(![pluginBundle loadAndReturnError:&error]) {
NSLog(@"Bundle Loading Error %@ %@", error.localizedDescription, error.localizedFailureReason);
[self _addPluginForBundle:pluginBundle error:error.localizedDescription];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:error.localizedDescription];
[self _addPlugin:plugin];
continue;
}
if(![self _isValidPluginClass:pluginBundle.principalClass]) {
NSLog(@"Wrong principal Class.");
[self _addPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_WRONG_PRINCIPAL_CLASS", "Plugin specifies the wrong principla class!".)];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_WRONG_PRINCIPAL_CLASS", "Plugin specifies the wrong principla class!".)];
[self _addPlugin:plugin];
continue;
}
@@ -270,17 +276,26 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
}
else {
NSLog(@"Unable to create instance of plugin class %@", pluginBundle.principalClass);
[self _addPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_INTILIZATION_FAILED", "The plugin could not be initalized".)];
MPPlugin *plugin = [self _createPluginForBundle:pluginBundle error:NSLocalizedString(@"PLUGIN_ERROR_INTILIZATION_FAILED", "The plugin could not be initalized".)];
[self _addPlugin:plugin];
}
}
if(incompatiblePlugins.count > 0) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"ALERT_INCOMPATIBLE_PLUGINS_ENCOUNTERED_MESSAGE", "Message text of the alert displayed when plugins where disabled due to incompatibilty");
alert.informativeText = NSLocalizedString(@"ALERT_INCOMPATIBLE_PLUGINS_ENCOUNTERED_INFORMATIVE_TEXT", "Informative text of the alert displayed when plugins where disabled due to incompatibilty");
alert.alertStyle = NSAlertStyleWarning;
alert.showsSuppressionButton = YES;
[alert runModal];
}
}
- (void)_addPluginForBundle:(NSBundle *)bundle error:(NSString *)errorMessage {
- (MPPlugin *)_createPluginForBundle:(NSBundle *)bundle error:(NSString *)errorMessage {
MPPlugin *plugin = [[MPPlugin alloc] initWithPluginHost:self];
plugin.bundle = bundle;
plugin.enabled = NO;
plugin.errorMessage = errorMessage;
[self _addPlugin:plugin];
return plugin;
}
- (BOOL)_isUniqueBundle:(NSBundle *)bundle {