Skip to content

Commit

Permalink
Merge branch 'v0.4' of github.com:blockstack/blockstack-portal into u…
Browse files Browse the repository at this point in the history
…i-0.4

merge of v0.4
  • Loading branch information
guylepage3 committed Feb 27, 2017
2 parents 3f5d4ed + 8e3fa74 commit fb761c8
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 172 deletions.
12 changes: 0 additions & 12 deletions native/macos/Blockstack/Blockstack.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
DD4F7C1513C30F9F00825C6E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F7C1413C30F9F00825C6E /* main.m */; };
DD4F7C1C13C30F9F00825C6E /* ApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F7C1B13C30F9F00825C6E /* ApplicationDelegate.m */; };
DD4F7C1F13C30F9F00825C6E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD4F7C1D13C30F9F00825C6E /* MainMenu.xib */; };
DD4F7C3813C317A500825C6E /* MenubarController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F7C3713C317A500825C6E /* MenubarController.m */; };
DD4F7C3C13C3180800825C6E /* StatusItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F7C3B13C3180800825C6E /* StatusItemView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -39,10 +37,6 @@
DD4F7C1A13C30F9F00825C6E /* ApplicationDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplicationDelegate.h; sourceTree = "<group>"; };
DD4F7C1B13C30F9F00825C6E /* ApplicationDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ApplicationDelegate.m; sourceTree = "<group>"; };
DD4F7C1E13C30F9F00825C6E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
DD4F7C3613C317A500825C6E /* MenubarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenubarController.h; sourceTree = "<group>"; };
DD4F7C3713C317A500825C6E /* MenubarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenubarController.m; sourceTree = "<group>"; };
DD4F7C3A13C3180800825C6E /* StatusItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatusItemView.h; sourceTree = "<group>"; };
DD4F7C3B13C3180800825C6E /* StatusItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatusItemView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -118,8 +112,6 @@
children = (
DD4F7C1A13C30F9F00825C6E /* ApplicationDelegate.h */,
DD4F7C1B13C30F9F00825C6E /* ApplicationDelegate.m */,
DD4F7C3613C317A500825C6E /* MenubarController.h */,
DD4F7C3713C317A500825C6E /* MenubarController.m */,
);
name = Controllers;
sourceTree = "<group>";
Expand All @@ -144,8 +136,6 @@
DD4F7C3913C317EC00825C6E /* Views */ = {
isa = PBXGroup;
children = (
DD4F7C3A13C3180800825C6E /* StatusItemView.h */,
DD4F7C3B13C3180800825C6E /* StatusItemView.m */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -236,8 +226,6 @@
files = (
DD4F7C1513C30F9F00825C6E /* main.m in Sources */,
DD4F7C1C13C30F9F00825C6E /* ApplicationDelegate.m in Sources */,
DD4F7C3813C317A500825C6E /* MenubarController.m in Sources */,
DD4F7C3C13C3180800825C6E /* StatusItemView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 6 additions & 3 deletions native/macos/Blockstack/Blockstack/ApplicationDelegate.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#define LAUNCH_BROWSER_DELAY 1.0

#import "MenubarController.h"

@interface ApplicationDelegate : NSObject <NSApplicationDelegate>

@property (nonatomic, strong) MenubarController *menubarController;
@property (nonatomic, strong) NSTask *blockstackProxyTask;
@property (nonatomic, strong) NSTask *corsProxyTask;

@property (strong) NSString *blockstackCoreConfigFilePath;

@property (strong) NSString *blockstackPath;

@property (strong) NSStatusItem *statusItem;

- (IBAction)handleClick:(id)sender;
@property BOOL devModeEnabled;

@property (readonly) int prodModePortalPort;
@property (readonly) int devModePortalPort;
@property (readonly) int corsProxyPort;

@end
144 changes: 133 additions & 11 deletions native/macos/Blockstack/Blockstack/ApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,57 @@

@implementation ApplicationDelegate

@synthesize menubarController = _menubarController;
@synthesize blockstackProxyTask;
@synthesize corsProxyTask;
@synthesize blockstackCoreConfigFilePath;
@synthesize blockstackPath;
@synthesize statusItem;
@synthesize devModeEnabled;

@synthesize prodModePortalPort = _prodModePortalPort;
@synthesize devModePortalPort = _devModePortalPort;
@synthesize corsProxyPort = _corsProxyPort;



- (void)dealloc
{
}

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
NSLog(@"Blockstack URL: %@", url);
NSLog(@"Blockstack URL host: %@", [url host]);

NSString* portalPath = [NSString stringWithFormat:@"%@%@", [self portalAuthPath], [url host]];
[self launchBrowser:portalPath];
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
_prodModePortalPort = 8888;
_devModePortalPort = 3000;
_corsProxyPort = 1337;

self.devModeEnabled = NO;

// Add our icon to menu bar
self.menubarController = [[MenubarController alloc] init];
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
self.statusItem.highlightMode = YES;
self.statusItem.button.image = [NSImage imageNamed:@"MenuBar"];
self.statusItem.button.alternateImage = [NSImage imageNamed:@"MenuBarDark"];
self.statusItem.button.target = self;
self.statusItem.action = @selector(statusItemClick:);


NSString* coreWalletPassword = [self createOrRetrieveCoreWalletPassword];

Expand All @@ -35,17 +67,82 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
// Explicitly remove the icon from the menu bar
self.menubarController = nil;
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
[self.blockstackProxyTask terminate];
[self.corsProxyTask terminate];
[self stopBlockstackCoreApiAndExit];
return NSTerminateNow;
}

- (void)statusItemClick:(id)sender
{
NSMenu *menu = [[NSMenu alloc] init];


NSLog(@"statusItemClick");

if ((([[NSApp currentEvent] modifierFlags] & NSEventModifierFlagOption) != 0)
|| self.devModeEnabled == YES)
{
NSLog(@"Option click");

if(self.devModeEnabled == YES)
[menu addItemWithTitle:@"Go to Development Portal" action:@selector(openPortalClick:) keyEquivalent:@"g"];
else
[menu addItemWithTitle:@"Go to Portal" action:@selector(openPortalClick:) keyEquivalent:@"g"];

[menu addItem:[NSMenuItem separatorItem]];

NSMenuItem *portalPortMenuItem = [[NSMenuItem alloc] init];
portalPortMenuItem.title = [NSString stringWithFormat:@"Portal proxy running on port %d", [self portalPort]];
portalPortMenuItem.enabled = NO;

NSMenuItem *corsProxyPortMenuItem = [[NSMenuItem alloc] init];
corsProxyPortMenuItem.title = [NSString stringWithFormat:@"CORS proxy running on port %d", [self corsProxyPort]];
corsProxyPortMenuItem.enabled = NO;

NSMenuItem *corePortMenuItem = [[NSMenuItem alloc] init];
corePortMenuItem.title = @"Core node running on port 6270";
corePortMenuItem.enabled = NO;

[menu addItem:portalPortMenuItem];
[menu addItem:corsProxyPortMenuItem];
[menu addItem:corePortMenuItem];
[menu addItem:[NSMenuItem separatorItem]];

NSMenuItem *devModeStatusMenuItem = [[NSMenuItem alloc] init];
devModeStatusMenuItem.title = [NSString stringWithFormat:@"Portal Development Mode: %@", self.devModeEnabled ? @"Enabled" : @"Disabled"];
devModeStatusMenuItem.enabled = NO;

[menu addItem:devModeStatusMenuItem];

[menu addItemWithTitle:[NSString stringWithFormat:@"%@ Portal Development Mode", self.devModeEnabled ? @"Disable" : @"Enable"] action:@selector(devModeClick:) keyEquivalent:@"d"];

[menu addItem:[NSMenuItem separatorItem]];
} else {
[menu addItemWithTitle:@"Go to Portal" action:@selector(openPortalClick:) keyEquivalent:@"g"];
[menu addItem:[NSMenuItem separatorItem]];
}

[menu addItemWithTitle:@"Turn Off Blockstack" action:@selector(exitClick:) keyEquivalent:@"q"];
[self.statusItem popUpStatusItemMenu:menu];
}

- (void)devModeClick:(id)sender
{
NSLog(@"devModeClick");
self.devModeEnabled = !self.devModeEnabled;
}

- (void)openPortalClick:(id)sender
{
NSLog(@"openPortalClick");
[self launchBrowser];
}

- (IBAction)handleClick:(id)sender
- (void)exitClick:(id)sender
{
NSLog(@"handleClick");
NSLog(@"exitClick");

NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Turn off"];
Expand All @@ -57,11 +154,14 @@ - (IBAction)handleClick:(id)sender
if ([alert runModal] == NSAlertFirstButtonReturn) {

[self.blockstackProxyTask terminate];
NSLog(@"Blockstack Browser proxy terminated");
NSLog(@"Blockstack Portal proxy terminated");

[self.corsProxyTask terminate];
NSLog(@"CORS proxy terminated");

// Remove the icon from the menu bar
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];

[self stopBlockstackCoreApiAndExit];

}
Expand All @@ -70,7 +170,16 @@ - (IBAction)handleClick:(id)sender

- (void)launchBrowser
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://localhost:8888"]];
[self launchBrowser:NULL];
}
- (void)launchBrowser:(NSString*)path
{
if(path == NULL)
path = @"/";

NSURL *portalURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", [self portalBaseUrl], path]];
NSLog(@"Opening portal: %@", portalURL);
[[NSWorkspace sharedWorkspace] openURL:portalURL];
}

- (void)startBlockstackProxy
Expand All @@ -85,9 +194,9 @@ - (void)startBlockstackProxy
self.blockstackProxyTask = [[NSTask alloc] init];
self.blockstackProxyTask.launchPath = path;

self.blockstackProxyTask.arguments = @[@"8888", browserPath];
self.blockstackProxyTask.arguments = @[[NSString stringWithFormat:@"%d", self.prodModePortalPort], browserPath];

NSLog(@"Starting Blockstack Browser proxy...");
NSLog(@"Starting Blockstack Portal proxy...");

[self.blockstackProxyTask launch];

Expand Down Expand Up @@ -232,8 +341,6 @@ -(void)stopBlockstackCoreApiAndExit
blockstackCoreApiStopTask.terminationHandler = ^(NSTask *aTask){
NSLog(@"Blockstack Core api stopped.");

// Remove the icon from the menu bar
self.menubarController = nil;

NSLog(@"Goodbye!");
exit(0);
Expand Down Expand Up @@ -341,4 +448,19 @@ -(NSString*)accountName
return @"blockstack-core";
}

-(int)portalPort
{
return self.devModeEnabled ? self.devModePortalPort : self.prodModePortalPort;
}

-(NSString*)portalBaseUrl
{
return [NSString stringWithFormat:@"http://localhost:%d", [self portalPort]];
}

-(NSString*) portalAuthPath
{
return @"/auth?authRequest=";
}

@end
15 changes: 13 additions & 2 deletions native/macos/Blockstack/Blockstack/Blockstack-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.0</string>
<string>0.4.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>blockstack</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>17</string>
<string>18</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"images" : [
{
"idiom" : "universal",
"filename" : "blockstack-bug-mac-menubar.png",
"filename" : "blockstack-bug-mac-menubar-1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "blockstack-bug-mac-menubar-1x.png",
"filename" : "blockstack-bug-mac-menubar-2x.png",
"scale" : "2x"
},
{
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"images" : [
{
"idiom" : "universal",
"filename" : "Artboard.png",
"filename" : "blockstack-bug-mac-menubar-1x-inverted.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Artboard-2x.png",
"filename" : "blockstack-bug-mac-menubar-2x-inverted.png",
"scale" : "2x"
},
{
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.
15 changes: 0 additions & 15 deletions native/macos/Blockstack/Blockstack/MenubarController.h

This file was deleted.

Loading

0 comments on commit fb761c8

Please sign in to comment.