Daemon status auto-update in a popup

Change-Id: I5d0b79ea5beda95ace811e705ca45ed5fa6339a1
diff --git a/osx/MainMenu.xib b/osx/MainMenu.xib
index 6fa5cef..8ee537e 100644
--- a/osx/MainMenu.xib
+++ b/osx/MainMenu.xib
@@ -17,6 +17,7 @@
                 <outlet property="connectionStatusText" destination="EUJ-R2-Os4" id="2pC-dc-tng"/>
                 <outlet property="connectionStatusView" destination="24d-37-bzd" id="AYC-I7-1KX"/>
                 <outlet property="daemonStatus" destination="Tap-5m-ZRP" id="yrK-Nr-zKm"/>
+                <outlet property="daemonStatusText" destination="XxQ-Xi-z1I" id="tTA-y8-Uze"/>
                 <outlet property="daemonStatusView" destination="NBE-Gf-zLc" id="91G-ey-DeA"/>
                 <outlet property="forwardingSettingsView" destination="lQz-E7-PRx" id="8MT-1G-PZi"/>
                 <outlet property="generalSettingsView" destination="A7D-GN-X5W" id="Apc-XD-aOH"/>
@@ -84,11 +85,11 @@
             </connections>
         </popover>
         <customView id="pEE-BK-JGJ">
-            <rect key="frame" x="0.0" y="0.0" width="247" height="132"/>
+            <rect key="frame" x="0.0" y="0.0" width="330" height="258"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="90x-3T-Z7e">
-                    <rect key="frame" x="57" y="82" width="166" height="17"/>
+                    <rect key="frame" x="82" y="234" width="166" height="17"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="NDN Daemon Status" id="Di0-ug-aeg">
                         <font key="font" metaFont="system"/>
@@ -96,6 +97,15 @@
                         <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                     </textFieldCell>
                 </textField>
+                <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XxQ-Xi-z1I">
+                    <rect key="frame" x="7" y="7" width="315" height="219"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Multiline Label" id="R13-Gb-7b6">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
             </subviews>
         </customView>
         <customView id="NBE-Gf-zLc">
diff --git a/osx/menu-delegate.h b/osx/menu-delegate.h
index 05746c0..485a98d 100644
--- a/osx/menu-delegate.h
+++ b/osx/menu-delegate.h
@@ -28,6 +28,7 @@
     BOOL enableHubDiscovery;
   
     IBOutlet NSView *daemonStatusView;
+    IBOutlet NSTextField *daemonStatusText;
   
     IBOutlet NSView *connectionStatusView;
     IBOutlet NSTextField *connectionStatusText;
diff --git a/osx/menu-delegate.mm b/osx/menu-delegate.mm
index d91e780..cdb02e7 100644
--- a/osx/menu-delegate.mm
+++ b/osx/menu-delegate.mm
@@ -16,7 +16,15 @@
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 {
-  // Insert code here to initialize your application
+  daemonStarted = false;
+  allowSoftwareUpdates = true;
+  enableHubDiscovery = true;
+  
+  NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 1.0
+                      target: self
+                      selector:@selector(onTick:)
+                      userInfo: nil repeats:YES];
+  [[NSRunLoop mainRunLoop] addTimer:t forMode:NSRunLoopCommonModes];
 }
 
 -(void)awakeFromNib
@@ -39,9 +47,6 @@
   [connectionStatus setTarget:self];
   [daemonStatus setView: daemonStatusView];
   [daemonStatus setTarget:self];
-
-  daemonStarted = false;
-  //[NSApp activateIgnoringOtherApps:YES];
 }
 
 -(IBAction)switchDaemon:(id)sender
@@ -158,4 +163,25 @@
   }
 }
 
+-(void)onTick:(NSTimer *)timer
+{
+  if (daemonStarted)
+  {
+    NSTask *task = [[NSTask alloc] init];
+    [task setLaunchPath: NDND_STATUS_COMMAND];
+    
+    NSPipe * out = [NSPipe pipe];
+    [task setStandardOutput:out];
+
+    [task launch];
+    [task waitUntilExit];
+
+    NSFileHandle * read = [out fileHandleForReading];
+    NSData * dataRead = [read readDataToEndOfFile];
+    NSString *stringRead = [[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding];
+  
+    [daemonStatusText setStringValue:stringRead];
+  }
+}
+
 @end