Skip to content

Commit

Permalink
exit dialog & open portal
Browse files Browse the repository at this point in the history
  • Loading branch information
larrysalibra committed Feb 27, 2017
1 parent 9faebf6 commit 0ae7194
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions native/macos/Blockstack/Blockstack/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let corsProxyPort = 1337
let coreProxyPort = 6270


var statusItem : NSStatusItem = NSStatusItem()

var isDevModeEnabled : Bool = false
Expand All @@ -32,16 +33,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.action = #selector(statusItemClick)
}



}

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

func portalBaseUrl() -> String {
return "http://localhost:\(portalPort())"
}

func portalPort() -> Int {
return isDevModeEnabled ? developmentModePortalPort : productionModePortalPort
}

func openPortalClick(sender: AnyObject?) {

NSLog("openPortalClick")
openPortal(path: "/")
}

func openPortal(path: String?) {
let portalURL = URL(string: "\(portalBaseUrl())\(path ?? "/")")
NSLog("Opening portal with URL: \(portalURL)")
NSWorkspace.shared().open(portalURL!)
}

func statusItemClick(sender: AnyObject?) {
Expand Down Expand Up @@ -69,7 +83,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if showExpandedMenu {

let portalPortMenuItem = NSMenuItem()
portalPortMenuItem.title = "Portal proxy running on port \(isDevModeEnabled ? developmentModePortalPort : productionModePortalPort)"
portalPortMenuItem.title = "Portal proxy running on port \(portalPort())"
portalPortMenuItem.isEnabled = false
menu.addItem(portalPortMenuItem)

Expand Down Expand Up @@ -108,6 +122,30 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func exitClick(sender: AnyObject?) {
NSLog("exitClick")

let alert = NSAlert()

alert.addButton(withTitle: "Turn off")
alert.addButton(withTitle: "Cancel")
alert.messageText = "Turn off Blockstack?"
alert.informativeText = "You will not be able to access the decentralized internet if you turn off Blockstack."
alert.alertStyle = NSAlertStyle.warning

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

NSStatusBar.system().removeStatusItem(statusItem)

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


}
}
}

0 comments on commit 0ae7194

Please sign in to comment.