mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 13:29:46 +00:00
prototyped plugin repository browsing
This commit is contained in:
@@ -39,4 +39,5 @@ FOUNDATION_EXPORT NSString *const MPPluginUTI;
|
||||
*/
|
||||
FOUNDATION_EXPORT NSString *const MPBundleHelpURLKey; // MPHelpURL
|
||||
FOUNDATION_EXPORT NSString *const MPBundlePluginRepositoryURLKey; // MPPluginRepositoryURL
|
||||
FOUNDATION_EXPORT NSString *const MPBundlePluginCompaibilityURLKey; // MPPluginCompaibilityURL
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,7 @@ NSString *const MPKdbDocumentUTI = @"com.hicknhack.macpass.kdb";
|
||||
NSString *const MPKdbxDocumentUTI = @"com.hicknhack.macpass.kdbx";
|
||||
NSString *const MPPluginUTI = @"com.hicknhack.macpass.plugin";
|
||||
|
||||
NSString *const MPBundleHelpURLKey = @"MPHelpURL";
|
||||
NSString *const MPBundlePluginRepositoryURLKey = @"MPPluginRepositoryURL"
|
||||
NSString *const MPBundleHelpURLKey = @"MPHelpURL";
|
||||
NSString *const MPBundlePluginRepositoryURLKey = @"MPPluginRepositoryURL";
|
||||
NSString *const MPBundlePluginCompaibilityURLKey = @"MPPluginCompaibilityURL";
|
||||
|
||||
|
||||
31
MacPass/MPPluginRepository.h
Normal file
31
MacPass/MPPluginRepository.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// MPPluginRepository.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 04.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MPPluginRespositoryItem : NSObject
|
||||
|
||||
@property (copy) NSString *name;
|
||||
@property (copy) NSString *version;
|
||||
@property (copy) NSString *descriptionText;
|
||||
@property (copy) NSURL *sourceURL;
|
||||
@property (copy) NSURL *downloadURL;
|
||||
@property (readonly, nonatomic, getter=isVaid) BOOL valid;
|
||||
|
||||
+ (instancetype)pluginItemFromDictionary:(NSDictionary *)dict;
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPPluginRepository : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSArray<MPPluginRespositoryItem *> *availablePlugins;
|
||||
|
||||
+ (instancetype)sharedRespoitory;
|
||||
|
||||
@end
|
||||
94
MacPass/MPPluginRepository.m
Normal file
94
MacPass/MPPluginRepository.m
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// MPPluginRepository.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 04.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPPluginRepository.h"
|
||||
#import "MPConstants.h"
|
||||
|
||||
NSString *const MPPluginItemNameKey = @"name";
|
||||
NSString *const MPPluginItemDescriptionKey = @"description";
|
||||
NSString *const MPPluginItemDownloadURLKey = @"download";
|
||||
NSString *const MPPluginItemSourceURLKey = @"source";
|
||||
NSString *const MPPluginItemVersionKey = @"version";
|
||||
|
||||
@implementation MPPluginRespositoryItem
|
||||
|
||||
@dynamic valid;
|
||||
|
||||
+ (instancetype)pluginItemFromDictionary:(NSDictionary *)dict {
|
||||
return [[MPPluginRespositoryItem alloc] initWithDictionary:dict];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.name = dict[MPPluginItemNameKey];
|
||||
self.descriptionText = dict[MPPluginItemDescriptionKey];
|
||||
self.downloadURL = [NSURL URLWithString:dict[MPPluginItemDownloadURLKey]];
|
||||
self.sourceURL = [NSURL URLWithString:dict[MPPluginItemSourceURLKey]];
|
||||
self.version = dict[MPPluginItemVersionKey];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isVaid {
|
||||
/* name and download seems ok */
|
||||
return (self.name.length > 0 && self.downloadURL);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPPluginRepository
|
||||
|
||||
@dynamic availablePlugins;
|
||||
|
||||
+ (instancetype)sharedRespoitory {
|
||||
static MPPluginRepository *instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[MPPluginRepository alloc] init];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray<MPPluginRespositoryItem *> *)availablePlugins {
|
||||
NSString *urlString = NSBundle.mainBundle.infoDictionary[MPBundlePluginRepositoryURLKey];
|
||||
if(!urlString) {
|
||||
return @[];
|
||||
}
|
||||
NSURL *jsonURL = [NSURL URLWithString:urlString];
|
||||
if(!jsonURL) {
|
||||
return @[];
|
||||
}
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL options:0 error:&error];
|
||||
if(!jsonData) {
|
||||
return @[];
|
||||
}
|
||||
id jsonRoot = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
|
||||
if(!jsonRoot || ![jsonRoot isKindOfClass:NSArray.class]) {
|
||||
return @[];
|
||||
}
|
||||
NSMutableArray *items = [[NSMutableArray alloc] init];
|
||||
for(id item in jsonRoot) {
|
||||
if(![item isKindOfClass:NSDictionary.class]) {
|
||||
continue;
|
||||
}
|
||||
MPPluginRespositoryItem *pluginItem = [MPPluginRespositoryItem pluginItemFromDictionary:item];
|
||||
if(pluginItem.isVaid) {
|
||||
[items addObject:pluginItem];
|
||||
}
|
||||
}
|
||||
return [items copy];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -68,7 +68,7 @@
|
||||
<key>MPHelpURL</key>
|
||||
<string>https://github.com/mstarke/MacPass</string>
|
||||
<key>MPPluginRepositoryURL</key>
|
||||
<string>file:///Users/michael/Projekte/GitHub/MacPassPlugins/plugins.json</string>
|
||||
<string>https://macpass.github.io/data/plugins.json</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2012-2017 HicknHack Software GmbH. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
|
||||
Reference in New Issue
Block a user