mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-15 23:52:16 +00:00
Display a generic description text if the appropriate key is present in the InfoDictionary of the plugin bundle
This commit is contained in:
@@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@class KPKTree;
|
@class KPKTree;
|
||||||
|
|
||||||
FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion;
|
FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion;
|
||||||
|
FOUNDATION_EXPORT NSString *const MPPluginDescriptionInfoDictionaryKey;
|
||||||
|
|
||||||
@interface MPPlugin : NSObject
|
@interface MPPlugin : NSObject
|
||||||
|
|
||||||
@@ -37,8 +38,10 @@ FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion;
|
|||||||
@property (copy, readonly) NSString *name;
|
@property (copy, readonly) NSString *name;
|
||||||
@property (nonatomic, copy, readonly, nullable) NSString *shortVersionString;
|
@property (nonatomic, copy, readonly, nullable) NSString *shortVersionString;
|
||||||
@property (nonatomic, copy, readonly) NSString *versionString;
|
@property (nonatomic, copy, readonly) NSString *versionString;
|
||||||
|
@property (nonatomic, copy, readonly) NSString *localizedDescription;
|
||||||
@property (nonatomic, strong, readonly) NSBundle *bundle;
|
@property (nonatomic, strong, readonly) NSBundle *bundle;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
If your plugin needs initalization override this method but you have to call [super initWithPluginHost:]
|
If your plugin needs initalization override this method but you have to call [super initWithPluginHost:]
|
||||||
Otherwise your plugin might not get registered correctly
|
Otherwise your plugin might not get registered correctly
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#import "MPPluginVersionComparator.h"
|
#import "MPPluginVersionComparator.h"
|
||||||
|
|
||||||
NSString *const MPPluginUnkownVersion = @"unkown.plugin.version";
|
NSString *const MPPluginUnkownVersion = @"unkown.plugin.version";
|
||||||
|
NSString *const MPPluginDescriptionInfoDictionaryKey = @"MPPluginDescription";
|
||||||
|
|
||||||
@implementation MPPlugin
|
@implementation MPPlugin
|
||||||
|
|
||||||
@@ -90,6 +91,16 @@ NSString *const MPPluginUnkownVersion = @"unkown.plugin.version";
|
|||||||
return MPPluginUnkownVersion;
|
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 {
|
- (void)didLoadPlugin {
|
||||||
|
|
||||||
|
|||||||
@@ -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:@"H:|[view]|" options:0 metrics:nil views:dict]];
|
||||||
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[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) {
|
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) {
|
if(plugin.errorMessage.length > 0) {
|
||||||
self.fallbackDescriptionTextField.stringValue = plugin.errorMessage;
|
[self _showInfoMessageForPlugin:plugin.errorMessage];
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
- (MPPlugin *)pluginForRow:(NSInteger)row {
|
||||||
NSArray<MPPlugin __kindof *> *plugins = [MPPluginHost sharedHost].plugins;
|
NSArray<MPPlugin __kindof *> *plugins = [MPPluginHost sharedHost].plugins;
|
||||||
if(0 > row || row >= plugins.count) {
|
if(0 > row || row >= plugins.count) {
|
||||||
|
|||||||
Reference in New Issue
Block a user