From: Lars Op den Kamp Date: Sun, 7 Oct 2012 00:46:26 +0000 (+0200) Subject: exit LibCecTray when we detect that XBMC was started X-Git-Tag: upstream/2.2.0~1^2~17^2^2~22 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f4729954da8ed049a6bc5ea6bbd72e30f158ddc9;p=deb_libcec.git exit LibCecTray when we detect that XBMC was started --- diff --git a/src/LibCecTray/controller/applications/ApplicationController.cs b/src/LibCecTray/controller/applications/ApplicationController.cs index 4d23071..f36bd6a 100644 --- a/src/LibCecTray/controller/applications/ApplicationController.cs +++ b/src/LibCecTray/controller/applications/ApplicationController.cs @@ -42,6 +42,8 @@ using Timer = System.Timers.Timer; namespace LibCECTray.controller.applications { + public delegate void OnApplicationRunningChanged(bool running); + /// /// Controls an application on the PC: send key presses, open the application, close it, etc. /// @@ -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 } } diff --git a/src/LibCecTray/controller/applications/ApplicationControllerUI.cs b/src/LibCecTray/controller/applications/ApplicationControllerUI.cs index a9eb3b5..7ba18f0 100644 --- a/src/LibCecTray/controller/applications/ApplicationControllerUI.cs +++ b/src/LibCecTray/controller/applications/ApplicationControllerUI.cs @@ -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; diff --git a/src/LibCecTray/controller/applications/internal/XBMCController.cs b/src/LibCecTray/controller/applications/internal/XBMCController.cs index b2dfc20..fe15fd2 100644 --- a/src/LibCecTray/controller/applications/internal/XBMCController.cs +++ b/src/LibCecTray/controller/applications/internal/XBMCController.cs @@ -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)