Extracted MPPluginRepositoryItem into a seperate file

This commit is contained in:
Michael Starke
2018-03-08 21:42:38 +01:00
parent 5a5064da43
commit 9314b84b9d
7 changed files with 94 additions and 56 deletions

View File

@@ -28,6 +28,6 @@ NSString *const MPKdbxDocumentUTI = @"com.hicknhack.macpass.kdbx";
NSString *const MPPluginUTI = @"com.hicknhack.macpass.plugin";
NSString *const MPBundleHelpURLKey = @"MPHelpURL";
NSString *const MPBundlePluginRepositoryURLKey = @"MPPluginRepositoryURL";
NSString *const MPBundlePluginCompaibilityURLKey = @"MPPluginCompaibilityURL";
NSString *const MPBundlePluginRepositoryURLKey = @"MPPluginRepositoryURLKey";
NSString *const MPBundlePluginCompadibilityURLKey = @"MPPluginCompadibilityURLKey";

View File

@@ -13,7 +13,4 @@
FOUNDATION_EXPORT NSString *const MPPluginFileExtension;
FOUNDATION_EXPORT NSString *const MPPluginMinimumHostVersionKey;
FOUNDATION_EXPORT NSString *const MPPluginMaxiumHostVersoinKey;
#endif /* MPPluginConstants_h */

View File

@@ -6,26 +6,14 @@
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@import Foundation;
@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
@class MPPluginRepositoryItem;
@interface MPPluginRepository : NSObject
@property (nonatomic, copy) NSArray<MPPluginRespositoryItem *> *availablePlugins;
@property (class, strong, readonly) MPPluginRepository *sharedRespoitory;
@property (nonatomic, copy) NSArray<MPPluginRepositoryItem *> *availablePlugins;
+ (instancetype)sharedRespoitory;
@end

View File

@@ -8,39 +8,7 @@
#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
#import "MPPluginRepositoryItem.h"
@implementation MPPluginRepository
@@ -60,7 +28,7 @@ NSString *const MPPluginItemVersionKey = @"version";
return self;
}
- (NSArray<MPPluginRespositoryItem *> *)availablePlugins {
- (NSArray<MPPluginRepositoryItem *> *)availablePlugins {
NSString *urlString = NSBundle.mainBundle.infoDictionary[MPBundlePluginRepositoryURLKey];
if(!urlString) {
return @[];
@@ -83,7 +51,7 @@ NSString *const MPPluginItemVersionKey = @"version";
if(![item isKindOfClass:NSDictionary.class]) {
continue;
}
MPPluginRespositoryItem *pluginItem = [MPPluginRespositoryItem pluginItemFromDictionary:item];
MPPluginRepositoryItem *pluginItem = [MPPluginRepositoryItem pluginItemFromDictionary:item];
if(pluginItem.isVaid) {
[items addObject:pluginItem];
}

View File

@@ -0,0 +1,25 @@
//
// MPPluginRepositoryItem.h
// MacPass
//
// Created by Michael Starke on 08.03.18.
// Copyright © 2018 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MPPluginRepositoryItem : NSObject
@property (copy,readonly) NSString *name;
@property (copy,readonly) NSString *currentVersion;
@property (copy,readonly) NSString *descriptionText;
@property (copy,readonly) NSURL *sourceURL;
@property (copy,readonly) NSURL *downloadURL;
@property (copy,readonly) NSURL *bundleIdentifier;
@property (readonly, nonatomic, getter=isVaid) BOOL valid;
+ (instancetype)pluginItemFromDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
@end

View File

@@ -0,0 +1,54 @@
//
// MPPluginRepositoryItem.m
// MacPass
//
// Created by Michael Starke on 08.03.18.
// Copyright © 2018 HicknHack Software GmbH. All rights reserved.
//
#import "MPPluginRepositoryItem.h"
NSString *const MPPluginItemNameKey = @"name";
NSString *const MPPluginItemDescriptionKey = @"description";
NSString *const MPPluginItemDownloadURLKey = @"download";
NSString *const MPPluginItemSourceURLKey = @"source";
NSString *const MPPluginItemCurrentVersionKey = @"currentVersion";
@interface MPPluginRepositoryItem ()
@property (copy) NSString *name;
@property (copy) NSString *currentVersion;
@property (copy) NSString *descriptionText;
@property (copy) NSURL *sourceURL;
@property (copy) NSURL *downloadURL;
@property (copy) NSURL *bundleIdentifier;
@end
@implementation MPPluginRepositoryItem
@dynamic valid;
+ (instancetype)pluginItemFromDictionary:(NSDictionary *)dict {
return [[MPPluginRepositoryItem 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.currentVersion = dict[MPPluginItemCurrentVersionKey];
}
return self;
}
- (BOOL)isVaid {
/* name and download seems ok */
return (self.name.length > 0 && self.downloadURL);
}
@end