diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index d2b5c36c..7d407453 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -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]; diff --git a/MacPass/MPPluginHost.h b/MacPass/MPPluginHost.h index f763f422..80127091 100644 --- a/MacPass/MPPluginHost.h +++ b/MacPass/MPPluginHost.h @@ -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 *)entries; @end diff --git a/MacPass/MPPluginHost.m b/MacPass/MPPluginHost.m index f8a63b55..1918047e 100644 --- a/MacPass/MPPluginHost.m +++ b/MacPass/MPPluginHost.m @@ -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 {