Skip to content

Commit

Permalink
add CORS & Portal proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
larrysalibra committed Feb 27, 2017
1 parent eaddee6 commit 9d35095
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
24 changes: 24 additions & 0 deletions native/macos/Blockstack/Blockstack.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
46AB7B411E632F08004DACD8 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 46AB7B3F1E632F08004DACD8 /* MainMenu.xib */; };
46AB7B4C1E632F08004DACD8 /* BlockstackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AB7B4B1E632F08004DACD8 /* BlockstackTests.swift */; };
46AB7B571E632F09004DACD8 /* BlockstackUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AB7B561E632F09004DACD8 /* BlockstackUITests.swift */; };
46AB7B661E64363B004DACD8 /* corsproxy in Resources */ = {isa = PBXBuildFile; fileRef = 46AB7B641E64363B004DACD8 /* corsproxy */; };
46AB7B671E64363B004DACD8 /* blockstackProxy in Resources */ = {isa = PBXBuildFile; fileRef = 46AB7B651E64363B004DACD8 /* blockstackProxy */; };
46AB7B6B1E643675004DACD8 /* blockstack-venv.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 46AB7B691E643675004DACD8 /* blockstack-venv.tar.gz */; };
46AB7B6C1E643675004DACD8 /* browser in Resources */ = {isa = PBXBuildFile; fileRef = 46AB7B6A1E643675004DACD8 /* browser */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -43,6 +47,10 @@
46AB7B521E632F09004DACD8 /* BlockstackUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BlockstackUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
46AB7B561E632F09004DACD8 /* BlockstackUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockstackUITests.swift; sourceTree = "<group>"; };
46AB7B581E632F09004DACD8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
46AB7B641E64363B004DACD8 /* corsproxy */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = corsproxy; path = Blockstack/corsproxy; sourceTree = "<group>"; };
46AB7B651E64363B004DACD8 /* blockstackProxy */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = blockstackProxy; path = Blockstack/blockstackProxy; sourceTree = "<group>"; };
46AB7B691E643675004DACD8 /* blockstack-venv.tar.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; name = "blockstack-venv.tar.gz"; path = "Blockstack/blockstack-venv.tar.gz"; sourceTree = "<group>"; };
46AB7B6A1E643675004DACD8 /* browser */ = {isa = PBXFileReference; lastKnownFileType = folder; name = browser; path = Blockstack/browser; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,6 +81,7 @@
46AB7B2F1E632F08004DACD8 = {
isa = PBXGroup;
children = (
46AB7B681E643643004DACD8 /* Binaries */,
46AB7B3A1E632F08004DACD8 /* Blockstack */,
46AB7B4A1E632F08004DACD8 /* BlockstackTests */,
46AB7B551E632F09004DACD8 /* BlockstackUITests */,
Expand Down Expand Up @@ -119,6 +128,17 @@
path = BlockstackUITests;
sourceTree = "<group>";
};
46AB7B681E643643004DACD8 /* Binaries */ = {
isa = PBXGroup;
children = (
46AB7B691E643675004DACD8 /* blockstack-venv.tar.gz */,
46AB7B6A1E643675004DACD8 /* browser */,
46AB7B641E64363B004DACD8 /* corsproxy */,
46AB7B651E64363B004DACD8 /* blockstackProxy */,
);
name = Binaries;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -229,7 +249,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
46AB7B661E64363B004DACD8 /* corsproxy in Resources */,
46AB7B3E1E632F08004DACD8 /* Assets.xcassets in Resources */,
46AB7B6B1E643675004DACD8 /* blockstack-venv.tar.gz in Resources */,
46AB7B6C1E643675004DACD8 /* browser in Resources */,
46AB7B671E64363B004DACD8 /* blockstackProxy in Resources */,
46AB7B411E632F08004DACD8 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
66 changes: 58 additions & 8 deletions native/macos/Blockstack/Blockstack/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var statusItem : NSStatusItem = NSStatusItem()

var isDevModeEnabled : Bool = false

var isShutdown : Bool = false

let portalProxyProcess = Process()
let corsProxyProcess = Process()

func applicationDidFinishLaunching(_ aNotification: Notification) {
NSLog("applicationDidFinishLaunching")
Expand All @@ -36,10 +41,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.action = #selector(statusItemClick)
}

startPortalProxy()
startCorsProxy()

}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
shutdown(terminate: false)
}

func handleGetURLEvent(_ event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
Expand Down Expand Up @@ -149,19 +157,61 @@ class AppDelegate: NSObject, NSApplicationDelegate {

if alert.runModal() == NSAlertFirstButtonReturn {
NSLog("User decided to exit...")

shutdown(terminate: true)
}
}

func shutdown(terminate: Bool = true) {

if(!isShutdown) {
isShutdown = true // prevent shutdown code from running twice
NSStatusBar.system().removeStatusItem(statusItem)
portalProxyProcess.terminate()
NSLog("Blockstack Portal proxy terminated")
corsProxyProcess.terminate()
NSLog("CORS proxy terminated")

// [self.blockstackProxyTask terminate];
// NSLog(@"Blockstack Portal proxy terminated");
//
// [self.corsProxyTask terminate];
// NSLog(@"CORS proxy terminated");
//
// [self stopBlockstackCoreApiAndExit];
}

if(terminate) {
NSApplication.shared().terminate(self)
}


}


func startPortalProxy() {
let proxyPath = Bundle.main.path(forResource: "blockstackProxy", ofType: "")
let portalPath = Bundle.main.path(forResource: "browser", ofType: "")

NSLog("Portal proxy path: \(proxyPath)")
NSLog("Portal path: \(portalPath)")

portalProxyProcess.launchPath = proxyPath
if let portalPath = portalPath {
portalProxyProcess.arguments = [String(productionModePortalPort), portalPath]

NSLog("Starting Blockstack Portal proxy...")

portalProxyProcess.launch()
} else {
NSLog("Error: Portal directory not found!")
}
}

func startCorsProxy() {
let corsProxyPath = Bundle.main.path(forResource: "corsproxy", ofType: "")

NSLog("CORS proxy Path: \(corsProxyPath)")

corsProxyProcess.launchPath = corsProxyPath

NSLog("Starting CORS proxy...")

corsProxyProcess.launch()
}

}

0 comments on commit 9d35095

Please sign in to comment.