Beispiel #1
0
        private void AddMenuItems()
        {
            // Add an item for each power plan.
            PowerPlan currentPlan = powerManager.GetCurrentPlan();

            foreach (PowerPlan p in plans)
            {
                ToolStripMenuItem item = new ToolStripMenuItem(p.name);
                PowerPlan         pp   = p;
                item.Click += delegate(object sender, EventArgs args)
                {
                    powerManager.SetActive(pp);
                };
                item.Checked = (currentPlan == p);
                notifyIcon.ContextMenuStrip.Items.Add(item);
            }

            notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());

            // Utility items.
            {
                var item = new ToolStripMenuItem("Open control panel");
                item.Click += OpenControlPanelClick;
                notifyIcon.ContextMenuStrip.Items.Add(item);
            }

            {
                var item = new ToolStripMenuItem("Exit");
                item.Click += ExitClick;
                notifyIcon.ContextMenuStrip.Items.Add(item);
            }
        }
        public void SetActive(PowerPlan plan)
        {
            PowerSetActiveScheme(IntPtr.Zero, ref plan.guid);
            uiCallback.UpdateBatteryState();

            Logger.Instance().Info("Switched to " + plan.name);
        }
Beispiel #3
0
        public void UpdateBatteryState()
        {
            PowerPlan currentPlan  = powerManager.GetCurrentPlan();
            bool      isCharging   = powerManager.IsCharging();
            int       percentValue = powerManager.GetChargeValue();

            UpdateBatteryState(currentPlan.name, isCharging, percentValue);
        }
        public PowerManager(UICallback uiCallback)
        {
            this.uiCallback = uiCallback;

            // See GUID values in WinNT.h.
            MaximumPerformance = NewPlan("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c");
            Balanced = NewPlan("381b4222-f694-41f0-9685-ff5bb260df2e");
            PowerSourceOptimized = NewPlan("a1841308-3541-4fab-bc81-f71556f20b4a");

            // Add handler for power mode state changing.
            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(PowerModeChangedHandler);
        }
        public PowerManager(UICallback uiCallback)
        {
            this.uiCallback = uiCallback;

            // See GUID values in WinNT.h.
            MaximumPerformance   = NewPlan("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c");
            Balanced             = NewPlan("381b4222-f694-41f0-9685-ff5bb260df2e");
            PowerSourceOptimized = NewPlan("a1841308-3541-4fab-bc81-f71556f20b4a");

            // Add handler for power mode state changing.
            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(PowerModeChangedHandler);
        }
        public PowerPlan GetCurrentPlan()
        {
            Guid      guid = GetActiveGuid();
            PowerPlan pp   = GetPlans().Find(p => (p.guid == guid));

            if (pp == null)
            {
                string name = GetPowerPlanName(guid);
                return(new PowerPlan(name, guid));
            }

            return(pp);
        }
        public void SetActive(PowerPlan plan)
        {
            PowerSetActiveScheme(IntPtr.Zero, ref plan.guid);
            uiCallback.UpdateBatteryState();

            Logger.Instance().Info("Switched to " + plan.name);
        }