From ce62576ba4cb455a64f22a59f30eef7c0c8767fc Mon Sep 17 00:00:00 2001 From: dbuechel Date: Thu, 17 Aug 2017 15:04:19 +0200 Subject: [PATCH] Minor refactoring. --- .../PowerSupply.cs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/SafeExamBrowser.SystemComponents/PowerSupply.cs b/SafeExamBrowser.SystemComponents/PowerSupply.cs index 9efe70cc..6e7804a4 100644 --- a/SafeExamBrowser.SystemComponents/PowerSupply.cs +++ b/SafeExamBrowser.SystemComponents/PowerSupply.cs @@ -78,19 +78,7 @@ namespace SafeExamBrowser.SystemComponents var hours = SystemInformation.PowerStatus.BatteryLifeRemaining / 3600; var minutes = (SystemInformation.PowerStatus.BatteryLifeRemaining - (hours * 3600)) / 60; - if (status == BatteryChargeStatus.Low && !infoShown) - { - control.ShowLowBatteryInfo(text.Get(TextKey.SystemControl_BatteryChargeLowInfo)); - infoShown = true; - logger.Info("Informed the user about low battery charge."); - } - - if (status == BatteryChargeStatus.Critical && !warningShown) - { - control.ShowCriticalBatteryWarning(text.Get(TextKey.SystemControl_BatteryChargeCriticalWarning)); - warningShown = true; - logger.Warn("Warned the user about critical battery charge."); - } + HandleBatteryStatus(status); tooltip = text.Get(TextKey.SystemControl_BatteryRemainingCharge); tooltip = tooltip.Replace("%%HOURS%%", hours.ToString()); @@ -103,5 +91,22 @@ namespace SafeExamBrowser.SystemComponents control.SetPowerGridConnection(online); control.SetTooltip(tooltip); } + + private void HandleBatteryStatus(BatteryChargeStatus status) + { + if (status == BatteryChargeStatus.Low && !infoShown) + { + control.ShowLowBatteryInfo(text.Get(TextKey.SystemControl_BatteryChargeLowInfo)); + infoShown = true; + logger.Info("Informed the user about low battery charge."); + } + + if (status == BatteryChargeStatus.Critical && !warningShown) + { + control.ShowCriticalBatteryWarning(text.Get(TextKey.SystemControl_BatteryChargeCriticalWarning)); + warningShown = true; + logger.Warn("Warned the user about critical battery charge."); + } + } } }