From 0ae71940ec66ed449536c4bf2161f73e35dbb44c Mon Sep 17 00:00:00 2001 From: Larry Salibra Date: Mon, 27 Feb 2017 02:01:46 +0200 Subject: [PATCH] exit dialog & open portal --- .../Blockstack/Blockstack/AppDelegate.swift | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/native/macos/Blockstack/Blockstack/AppDelegate.swift b/native/macos/Blockstack/Blockstack/AppDelegate.swift index 44136732e..707d89103 100644 --- a/native/macos/Blockstack/Blockstack/AppDelegate.swift +++ b/native/macos/Blockstack/Blockstack/AppDelegate.swift @@ -17,6 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let corsProxyPort = 1337 let coreProxyPort = 6270 + var statusItem : NSStatusItem = NSStatusItem() var isDevModeEnabled : Bool = false @@ -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?) { @@ -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) @@ -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]; + + + } } }