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>
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
return !IsInternal;
}
}
+
+ private bool _applicationRunning;
+
#endregion
}
}
public override void SetStartButtonEnabled(bool val)
{
- SetControlEnabled(bStartApplication, !_controller.IsRunning() && !_controller.SuppressApplicationStart && val);
+ SetControlEnabled(bStartApplication, val);
}
private readonly ApplicationController _controller;
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)