exit LibCecTray when we detect that XBMC was started
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 00:46:26 +0000 (02:46 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 00:46:26 +0000 (02:46 +0200)
src/LibCecTray/controller/applications/ApplicationController.cs
src/LibCecTray/controller/applications/ApplicationControllerUI.cs
src/LibCecTray/controller/applications/internal/XBMCController.cs

index 4d23071946db8ecfff2e61d5fc32c9a4e5240581..f36bd6ae7efaeda194fba55558400e6073fe26ba 100644 (file)
@@ -42,6 +42,8 @@ using Timer = System.Timers.Timer;
 
 namespace LibCECTray.controller.applications
 {
+  public delegate void OnApplicationRunningChanged(bool running);
+
   /// <summary>
   /// Controls an application on the PC: send key presses, open the application, close it, etc.
   /// </summary>
@@ -190,12 +192,24 @@ namespace LibCECTray.controller.applications
     public virtual void Initialise()
     {
       Timer timer = new Timer { Interval = 1000, AutoReset = true };
-      timer.Elapsed += delegate { UiControl.SetStartButtonEnabled(true); };
+      timer.Elapsed += delegate { CheckApplicationEnabled(); };
       timer.Start();
 
       if (AutoStartApplication.Value)
         Start(false);
     }
+
+    public event OnApplicationRunningChanged ApplicationRunningChanged;
+
+    private void CheckApplicationEnabled()
+    {
+      var isRunning = IsRunning();
+      if (isRunning != _applicationRunning && ApplicationRunningChanged != null)
+        ApplicationRunningChanged(isRunning);
+
+      _applicationRunning = isRunning;
+      UiControl.SetStartButtonEnabled(isRunning && !SuppressApplicationStart);
+    }
     #endregion
 
     #region Send input to the application
@@ -377,6 +391,9 @@ namespace LibCECTray.controller.applications
         return !IsInternal;
       }
     }
+
+    private bool _applicationRunning;
+
     #endregion
   }
 }
index a9eb3b5fc8dd163010b3ec439cac345520c1a5a9..7ba18f0292cf21bd3dae61eae4fb8523a5277bc5 100644 (file)
@@ -78,7 +78,7 @@ namespace LibCECTray.controller.applications
 
     public override void SetStartButtonEnabled(bool val)
     {
-      SetControlEnabled(bStartApplication, !_controller.IsRunning() && !_controller.SuppressApplicationStart && val);
+      SetControlEnabled(bStartApplication, val);
     }
 
     private readonly ApplicationController _controller;
index b2dfc20455973408970b258a79a136a0218c9663..fe15fd25edc18d3b62c2442ab9d3ce17b2433d4d 100644 (file)
@@ -56,6 +56,17 @@ namespace LibCECTray.controller.applications.@internal
       ControlApplication.Value = false;
 
       LoadXMLConfiguration();
+
+      ApplicationRunningChanged += RunningChanged;
+    }
+
+         static void RunningChanged(bool running)
+    {
+      if (running)
+      {
+        // XBMC is running, close the application, or we'll block communication
+        Application.Exit();
+      }
     }
 
     public override ApplicationAction DefaultValue(CecKeypress key)