Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumealgis committed Jan 7, 2016
1 parent ed99765 commit 7c5c742
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 72 deletions.
6 changes: 6 additions & 0 deletions Alcatraz.xcodeproj/project.pbxproj
Expand Up @@ -58,6 +58,7 @@
8ADC22341A2AD5B800DB7BCA /* ATZPreviewImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ADC22331A2AD5B800DB7BCA /* ATZPreviewImageButton.m */; };
8AF670C919C2DE8A00E1C168 /* ATZSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8AF670C819C2DE8A00E1C168 /* ATZSegmentedControl.m */; };
F0DF961E1B40416400DF68CC /* ATZSegmentedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */; };
F07E55521B551BA800161E61 /* ATZXcodePrefsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F07E55511B551BA800161E61 /* ATZXcodePrefsManager.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -145,6 +146,8 @@
8AF670C819C2DE8A00E1C168 /* ATZSegmentedControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ATZSegmentedControl.m; path = Views/ATZSegmentedControl.m; sourceTree = "<group>"; };
F0DF961C1B40416300DF68CC /* ATZSegmentedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATZSegmentedCell.h; sourceTree = "<group>"; };
F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATZSegmentedCell.m; sourceTree = "<group>"; };
F07E55501B551BA800161E61 /* ATZXcodePrefsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATZXcodePrefsManager.h; sourceTree = "<group>"; };
F07E55511B551BA800161E61 /* ATZXcodePrefsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATZXcodePrefsManager.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -300,6 +303,8 @@
8917DA171726B63B00F0B2D2 /* ATZShell.m */,
89B4F2BC172FF5AC001FD2E3 /* ATZPBXProjParser.h */,
89B4F2BD172FF5AC001FD2E3 /* ATZPBXProjParser.m */,
F07E55501B551BA800161E61 /* ATZXcodePrefsManager.h */,
F07E55511B551BA800161E61 /* ATZXcodePrefsManager.m */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -464,6 +469,7 @@
8A1732A81A2694BB002033D6 /* NSColor+Alcatraz.m in Sources */,
894714E817302F63003CDDA7 /* ATZInstaller.m in Sources */,
897F7899173FC54C006C43E5 /* ATZAlcatrazPackage.m in Sources */,
F07E55521B551BA800161E61 /* ATZXcodePrefsManager.m in Sources */,
8A4C621A19C2D6F1003580BD /* ATZFilterBarView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
6 changes: 2 additions & 4 deletions Alcatraz/Controllers/ATZPluginWindowController.m
Expand Up @@ -91,7 +91,7 @@ - (IBAction)installPressed:(ATZFillableButton *)button {
ATZPackage *package = [self.tableViewDelegate tableView:self.tableView objectValueForTableColumn:0 row:[self.tableView rowForView:button]];

if (package.isInstalled) {
if ([package isKindOfClass:[ATZPlugin class]] && [(ATZPlugin *)package isBlacklisted]) {
if (package.isBlacklisted) {
[self whitelistPackage:(ATZPlugin *)package andUpdateControl:button];
}
else {
Expand Down Expand Up @@ -224,9 +224,7 @@ - (void)whitelistPackage:(ATZPlugin *)package andUpdateControl:(ATZFillableButto
}

- (void)postNotificationForInstalledPackage:(ATZPackage *)package {
if (![NSUserNotificationCenter class] || !package.isInstalled) {
return;
}
if (![NSUserNotificationCenter class] || !package.isInstalled) return;

NSUserNotification *notification = [NSUserNotification new];
notification.title = [NSString stringWithFormat:@"%@ installed", package.type];
Expand Down
10 changes: 7 additions & 3 deletions Alcatraz/Helpers/ATZStyleKit.m
Expand Up @@ -25,25 +25,29 @@
#import "ATZPlugin.h"
#import "ATZFillableButton.h"

static NSString *const BUTTON_TITLE_INSTALL = @"INSTALL";
static NSString *const BUTTON_TITLE_REMOVE = @"REMOVE";
static NSString *const BUTTON_TITLE_BLOCKED = @"BLOCKED";

@implementation ATZStyleKit

#pragma mark ATZFillableButton styling

+ (void)updateButton:(ATZFillableButton *)fillableButton forPackageState:(ATZPackage *)package animated:(BOOL)animated {
if ([package isInstalled]) {
if ([package isBlacklisted]) {
[fillableButton setTitle:@"BLOCKED"];
[fillableButton setTitle:BUTTON_TITLE_BLOCKED];
[fillableButton setButtonStyle:ATZFillableButtonStyleBlocked];
[fillableButton setFillRatio:0 animated:animated];
}
else {
[fillableButton setTitle:@"REMOVE"];
[fillableButton setTitle:BUTTON_TITLE_REMOVE];
[fillableButton setButtonStyle:ATZFillableButtonStyleRemove];
[fillableButton setFillRatio:1 animated:animated];
}
}
else {
[fillableButton setTitle:@"INSTALL"];
[fillableButton setTitle:BUTTON_TITLE_INSTALL];
[fillableButton setButtonStyle:ATZFillableButtonStyleInstall];
[fillableButton setFillRatio:0 animated:animated];
}
Expand Down
20 changes: 20 additions & 0 deletions Alcatraz/Helpers/ATZXcodePrefsManager.h
@@ -0,0 +1,20 @@
//
// ATZXcodePrefsManager.h
// Alcatraz
//
// Created by Guillaume Algis on 14/07/2015.
// Copyright (c) 2015 supermar.in. All rights reserved.
//

#import <Foundation/Foundation.h>

@class ATZPackage;

@interface ATZXcodePrefsManager : NSObject

+ (instancetype)sharedManager;

- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion;
- (BOOL)isPackageBlacklisted:(ATZPackage *)package;

@end
81 changes: 81 additions & 0 deletions Alcatraz/Helpers/ATZXcodePrefsManager.m
@@ -0,0 +1,81 @@
//
// ATZXcodePrefsManager.m
// Alcatraz
//
// Created by Guillaume Algis on 14/07/2015.
// Copyright (c) 2015 supermar.in. All rights reserved.
//

#import "ATZXcodePrefsManager.h"
#import "ATZPackage.h"
#import "ATZInstaller.h"

static NSString *const NON_APPLE_PLUGINS_KEY_FORMAT = @"DVTPlugInManagerNonApplePlugIns-Xcode-%@";
static NSString *const NON_APPLE_PLUGINS_WHITELISTED_KEY = @"allowed";
static NSString *const NON_APPLE_PLUGINS_BLACKLISTED_KEY = @"skipped";

@implementation ATZXcodePrefsManager

#pragma mark - Singleton

+ (instancetype)sharedManager {
static ATZXcodePrefsManager *instance = nil;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}

#pragma mark - Public

- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion {
NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey];
NSMutableDictionary *nonApplePlugins = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey] mutableCopy];
NSMutableDictionary *whitelistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] mutableCopy];
NSMutableDictionary *blacklistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] mutableCopy];

NSBundle *pluginBundle = [NSBundle bundleWithPath:[package.installer pathForInstalledPackage:package]];
NSString *pluginIdentifier = [pluginBundle bundleIdentifier];

NSDictionary *pluginEntry = blacklistedPlugins[pluginIdentifier];
[blacklistedPlugins removeObjectForKey:pluginIdentifier];
whitelistedPlugins[pluginIdentifier] = pluginEntry;

nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] = [whitelistedPlugins copy];
nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] = [blacklistedPlugins copy];

[[NSUserDefaults standardUserDefaults] setObject:[nonApplePlugins copy] forKey:pluginManagerKey];
BOOL synchronizedSuccessfully = [[NSUserDefaults standardUserDefaults] synchronize];

NSError *error;
if (!synchronizedSuccessfully) {
error = [NSError errorWithDomain:@"Could not update Xcode's preferences and whitelist plugin" code:666 userInfo:nil];
}

completion(error);
}

- (BOOL)isPackageBlacklisted:(ATZPackage *)package {
if (![package isInstalled]) {
return NO;
}

NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey];
NSDictionary *nonApplePlugins = [[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey];
NSArray *skippedPluginsIdentifiers = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] allKeys];

NSBundle *pluginBundle = [NSBundle bundleWithPath:[package.installer pathForInstalledPackage:package]];

return [skippedPluginsIdentifiers containsObject:[pluginBundle bundleIdentifier]];
}

#pragma mark - Private

- (NSString *)xcodeDefaultsNonApplePluginsKey {
NSString *xcodeVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
return [NSString stringWithFormat:NON_APPLE_PLUGINS_KEY_FORMAT, xcodeVersion];
}

@end
2 changes: 0 additions & 2 deletions Alcatraz/Installers/ATZInstaller.h
Expand Up @@ -40,9 +40,7 @@ static NSString *const UPDATING_FORMAT = @"Updating %@...";
- (void)updatePackage:(ATZPackage *)package progress:(void(^)(NSString *progressMessage, CGFloat progress))progress
completion:(void(^)(NSError *error))completion;
- (void)removePackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion;
- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion;

- (BOOL)isPackageBlacklisted:(ATZPackage *)package;
- (BOOL)isPackageInstalled:(ATZPackage *)package;
- (NSString *)pathForDownloadedPackage:(ATZPackage *)package;

Expand Down
10 changes: 0 additions & 10 deletions Alcatraz/Installers/ATZInstaller.m
Expand Up @@ -81,10 +81,6 @@ - (void)removePackage:(ATZPackage *)package completion:(void (^)(NSError *))comp
[[NSFileManager sharedManager] removeItemAtPath:[self pathForInstalledPackage:package] completion:completion];
}

- (BOOL)isPackageBlacklisted:(ATZPackage *)package {
return NO;
}

- (BOOL)isPackageInstalled:(ATZPackage *)package {
return [[NSFileManager sharedManager] fileExistsAtPath:[self pathForInstalledPackage:package]];
}
Expand Down Expand Up @@ -117,12 +113,6 @@ - (void)installPackage:(ATZPackage *)package completion:(void(^)(NSError *))comp
reason:@"Abstract Installer doesn't know how to install" userInfo:nil];
}

- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion {
@throw [NSException exceptionWithName:@"Abstract Installer"
reason:@"Abstract Installer doesn't know how to whitelist" userInfo:nil];
}


- (NSString *)pathForInstalledPackage:(ATZPackage *)package {
@throw [NSException exceptionWithName:@"Abstract Installer"
reason:@"Install path is different for every package type" userInfo:nil];
Expand Down
48 changes: 0 additions & 48 deletions Alcatraz/Installers/ATZPluginInstaller.m
Expand Up @@ -38,10 +38,6 @@
static NSString *const XCODEPROJ = @".xcodeproj";
static NSString *const PROJECT_PBXPROJ = @"project.pbxproj";

static NSString *const NON_APPLE_PLUGINS_KEY_FORMAT = @"DVTPlugInManagerNonApplePlugIns-Xcode-%@";
static NSString *const NON_APPLE_PLUGINS_WHITELISTED_KEY = @"allowed";
static NSString *const NON_APPLE_PLUGINS_BLACKLISTED_KEY = @"skipped";

@implementation ATZPluginInstaller

#pragma mark - Abstract
Expand Down Expand Up @@ -88,45 +84,6 @@ - (NSString *)pathForPluginsWithExtension:(NSString *)extension
return path;
}

- (BOOL)isPackageBlacklisted:(ATZPackage *)package {
if (![self isPackageInstalled:package]) {
return NO;
}

NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey];
NSDictionary *nonApplePlugins = [[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey];
NSArray *skippedPluginsIdentifiers = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] allKeys];

NSBundle *pluginBundle = [NSBundle bundleWithPath:[self pathForInstalledPackage:package]];
}

- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion {
NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey];
NSMutableDictionary *nonApplePlugins = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey] mutableCopy];
NSMutableDictionary *whitelistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] mutableCopy];
NSMutableDictionary *blacklistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] mutableCopy];

NSBundle *pluginBundle = [NSBundle bundleWithPath:[self pathForInstalledPackage:package]];
NSString *pluginIdentifier = [pluginBundle bundleIdentifier];

NSDictionary *pluginEntry = blacklistedPlugins[pluginIdentifier];
[blacklistedPlugins removeObjectForKey:pluginIdentifier];
whitelistedPlugins[pluginIdentifier] = pluginEntry;

nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] = [whitelistedPlugins copy];
nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] = [blacklistedPlugins copy];

[[NSUserDefaults standardUserDefaults] setObject:[nonApplePlugins copy] forKey:pluginManagerKey];
BOOL synchronizedSuccessfully = [[NSUserDefaults standardUserDefaults] synchronize];

NSError *error;
if (!synchronizedSuccessfully) {
error = [NSError errorWithDomain:@"Could not update Xcode's preferences and whitelist plugin" code:666 userInfo:nil];
}

completion(error);
}

#pragma mark - Hooks
// Note: this is an early alpha implementation. It needs some love
- (void)reloadXcodeForPackage:(ATZPackage *)plugin completion:(void(^)(NSError *))completion {
Expand Down Expand Up @@ -209,9 +166,4 @@ - (void)reloadPluginBundleWithoutWarnings:(NSBundle *)pluginBundle forPlugin:(AT
}
}

- (NSString *)xcodeDefaultsNonApplePluginsKey {
NSString *xcodeVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
return [NSString stringWithFormat:NON_APPLE_PLUGINS_KEY_FORMAT, xcodeVersion];
}

@end
5 changes: 3 additions & 2 deletions Alcatraz/Packages/ATZPackage.m
Expand Up @@ -22,6 +22,7 @@

#import "ATZPackage.h"
#import "ATZInstaller.h"
#import "ATZXcodePrefsManager.h"
#import "ATZGit.h"

@implementation ATZPackage
Expand Down Expand Up @@ -76,7 +77,7 @@ - (NSString *)website {
#pragma mark - Abstract

- (BOOL)isBlacklisted {
return [[self installer] isPackageBlacklisted:self];
return [[ATZXcodePrefsManager sharedManager] isPackageBlacklisted:self];
}

- (BOOL)isInstalled {
Expand All @@ -100,7 +101,7 @@ - (void)removeWithCompletion:(void (^)(NSError *))completion {
}

- (void)whitelistWithCompletion:(void(^)(NSError *failure))completion {
[self.installer whitelistPackage:self completion:completion];
[[ATZXcodePrefsManager sharedManager] whitelistPackage:self completion:completion];
}

- (ATZInstaller *)installer {
Expand Down
4 changes: 1 addition & 3 deletions Alcatraz/Views/ATZFillableButton.m
Expand Up @@ -72,17 +72,15 @@ - (void)updateButtonColorsMatchingStyle:(ATZFillableButtonStyle)buttonStyle {
switch (buttonStyle) {
case ATZFillableButtonStyleInstall:
self.fillColor = installGreen;
self.backgroundColor = [NSColor whiteColor];
break;
case ATZFillableButtonStyleRemove:
self.fillColor = removeRed;
self.backgroundColor = [NSColor whiteColor];
break;
case ATZFillableButtonStyleBlocked:
self.fillColor = blockedOrange;
self.backgroundColor = [NSColor whiteColor];
break;
}
self.backgroundColor = [NSColor whiteColor];
}

@end

0 comments on commit 7c5c742

Please sign in to comment.