Only attempt to instantiate a plug-in if it is not disabled, and disable it if we can't instantiate it.
authorPeter Hosey <hg@boredzo.org>
Wed Oct 07 03:20:25 2009 -0700 (2009-10-07)
changeset 44928fe45fd61f7d
parent 4491 5e2b01d86037
child 4493 233e2eb2e3da
Only attempt to instantiate a plug-in if it is not disabled, and disable it if we can't instantiate it.
Core/Source/GrowlPluginController.m
     1.1 --- a/Core/Source/GrowlPluginController.m	Wed Oct 07 03:20:25 2009 -0700
     1.2 +++ b/Core/Source/GrowlPluginController.m	Wed Oct 07 03:20:25 2009 -0700
     1.3 @@ -401,13 +401,19 @@
     1.4  		if (![bundlesToLazilyInstantiateAnInstanceFrom containsObject:bundle]) {
     1.5  			//We haven't previously queued it: Queue it.
     1.6  			[bundlesToLazilyInstantiateAnInstanceFrom addObject:bundle];
     1.7 -		} else {
     1.8 +		} else if (![disabledPlugins containsObject:name]) {
     1.9  			//We have: This is our cue to instantiate it.
    1.10  			plugin = [[[[bundle principalClass] alloc] init] autorelease];
    1.11  			//Dequeue it, because we don't want to hit this branch again for this plug-in.
    1.12  			[bundlesToLazilyInstantiateAnInstanceFrom removeObject:bundle];
    1.13 -			//Stash the plug-in instance in the plug-in dictionary. This retains the instance and means that we'll never hit the lazy-instantiation machinery again (because plugin will be non-nil).
    1.14 -			[pluginDict setObject:plugin forKey:GrowlPluginInfoKeyInstance];
    1.15 +			if (plugin) {
    1.16 +				//Stash the plug-in instance in the plug-in dictionary. This retains the instance and means that we'll never hit the lazy-instantiation machinery again (because plugin will be non-nil).
    1.17 +				[pluginDict setObject:plugin forKey:GrowlPluginInfoKeyInstance];
    1.18 +			} else {
    1.19 +				//Couldn't instantiate the plug-in, perhaps because of an architecture mismatch. Put it into disabled plug-ins.
    1.20 +				NSLog(@"Adding %@ to disabled plug-ins because we could not instantiate its class %@ (from bundle %@)", name, [bundle principalClass], bundle);
    1.21 +				[disabledPlugins addObject:name];
    1.22 +			}
    1.23  		}
    1.24  	}
    1.25  
    1.26 @@ -509,8 +515,9 @@
    1.27  	//Special handling if this plug-in is a display.
    1.28  	if ([self pluginWithDictionaryIsDisplayPlugin:pluginDict]) {
    1.29  		//If it doesn't respond to -requiresPositioning, it's old. Add it as a disabled plug-in.
    1.30 -		if(![[pluginDict valueForKey:GrowlPluginInfoKeyInstance] respondsToSelector:@selector(requiresPositioning)]) {
    1.31 -			[disabledPlugins addObject:[pluginDict valueForKey:GrowlPluginInfoKeyName]];
    1.32 +		if(plugin && ![plugin respondsToSelector:@selector(requiresPositioning)]) {
    1.33 +			NSLog(@"Adding %@ to disabled plug-ins because %@ is incompatible with Growl version 1.1 and later", [pluginDict objectForKey:GrowlPluginInfoKeyName], plugin);
    1.34 +			[disabledPlugins addObject:[pluginDict objectForKey:GrowlPluginInfoKeyName]];
    1.35  		} 
    1.36  		else {
    1.37  			//It responds to -requiresPositioning, so add it as a(n enabled) display plug-in.