예제 #1
0
        public override async void KeyPressed(KeyPayload payload)
        {
            Logger.Instance.LogMessage(TracingLevel.INFO, $"Key Pressed {this.GetType()}");

            if (String.IsNullOrEmpty(settings.PowerPlan))
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, "Key Pressed but power plan is empty");
                await Connection.ShowAlert();

                return;
            }

            if (!Guid.TryParse(settings.PowerPlan, out Guid guid))
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not parse power plan guid {settings.PowerPlan}");
                await Connection.ShowAlert();

                return;
            }

            try
            {
                PowerPlans.SwitchPowerPlan(guid);
                await Connection.ShowOk();
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"SwitchPowerPlan Exception: {ex}");
                await Connection.ShowAlert();
            }
        }
예제 #2
0
        public void ManualIntegrationTest()
        {
            PowerPlans plans = PowerPlans.Instance;

            Assert.AreEqual(3, plans.Plans.Count);
            Assert.AreSame(plans.Plans[1], plans.ActivePlan);
            var expectedPlans = new PowerPlan[]
            {
                new PowerPlan("381b4222-f694-41f0-9685-ff5bb260df2e", "Balanced"),
                //new PowerPlan("6d1902df-e109-4499-a36e-39f6393ca9ae", "My Custom Plan 1"),
                new PowerPlan("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c", "High performance"),
                new PowerPlan("a1841308-3541-4fab-bc81-f71556f20b4a", "Power saver")
            };
        }
        /// <summary>
        ///     Retrieves a list of available power plans and determines the currently active one.
        /// </summary>
        internal void LoadPowerPlans()
        {
            // use the powercfg cmd tool to determine existing powerplans and the currently active one.
            var process = new Process {
                StartInfo = _startInfo
            };

            process.Start();
            process.StandardInput.WriteLine("powercfg /L");
            process.StandardInput.WriteLine("exit");
            var utf8Reader = new StreamReader(process.StandardOutput.BaseStream, Encoding.GetEncoding(437));

            Console.WriteLine(utf8Reader.CurrentEncoding);
            var output = utf8Reader.ReadToEnd();

            Console.WriteLine(output);
            utf8Reader.Close();
            process.Dispose();

            // parse the output from powercfg
            PowerPlans.Clear();
            foreach (var line in output.Split('\n'))
            {
                if ((line.Trim().Length == 0) || !line.Contains("GUID"))
                {
                    continue;
                }

                var guid      = line.Substring(line.IndexOf(':') + 2).Remove(36);
                var name      = line.Substring(line.IndexOf('(')).Replace('*', ' ').Trim();
                var powerPlan = new PowerPlan(guid, name.Replace('(', ' ').Replace(')', ' ').Trim());
                PowerPlans.Add(powerPlan);

                if (line.Contains("*"))
                {
                    ActivePlan = powerPlan;
                }
            }
        }
예제 #4
0
        public async override void OnTick()
        {
            var powerPlan = PowerPlans.GetActivePowerPlan();

            if (powerPlan == null)
            {
                return;
            }

            if (settings.PowerPlan == powerPlan.Guid)
            {
                await Connection.SetImageAsync(GetActivePowerImage());
            }
            else
            {
                await Connection.SetImageAsync((string)null);
            }

            if (settings.ShowActivePowerPlan)
            {
                await Connection.SetTitleAsync(FormatStringToKey(powerPlan.Name));
            }
        }
        public async override void OnTick()
        {
            var powerPlan = PowerPlans.GetActivePowerPlan();

            if (powerPlan == null)
            {
                return;
            }

            if (settings.PowerPlan == powerPlan.Guid)
            {
                await Connection.SetImageAsync(GetActivePowerImage());
            }
            else
            {
                await Connection.SetImageAsync((string)null);
            }

            if (settings.ShowActivePowerPlan)
            {
                await Connection.SetTitleAsync(Tools.SplitStringToFit(powerPlan.Name, titleParameters));
            }
        }
예제 #6
0
 private void LoadAllPowerPlans()
 {
     settings.PowerPlans = PowerPlans.GetAll().ToList();
 }
        // index that points to currently active plan in guids and names arrays

        internal int GetIndexOfActivePlan()
        {
            return(PowerPlans.IndexOf(ActivePlan));
        }