LibCecTray: power management
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 5 Apr 2013 08:51:19 +0000 (10:51 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 5 Apr 2013 09:44:13 +0000 (11:44 +0200)
src/LibCecTray/controller/applications/Applications.cs
src/LibCecTray/ui/CECTray.cs

index 3f3a359b136d877d3ac2ea0f11e9a4ffefdc0fbb..1a11d1310fbf1b7c336d4cd71a9758f7389a62ce 100644 (file)
@@ -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);
 
index 7c08eec2304f4fa8b5749cbbeeb72d9f389c380f..6a04d62f2301da982ecb970cf78547c9031351bc 100644 (file)
@@ -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