From: Lars Op den Kamp Date: Fri, 5 Apr 2013 08:51:19 +0000 (+0200) Subject: LibCecTray: power management X-Git-Tag: upstream/2.2.0~1^2~4^2~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fec04a82ac869da26cd02a64be354cbd08ecdc1b;p=deb_libcec.git LibCecTray: power management --- diff --git a/src/LibCecTray/controller/applications/Applications.cs b/src/LibCecTray/controller/applications/Applications.cs index 3f3a359..1a11d13 100644 --- a/src/LibCecTray/controller/applications/Applications.cs +++ b/src/LibCecTray/controller/applications/Applications.cs @@ -122,7 +122,8 @@ namespace LibCECTray.controller.applications public static void Initialise(CECController controller) { _controller = controller; - _instance = new Applications(); + if (_instance == null) + _instance = new Applications(); controller.Settings["global_applications"] = _instance; controller.Settings.Load(_instance); diff --git a/src/LibCecTray/ui/CECTray.cs b/src/LibCecTray/ui/CECTray.cs index 7c08eec..6a04d62 100644 --- a/src/LibCecTray/ui/CECTray.cs +++ b/src/LibCecTray/ui/CECTray.cs @@ -38,6 +38,8 @@ using LibCECTray.Properties; using LibCECTray.controller; using LibCECTray.controller.applications; using LibCECTray.settings; +using Microsoft.Win32; +using System.Security.Permissions; namespace LibCECTray.ui { @@ -70,6 +72,28 @@ namespace LibCECTray.ui else OnShow(); }; + SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChanged); + SystemEvents.SessionEnding += new SessionEndingEventHandler(OnSessionEnding); + } + + public void OnSessionEnding(object sender, SessionEndingEventArgs e) + { + Controller.Close(); + } + + public void OnPowerModeChanged(Object sender, PowerModeChangedEventArgs e) + { + switch (e.Mode) + { + case PowerModes.Resume: + Controller.Initialise(); + break; + case PowerModes.Suspend: + Controller.Close(); + break; + case PowerModes.StatusChange: + break; + } } public override sealed string Text