Skip to content
This repository has been archived by the owner on Oct 11, 2018. It is now read-only.

new function added #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Sketch Toolbox.xcodeproj/project.pbxproj
100644 → 100755
Empty file.
Empty file.
98 changes: 65 additions & 33 deletions Sketch Toolbox/Base.lproj/MainMenu.xib
100644 → 100755

Large diffs are not rendered by default.

Empty file modified Sketch Toolbox/Constants.h
100644 → 100755
Empty file.
Empty file modified Sketch Toolbox/Constants.m
100644 → 100755
Empty file.
Empty file modified Sketch Toolbox/Images.xcassets/AppIcon.appiconset/Contents.json
100644 → 100755
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Sketch Toolbox/Images.xcassets/Download.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
4 changes: 4 additions & 0 deletions Sketch Toolbox/Images.xcassets/Github.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
Empty file modified Sketch Toolbox/Images.xcassets/Github.imageset/Github.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions Sketch Toolbox/Images.xcassets/Refresh.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "icon_4985.png"
"filename" : "Refresh@1x.png"
},
{
"idiom" : "universal",
"scale" : "2x"
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "[email protected]"
}
],
"info" : {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions Sketch Toolbox/Images.xcassets/Star.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
Empty file modified Sketch Toolbox/Images.xcassets/Star.imageset/Star.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Sketch Toolbox/Images.xcassets/Star.imageset/[email protected]
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Sketch Toolbox/Images.xcassets/Trash.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
5 changes: 5 additions & 0 deletions Sketch Toolbox/Images.xcassets/User.imageset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "[email protected]"
}
],
"info" : {
Expand Down
Empty file modified Sketch Toolbox/Images.xcassets/User.imageset/User.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Sketch Toolbox/Images.xcassets/User.imageset/[email protected]
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Sketch Toolbox/Plugin.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ typedef NS_ENUM(UInt16, PluginState) {
@property (nonatomic, retain) NSString * owner;
@property (nonatomic, retain) NSString * desc;
@property (nonatomic, retain) NSDate * installed;
@property () BOOL * downloading;
@property (nonatomic, retain) NSData * downloadPath;
@property (nonatomic, retain) NSDate * lastModified;
@property (nonatomic, retain) NSString * directoryName;
@property (nonatomic) UInt32 stars;
@property (nonatomic) UInt16 state;
@property (readonly) long long expectedContentLength;
@property () long long totalFileSize;

-(BOOL)isInstalled;
-(BOOL)isDownloading;

-(void)download;
-(void)delete;

-(NSString*)displayName;
-(NSURL*)repoURL;

+(long long)totalFileSize;
+(long long)downloadedFileSize;

@end
25 changes: 25 additions & 0 deletions Sketch Toolbox/Plugin.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,32 @@ @implementation Plugin
@dynamic owner;
@dynamic desc;
@dynamic installed;
@dynamic downloading;
@dynamic stars;
@dynamic downloadPath;
@dynamic lastModified;
@dynamic directoryName;
@dynamic state;
@dynamic totalFileSize;
@dynamic expectedContentLength;

#pragma mark - Main Methods
-(void)download {
if (self.isInstalled) return;
NSLog(@"Downloading %@", self.name);
self.state = PluginStateDownloading;
self.downloading = YES;

NSURL *url = [NSURL URLWithString:
[NSString stringWithFormat:
@"%@/archive/master.zip", self.repoURL]];

NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *tmpPath = [@"/tmp/" stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@-%@.zip", self.owner, self.name]];
self.totalFileSize = response.expectedContentLength;
NSLog(@"%lli",self.totalFileSize);
NSString *tmpOutputPath = @"/tmp/";
NSString *tmpContentsPath = [tmpOutputPath stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@-master", self.name]];
Expand All @@ -58,6 +65,7 @@ -(void)download {
[fm removeItemAtPath:tmpContentsPath error:nil];

NSLog(@"Finished downloading %@", self.name);
self.downloading = NO;
self.downloadPath = [NSKeyedArchiver archivedDataWithRootObject:downloadPaths];
self.installed = [NSDate date];
self.state = PluginStateInstalled;
Expand All @@ -82,12 +90,21 @@ -(void)delete {
[[NSNotificationCenter defaultCenter] postNotificationName:@"pluginStatusUpdated" object:nil];
}


#pragma mark - Properties

-(BOOL)isInstalled {
return self.state == PluginStateInstalled || self.state == PluginStateDownloading;
}

-(BOOL)isDownloading {
if (PluginStateDownloading) {
return YES;
} else {
return NO;
};
}

-(NSString*)displayName {
return [[self.name stringByReplacingOccurrencesOfString:@"-" withString:@" "] capitalizedString];
}
Expand All @@ -97,4 +114,12 @@ -(NSURL*)repoURL {
[NSString stringWithFormat:@"https://github.com/%@/%@", self.owner, self.name]];
}

+(long long)totalFileSize {
return 100 ;
}

+(long long)downloadedFileSize {
return 10;
}

@end
2 changes: 2 additions & 0 deletions Sketch Toolbox/PluginManager.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@interface PluginManager : NSObject <NSURLConnectionDelegate>

+(id)sharedManager;
+(void)importPlugins;
+(void)exportPlugins;

-(void)downloadCatalog;
-(NSArray*)localPlugins;
Expand Down
32 changes: 32 additions & 0 deletions Sketch Toolbox/PluginManager.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "Plugin.h"
#import "SSZipArchive/SSZipArchive.h"
#import "STAppDelegate.h"
#import "STPluginCellView.h"

@implementation PluginManager

Expand All @@ -32,6 +33,37 @@ -(void)downloadCatalog {
}];
}

+(void)importPlugins {
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *paths = @[kSketch3AppStorePluginPath, kSketch3PluginPath, kSketch3BetaPluginPath, kSketch2AppStorePluginPath, kSketch2PluginPath];

[paths enumerateObjectsUsingBlock:^(NSString *path, NSUInteger idx, BOOL *stop) {
if ([fm fileExistsAtPath:[path stringByExpandingTildeInPath]]) {
// NSString *outputPath = [NSString stringWithFormat:@"%@/%@", [path stringByExpandingTildeInPath], self.displayName];
// [fm copyItemAtPath:tmpContentsPath toPath:outputPath error:nil];
// NSLog(@"Copied to %@", outputPath);
// [downloadPaths addObject:outputPath];

}
}];
NSLog(@"impoetTest");
}
+(void)exportPlugins {
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *paths = @[kSketch3AppStorePluginPath, kSketch3PluginPath, kSketch3BetaPluginPath, kSketch2AppStorePluginPath, kSketch2PluginPath];

[paths enumerateObjectsUsingBlock:^(NSString *path, NSUInteger idx, BOOL *stop) {
if ([fm fileExistsAtPath:[path stringByExpandingTildeInPath]]) {
// NSString *outputPath = [NSString stringWithFormat:@"%@/%@", [path stringByExpandingTildeInPath], self.displayName];
// [fm copyItemAtPath:tmpContentsPath toPath:outputPath error:nil];
// NSLog(@"Copied to %@", outputPath);
// [downloadPaths addObject:outputPath];

}
}];
NSLog(@"exportTest");
}

-(NSArray *)localPlugins {
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *paths = @[kSketch3AppStorePluginPath, kSketch3PluginPath, kSketch3BetaPluginPath,kSketch2AppStorePluginPath, kSketch2PluginPath];
Expand Down
12 changes: 9 additions & 3 deletions Sketch Toolbox/STAppDelegate.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import <Cocoa/Cocoa.h>
#import "Constants.h"
#import "Plugin.h"

@interface STAppDelegate : NSObject <NSApplicationDelegate, NSTableViewDataSource, NSTableViewDelegate>

Expand All @@ -19,13 +21,17 @@
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;

- (IBAction)saveAction:(id)sender;
- (IBAction)importPlugin:(id)sender;
- (IBAction)exportPlugin:(id)sender;


-(IBAction)filterPlugins:(NSSearchField *)searchField;
-(IBAction)segmentSelected:(NSSegmentedControl*)sender;
-(IBAction)feedbackEmailClicked:(id)sender;
- (IBAction)filterPlugins:(NSSearchField *)searchField;
- (IBAction)segmentSelected:(NSSegmentedControl*)sender;
- (IBAction)feedbackEmailClicked:(id)sender;


- (NSString *)applicationFilesDirectory;
- (void)reloadTableData;

@property (nonatomic, strong) IBOutlet NSTableView *tableView;
@property (nonatomic, strong) IBOutlet NSButton *refreshButton;
Expand Down
41 changes: 33 additions & 8 deletions Sketch Toolbox/STAppDelegate.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PluginManager.h"
#import "Plugin.h"
#import "STPluginCellView.h"
#import "Constants.h"

@interface STAppDelegate() {
PluginManager *pluginManager;
Expand All @@ -34,7 +35,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[pluginManager downloadCatalog];
}

-(void)migrate {
- (void)migrate {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *currentAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *previousVersion = [defaults objectForKey:@"appVersion"];
Expand All @@ -50,7 +51,7 @@ -(void)migrate {
[defaults synchronize];
}

-(void)startApp {
- (void)startApp {
plugins = [Plugin MR_findAllSortedBy:@"name" ascending:YES];
activePlugins = plugins;
self.tableView.delegate = self;
Expand All @@ -59,14 +60,26 @@ -(void)startApp {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableData) name:@"pluginStatusUpdated" object:nil];
}

-(IBAction)feedbackEmailClicked:(id)sender {
- (IBAction)feedbackEmailClicked:(id)sender {
NSString *mailtoAddress = [[NSString stringWithFormat:@"mailto:[email protected]?Subject=[Sketch Toolbox] Feedback on version %@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]];
}


- (IBAction)importPlugin:(id)sender{
[PluginManager importPlugins];
}

- (IBAction)exportPlugin:(id)sender {
[PluginManager exportPlugins];
}

- (IBAction)preferenceButtonClicked:(id)sender{
}

#pragma mark - Plugins Table

-(void)reloadTableData {
- (void)reloadTableData {
if (self.searchField.stringValue.length) {
[self filterPlugins:self.searchField];
return;
Expand All @@ -77,21 +90,30 @@ -(void)reloadTableData {
} else if (self.filterControl.selectedSegment == 1) {
NSPredicate *installed = [NSPredicate predicateWithFormat:@"installed != nil"];
activePlugins = [Plugin MR_findAllSortedBy:@"name" ascending:YES withPredicate:installed];
} else if (self.filterControl.selectedSegment == 2) {
NSPredicate *downloading = [NSPredicate predicateWithFormat:@"downloading != nil"];
activePlugins = [Plugin MR_findAllSortedBy:@"name" ascending:YES withPredicate:downloading];
}
[self.tableView reloadData];
[self.tableView reloadData];
}

-(IBAction)segmentSelected:(NSSegmentedControl*)sender {
- (IBAction)segmentSelected:(NSSegmentedControl*)sender {
if (sender.selectedSegment == 0) {
activePlugins = plugins;

} else if (sender.selectedSegment == 1) {
NSPredicate *installed = [NSPredicate predicateWithFormat:@"installed != nil"];
activePlugins = [Plugin MR_findAllSortedBy:@"name" ascending:YES withPredicate:installed];
} else if (sender.selectedSegment == 2) {
NSPredicate *downloading = [NSPredicate predicateWithFormat:@"downloading != nil"];
activePlugins = [Plugin MR_findAllSortedBy:@"name" ascending:YES withPredicate:downloading];

}
[self.tableView reloadData];

}

-(IBAction)filterPlugins:(NSSearchField *)searchField {
- (IBAction)filterPlugins:(NSSearchField *)searchField {
NSMutableString *searchText = [NSMutableString stringWithString:[searchField stringValue]];
while ([searchText rangeOfString:@" "].location != NSNotFound) {
[searchText replaceOccurrencesOfString:@" " withString:@" " options:0 range:NSMakeRange(0, [searchText length])];
Expand Down Expand Up @@ -141,7 +163,7 @@ - (BOOL)selectionShouldChangeInTableView:(NSTableView *)tableView {
return NO;
}

-(IBAction)checkForUpdates:(id)sender {
- (IBAction)checkForUpdates:(id)sender {
[pluginManager downloadCatalog];
}

Expand All @@ -162,4 +184,7 @@ - (IBAction)saveAction:(id)sender {
}
}




@end
2 changes: 2 additions & 0 deletions Sketch Toolbox/STPluginCellView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@property (nonatomic, strong) IBOutlet NSTextField *owner;
@property (nonatomic, strong) IBOutlet NSTextField *starCount;
@property (nonatomic, strong) IBOutlet NSButton *actionButton;
@property (nonatomic, strong) IBOutlet NSProgressIndicator *downloadingPercentage;
@property (nonatomic, strong) IBOutlet NSTextField *percentageLabel;

-(IBAction)actionButtonPressed:(id)sender;
-(IBAction)infoButtonPressed:(id)sender;
Expand Down
Loading