Skip to content

Commit

Permalink
purged unneeded files, refactored overly verbose code, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mralexgray committed Sep 7, 2015
1 parent a55a9a9 commit 37b8a4c
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 348 deletions.
138 changes: 24 additions & 114 deletions App/BitBar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions App/BitBar/AppDelegate.h

This file was deleted.

16 changes: 14 additions & 2 deletions App/BitBar/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
// Copyright (c) 2013 Bit Bar. All rights reserved.
//

#import "AppDelegate.h"
#import "BitBarController.h"

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@property (nonatomic) BitBarController* controller;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// enable usage of Safari's WebInspector to debug HTML Plugins
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDeveloperExtras"];

self.controller = [[BitBarController alloc] init];
self.controller = BitBarController.new;
[self.controller startApp];

}

@end

int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, argv);
}
3 changes: 1 addition & 2 deletions App/BitBar/BitBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
// Copyright (c) 2013 Bit Bar. All rights reserved.
//

#import <Foundation/Foundation.h>
@class PluginManager;

@interface BitBarController : NSObject

@property (nonatomic, strong) PluginManager *pluginManager;
@property (nonatomic) PluginManager *pluginManager;

- (void) startApp;

Expand Down
4 changes: 2 additions & 2 deletions App/BitBar/BitBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ @implementation BitBarController
- (void) startApp {

if ([Settings isFirstTimeAppRun]) {
LaunchAtLoginController *launcher = [[LaunchAtLoginController alloc] init];
LaunchAtLoginController *launcher = LaunchAtLoginController.new;
if (!launcher.launchAtLogin) {
[launcher setLaunchAtLogin:YES];
}
}

// make a plugin manager
self.pluginManager = [[PluginManager alloc] initWithPluginPath:[Settings pluginsDirectory]];
self.pluginManager = [PluginManager.alloc initWithPluginPath:[Settings pluginsDirectory]];

[self.pluginManager setupAllPlugins];

Expand Down
12 changes: 6 additions & 6 deletions App/BitBar/ExecutablePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ - (BOOL) refreshContentByExecutingCommand {
return NO;
}

NSTask *task = [[NSTask alloc] init];
NSTask *task = NSTask.new;

[task setEnvironment:self.manager.environment];
[task setLaunchPath:self.path];
Expand All @@ -39,8 +39,8 @@ - (BOOL) refreshContentByExecutingCommand {

[task waitUntilExit];

self.content = [[NSString alloc] initWithData:stdoutData encoding:NSUTF8StringEncoding];
self.errorContent = [[NSString alloc] initWithData:stderrData encoding:NSUTF8StringEncoding];
self.content = [NSString.alloc initWithData:stdoutData encoding:NSUTF8StringEncoding];
self.errorContent = [NSString.alloc initWithData:stderrData encoding:NSUTF8StringEncoding];

// failure
if ([task terminationStatus] != 0) {
Expand All @@ -65,7 +65,7 @@ -(BOOL)refresh {
[self refreshContentByExecutingCommand];
dispatch_sync(dispatch_get_main_queue(), ^{

self.lastUpdated = [[NSDate alloc] init];
self.lastUpdated = NSDate.new;

[self rebuildMenuForStatusItem:self.statusItem];

Expand Down Expand Up @@ -122,14 +122,14 @@ - (void) runPluginExternally {

NSString *s = [NSString stringWithFormat:
script, self.path];
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:s];
NSAppleScript *as = [NSAppleScript.alloc initWithSource:s];
[as executeAndReturnError:nil];

}

- (void) addAdditionalMenuItems:(NSMenu *)menu {

NSMenuItem *runItem = [[NSMenuItem alloc] initWithTitle:@"Run in Terminal…" action:@selector(runPluginExternally) keyEquivalent:@"o"];
NSMenuItem *runItem = [NSMenuItem.alloc initWithTitle:@"Run in Terminal…" action:@selector(runPluginExternally) keyEquivalent:@"o"];
[runItem setTarget:self];
[menu addItem:runItem];

Expand Down
10 changes: 5 additions & 5 deletions App/BitBar/HTMLPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ -(void)reloadWebView {
}

-(void)rebuildMenuForStatusItem:(NSStatusItem *)statusItem {
WebView * webview = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 15, 15)];
WebView * webview = [WebView.alloc initWithFrame:NSMakeRect(0, 0, 15, 15)];

self.webView = webview;

Expand All @@ -64,7 +64,7 @@ -(void)rebuildMenuForStatusItem:(NSStatusItem *)statusItem {
webview.autoresizingMask = NSViewWidthSizable;

NSURL * url = [NSURL fileURLWithPath:self.path];
NSURLRequest * req = [[NSURLRequest alloc] initWithURL:url];
NSURLRequest * req = [NSURLRequest.alloc initWithURL:url];
[webview.mainFrame loadRequest:req];
statusItem.view = webview;

Expand Down Expand Up @@ -172,7 +172,7 @@ - (NSArray *) arrayOfKeysFromWebScriptObject:(WebScriptObject *)obj {

- (NSDictionary *) dictionaryFromWebScriptObject:(WebScriptObject *)obj {
NSArray * keys = [self arrayOfKeysFromWebScriptObject:obj];
NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:keys.count];
NSMutableDictionary * dict = [NSMutableDictionary.alloc initWithCapacity:keys.count];
for (NSString * key in keys) {
NSObject * value = [obj valueForKey:key];
if ([[value class] isSubclassOfClass:[NSString class]] || [[value class] isSubclassOfClass:[NSNumber class]]) {
Expand All @@ -189,7 +189,7 @@ - (BOOL) isWebScriptObjectInstanceOfArray:(WebScriptObject *)obj {
}

- (NSArray *) arrayFromWebScriptObject:(WebScriptObject *)obj {
NSMutableArray * values = [[NSMutableArray alloc] init];
NSMutableArray * values = NSMutableArray.new;
id elem = nil;
int i = 0;
WebUndefined *undefined = [WebUndefined undefined];
Expand Down Expand Up @@ -226,7 +226,7 @@ - (void) resizeToFit {

- (void) resetMenu {
NSLog(@"resetMenu");
_menu = [[NSMenu alloc] init];
_menu = NSMenu.new;
}

- (void) addMenuItem:(NSObject*)titleOrParamsDict {
Expand Down
36 changes: 13 additions & 23 deletions App/BitBar/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,26 @@
// Copyright (c) 2013 Bit Bar. All rights reserved.
//

#import <Foundation/Foundation.h>
@class PluginManager;

@interface Plugin : NSObject <NSMenuDelegate>

@property (nonatomic, copy) NSString *path;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *content;
@property (nonatomic, copy) NSString *allContent;
@property (nonatomic, assign) NSInteger currentLine;
@property (nonatomic, strong) NSArray *allContentLines;
@property (nonatomic, strong) NSArray *allContentLinesAfterBreak;
@property (nonatomic, copy) NSString *errorContent;
@property (nonatomic, assign) BOOL lastCommandWasError;
@property (nonatomic, strong) NSNumber *refreshIntervalSeconds;
@property (readonly, nonatomic, strong) PluginManager* manager;
@property (nonatomic, assign) NSInteger cycleLinesIntervalSeconds;
@property (nonatomic, assign) BOOL pluginIsVisible;
@property (nonatomic, strong) NSMenuItem *lastUpdatedMenuItem;
@property (nonatomic, strong) NSDate *lastUpdated;

@property (nonatomic, assign) BOOL menuIsOpen;
@property (nonatomic) NSInteger currentLine, cycleLinesIntervalSeconds;
@property (nonatomic) BOOL lastCommandWasError, pluginIsVisible, menuIsOpen;
@property (readonly) BOOL isMultiline;
@property (readonly) NSString *lastUpdatedString;
@property (nonatomic, copy) NSString *path, *name, *content, *allContent, *errorContent;
@property (nonatomic) NSArray *allContentLines, *allContentLinesAfterBreak;
@property (nonatomic) NSNumber *refreshIntervalSeconds;
@property (nonatomic) NSMenuItem *lastUpdatedMenuItem;
@property (nonatomic) NSDate *lastUpdated;
@property (readonly) PluginManager *manager;

// UI
@property (nonatomic, strong) NSStatusItem *statusItem;
@property (nonatomic) NSStatusItem *statusItem;

- initWithManager:(PluginManager*)manager;

- (id) initWithManager:(PluginManager*)manager;
- (BOOL) isMultiline;

- (NSMenuItem *) buildMenuItemWithParams:(NSDictionary *)params;
- (void) rebuildMenuForStatusItem:(NSStatusItem*)statusItem;
Expand All @@ -44,8 +36,6 @@
- (void) cycleLines;
- (void) contentHasChanged;

- (NSString *)lastUpdatedString;

// actions
- (void)changePluginsDirectorySelected:(id)sender;

Expand Down
18 changes: 9 additions & 9 deletions App/BitBar/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (NSMenuItem *) buildMenuItemWithParams:(NSDictionary *)params {
if ([params objectForKey:@"bash"] != nil) {
sel = @selector(performMenuItemOpenTerminalAction:);
}
NSMenuItem * item = [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""];
NSMenuItem * item = [NSMenuItem.alloc initWithTitle:title action:sel keyEquivalent:@""];
if (sel != nil) {
item.representedObject = params;
[item setTarget:self];
Expand All @@ -71,7 +71,7 @@ - (NSMenuItem *) buildMenuItemWithParams:(NSDictionary *)params {
- (NSAttributedString *) attributedTitleWithParams:(NSDictionary *)params {
NSString * title = [params objectForKey:@"title"];
NSFont * font = [NSFont menuFontOfSize:14.0];
NSMutableAttributedString * attributedTitle = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: font}];
NSMutableAttributedString * attributedTitle = [NSMutableAttributedString.alloc initWithString:title attributes:@{NSFontAttributeName: font}];
if ([params objectForKey:@"color"] != nil) {
NSColor * fgColor = [NSColor colorWithWebColorString:[params objectForKey:@"color"]];
if (fgColor != nil) {
Expand All @@ -93,7 +93,7 @@ - (NSDictionary *) dictionaryForLine:(NSString *)line {
}
NSString * title = [[line substringToIndex:found.location]
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
NSMutableDictionary * params = NSMutableDictionary.new;
[params setObject:title forKey:@"title"];
NSString * paramsStr = [line substringFromIndex:found.location + found.length];
NSArray * paramsArr = [[paramsStr
Expand Down Expand Up @@ -134,7 +134,7 @@ - (void) performMenuItemOpenTerminalAction:(NSMenuItem *)menuItem {
//NSLog(@"%@", terminal);

if([terminal isEqual: @"false"]){
NSTask *task = [[NSTask alloc] init];
NSTask *task = NSTask.new;
[task setLaunchPath:bash];
[task setArguments:@[ param1, param2, param3 ]];
[task launch];
Expand All @@ -147,15 +147,15 @@ - (void) performMenuItemOpenTerminalAction:(NSMenuItem *)menuItem {
end if \n\
do script \"%@\" in front window activate \n\
end tell", full_link];
NSAppleScript *as = [[NSAppleScript alloc] initWithSource: s];
NSAppleScript *as = [NSAppleScript.alloc initWithSource: s];
[as executeAndReturnError:nil];
}
}

- (void) rebuildMenuForStatusItem:(NSStatusItem*)statusItem {

// build the menu
NSMenu *menu = [[NSMenu alloc] init];
NSMenu *menu = NSMenu.new;
[menu setDelegate:self];

if (self.isMultiline) {
Expand Down Expand Up @@ -195,7 +195,7 @@ - (void) rebuildMenuForStatusItem:(NSStatusItem*)statusItem {

if (self.lastUpdated != nil) {

self.lastUpdatedMenuItem = [[NSMenuItem alloc] initWithTitle:@"Updated just now" action:nil keyEquivalent:@""];
self.lastUpdatedMenuItem = [NSMenuItem.alloc initWithTitle:@"Updated just now" action:nil keyEquivalent:@""];
[menu addItem:self.lastUpdatedMenuItem];

[menu addItem:[NSMenuItem separatorItem]];
Expand Down Expand Up @@ -340,7 +340,7 @@ - (NSArray *)allContentLines {

NSArray *lines = [self.allContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

NSMutableArray *cleanLines = [[NSMutableArray alloc] initWithCapacity:lines.count];
NSMutableArray *cleanLines = [NSMutableArray.alloc initWithCapacity:lines.count];
NSString *line;
for (line in lines) {

Expand Down Expand Up @@ -382,7 +382,7 @@ - (NSArray *)allContentLinesAfterBreak {
if (_allContentLinesAfterBreak == nil) {

NSArray *lines = [self.allContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSMutableArray *cleanLines = [[NSMutableArray alloc] initWithCapacity:lines.count];
NSMutableArray *cleanLines = [NSMutableArray.alloc initWithCapacity:lines.count];
NSString *line;
BOOL storing = NO;

Expand Down
15 changes: 6 additions & 9 deletions App/BitBar/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@
// Copyright (c) 2013 Bit Bar. All rights reserved.
//

#import <Foundation/Foundation.h>
@class Plugin;

@interface PluginManager : NSObject <NSMenuDelegate>

@property (nonatomic, copy) NSString *path;
@property (nonatomic, strong) NSArray *plugins;
@property (nonatomic, strong) NSStatusBar *statusBar;
@property (nonatomic, strong) NSStatusItem *defaultStatusItem;
@property (nonatomic, strong) NSTimer *timerForLastUpdated;
@property (nonatomic, strong) NSDictionary *environment;
@property (nonatomic) NSArray *plugins;
@property (nonatomic) NSStatusBar *statusBar;
@property (nonatomic) NSStatusItem *defaultStatusItem;
@property (nonatomic) NSTimer *timerForLastUpdated;
@property (nonatomic) NSDictionary *environment;

- (id) initWithPluginPath:(NSString *)path;
- initWithPluginPath:(NSString *)path;

- (NSArray *) pluginFilesWithAsking:(BOOL)shouldAsk;

- (NSArray *)plugins;

- (void) setupAllPlugins;
- (void) reset;
- (void) clearPathAndReset;
Expand Down
Loading

0 comments on commit 37b8a4c

Please sign in to comment.