Skip to content

Commit

Permalink
fix some potential bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 11, 2014
1 parent 8cb398d commit 6c32910
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion FlashlightApp/EasySIMBL/PluginInstallTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (id)initWithPlugin:(PluginModel *)plugin {
}
- (void)startInstallationIntoPluginsDirectory:(NSString *)directory withCallback:(void(^)(BOOL success, NSError *error))callback {
[[[NSURLSession sharedSession] dataTaskWithURL:self.plugin.zipURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
if (data && !error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSError *zipError = nil;
ZZArchive *archive = [ZZArchive archiveWithData:data error:&zipError];
Expand Down
29 changes: 12 additions & 17 deletions FlashlightApp/EasySIMBL/PluginListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ - (IBAction)reloadPluginsFromWeb:(id)sender {

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://raw.githubusercontent.com/nate-parrott/flashlight/master/PluginDirectories/1/index.json"]];
[[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSMutableArray *plugins = [NSMutableArray new];
for (NSDictionary *dict in d[@"plugins"]) {
[plugins addObject:[PluginModel fromJson:dict baseURL:url]];
if (data) {
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
for (NSDictionary *dict in d[@"plugins"]) {
[plugins addObject:[PluginModel fromJson:dict baseURL:url]];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self setPluginsFromWeb:plugins];
Expand Down Expand Up @@ -205,10 +207,13 @@ - (void)reloadFromDisk {
NSMutableArray *models = [NSMutableArray new];
for (NSString *itemName in contents) {
if ([[itemName pathExtension] isEqualToString:@"bundle"]) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[[self localPluginsPath] stringByAppendingPathComponent:itemName] stringByAppendingPathComponent:@"info.json"]] options:0 error:nil];
PluginModel *model = [PluginModel fromJson:json baseURL:nil];
model.installed = YES;
[models addObject:model];
NSData *data = [NSData dataWithContentsOfFile:[[[self localPluginsPath] stringByAppendingPathComponent:itemName] stringByAppendingPathComponent:@"info.json"]];
if (data) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
PluginModel *model = [PluginModel fromJson:json baseURL:nil];
model.installed = YES;
[models addObject:model];
}
}
}
self.installedPlugins = models;
Expand All @@ -234,16 +239,6 @@ - (void)installPlugin:(PluginModel *)plugin {
self.installTasksInProgress = self.installTasksInProgress ? [self.installTasksInProgress setByAddingObject:task] : [NSSet setWithObject:task];
[task startInstallationIntoPluginsDirectory:[self localPluginsPath] withCallback:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
/*if (!success) {
NSAlert *alert = [NSAlert new];
NSMutableString *errorMsg = [NSMutableString stringWithFormat:@"Couldn't install \"%@\".", plugin.displayName];
if (error) {
[errorMsg appendFormat:@"\n(%@)", error.localizedFailureReason];
}
alert.messageText = errorMsg;
[alert addButtonWithTitle:@"Okay"];
[alert runModal];
}*/
if (!success) {
NSAlert *alert = error ? [NSAlert alertWithError:error] : [NSAlert alertWithMessageText:@"Couldn't install plugin." defaultButton:@"Okay" alternateButton:nil otherButton:nil informativeTextWithFormat:nil];
alert.alertStyle = NSWarningAlertStyle;
Expand Down
16 changes: 10 additions & 6 deletions FlashlightApp/EasySIMBL/Updater.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ - (void)checkForUpdates:(void(^)())callback {
NSURL *updateURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/nate-parrott/flashlight/master/UpdateInfo.json"];
double currentBuild = [[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"] doubleValue];
[[[NSURLSession sharedSession] dataTaskWithURL:updateURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
self.updateJson = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([self.updateJson[@"build"] doubleValue] > currentBuild) {
self.updatedVersionName = self.updateJson[@"name"];
self.updateURL = self.updateJson[@"updateURL"];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
self.updatedVersionName = nil;
self.updateURL = nil;
}
if (data) {
self.updateJson = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([self.updateJson[@"build"] doubleValue] > currentBuild) {
self.updatedVersionName = self.updateJson[@"name"];
self.updateURL = self.updateJson[@"updateURL"];
}
}
callback();
});
}] resume];
}

Expand Down

0 comments on commit 6c32910

Please sign in to comment.