From 1baf2cd8e6c545136f1deda01a6e8ab4ec79a776 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 15 Jul 2019 18:21:03 +0200 Subject: [PATCH] Display a generic description text if the appropriate key is present in the InfoDictionary of the plugin bundle --- MacPass/MPPlugin.h | 3 +++ MacPass/MPPlugin.m | 11 +++++++++++ MacPass/MPPluginPreferencesController.m | 21 ++++++++++++++------- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/MacPass/MPPlugin.h b/MacPass/MPPlugin.h index 47ef58f0..6ed402d4 100644 --- a/MacPass/MPPlugin.h +++ b/MacPass/MPPlugin.h @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN @class KPKTree; FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion; +FOUNDATION_EXPORT NSString *const MPPluginDescriptionInfoDictionaryKey; @interface MPPlugin : NSObject @@ -37,8 +38,10 @@ FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion; @property (copy, readonly) NSString *name; @property (nonatomic, copy, readonly, nullable) NSString *shortVersionString; @property (nonatomic, copy, readonly) NSString *versionString; +@property (nonatomic, copy, readonly) NSString *localizedDescription; @property (nonatomic, strong, readonly) NSBundle *bundle; + /** If your plugin needs initalization override this method but you have to call [super initWithPluginHost:] Otherwise your plugin might not get registered correctly diff --git a/MacPass/MPPlugin.m b/MacPass/MPPlugin.m index 1a84dbb3..5a69df18 100644 --- a/MacPass/MPPlugin.m +++ b/MacPass/MPPlugin.m @@ -28,6 +28,7 @@ #import "MPPluginVersionComparator.h" NSString *const MPPluginUnkownVersion = @"unkown.plugin.version"; +NSString *const MPPluginDescriptionInfoDictionaryKey = @"MPPluginDescription"; @implementation MPPlugin @@ -90,6 +91,16 @@ NSString *const MPPluginUnkownVersion = @"unkown.plugin.version"; return MPPluginUnkownVersion; } +- (NSString *)localizedDescription { + if([self.bundle.localizedInfoDictionary objectForKey:MPPluginDescriptionInfoDictionaryKey]) { + return self.bundle.localizedInfoDictionary[MPPluginDescriptionInfoDictionaryKey]; + } + if([self.bundle.infoDictionary objectForKey:MPPluginDescriptionInfoDictionaryKey]) { + return self.bundle.infoDictionary[MPPluginDescriptionInfoDictionaryKey]; + } + return @""; +} + - (void)didLoadPlugin { diff --git a/MacPass/MPPluginPreferencesController.m b/MacPass/MPPluginPreferencesController.m index eb07bebc..6aec8f57 100644 --- a/MacPass/MPPluginPreferencesController.m +++ b/MacPass/MPPluginPreferencesController.m @@ -124,22 +124,29 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]]; } + else { + [self _showInfoMessageForPlugin:plugin.localizedDescription]; + } } else if(nil != plugin) { - [self.settingsView addSubview:self.fallbackSettingsView]; - NSDictionary *dict = @{ @"view" : self.fallbackSettingsView, - @"table" : self.pluginTableView.enclosingScrollView }; - [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]]; - [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]]; if(plugin.errorMessage.length > 0) { - self.fallbackDescriptionTextField.stringValue = plugin.errorMessage; + [self _showInfoMessageForPlugin:plugin.errorMessage]; } else { - self.fallbackDescriptionTextField.stringValue = NSLocalizedString(@"PLUGIN_SETTINGS_GENERIC_ERROR_MESSAGE", "Generic message displayed if no details are know why a plugin was not loaded."); + [self _showInfoMessageForPlugin:NSLocalizedString(@"PLUGIN_SETTINGS_GENERIC_ERROR_MESSAGE", "Generic message displayed if no details are know why a plugin was not loaded.")]; } } } +- (void)_showInfoMessageForPlugin:(NSString *)message { + [self.settingsView addSubview:self.fallbackSettingsView]; + NSDictionary *dict = @{ @"view" : self.fallbackSettingsView, + @"table" : self.pluginTableView.enclosingScrollView }; + [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]]; + [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]]; + self.fallbackDescriptionTextField.stringValue = message.length > 0 ? message : @""; +} + - (MPPlugin *)pluginForRow:(NSInteger)row { NSArray *plugins = [MPPluginHost sharedHost].plugins; if(0 > row || row >= plugins.count) {