Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
22 lines (19 sloc) 871 Bytes
using AnyStatus.API;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStatus
{
public class BatteryStatusQuery : IMetricQuery<Battery>
{
public Task Handle(MetricQueryRequest<Battery> request, CancellationToken cancellationToken)
{
var power = SystemInformation.PowerStatus;
request.DataContext.Value = power.BatteryLifePercent.ToString("P0");
request.DataContext.Progress = (int)(power.BatteryLifePercent * 100);
request.DataContext.Message = $"{power.BatteryLifeRemaining / 3600} hr {power.BatteryLifeRemaining % 3600 / 60} min remaining";
request.DataContext.State = power.BatteryLifePercent * 100 >= request.DataContext.BatteryLifePercentThreshold ? State.Ok : State.Failed;
return Task.CompletedTask;
}
}
}
You can’t perform that action at this time.