import { Fragment } from "react"; import { Component } from "react"; import { ToggleField, SliderField, Field, SingleDropdownOption, Dropdown, PanelSectionRow, staticClasses, } from "decky-frontend-lib"; import * as backend from "../backend"; import { tr } from "usdpl-front"; import { LIMITS_INFO, CHARGE_DESIGN_BATT, CHARGE_FULL_BATT, CHARGE_NOW_BATT, CHARGE_RATE_BATT, CHARGE_MODE_BATT, CURRENT_BATT, CHARGE_LIMIT_BATT, CHARGE_POWER_BATT, } from "../consts"; import { set_value, get_value} from "usdpl-front"; export class Battery extends Component { constructor(props: backend.IdcProps) { super(props); this.state = { reloadThingy: "/shrug", }; } render() { const reloadGUI = (x: string) => this.setState({reloadThingy: x}); const chargeModeOptions: SingleDropdownOption[] = (get_value(LIMITS_INFO) as backend.SettingsLimits).battery.charge_modes.map((elem) => {return { data: elem, label: {elem}, };}); return ( {/* Battery */}
{tr("Battery")}
{get_value(CHARGE_NOW_BATT) != null && get_value(CHARGE_FULL_BATT) != null && {get_value(CHARGE_NOW_BATT).toFixed(1)} Wh ({(100 * get_value(CHARGE_NOW_BATT) / get_value(CHARGE_FULL_BATT)).toFixed(1)}%) } {get_value(CHARGE_FULL_BATT) != null && get_value(CHARGE_DESIGN_BATT) != null && {get_value(CHARGE_FULL_BATT).toFixed(1)} Wh ({(100 * get_value(CHARGE_FULL_BATT) / get_value(CHARGE_DESIGN_BATT)).toFixed(1)}%) } {get_value(CHARGE_POWER_BATT) != null && get_value(CHARGE_POWER_BATT) > 0 && {get_value(CHARGE_POWER_BATT).toFixed(2)} W } {get_value(CURRENT_BATT) != null && {get_value(CURRENT_BATT)} mA } {(get_value(LIMITS_INFO) as backend.SettingsLimits).battery.charge_current != null && { if (value) { set_value(CHARGE_RATE_BATT, (get_value(LIMITS_INFO) as backend.SettingsLimits).battery.charge_current!.max); reloadGUI("BATTChargeRateToggle"); } else { set_value(CHARGE_RATE_BATT, null); backend.resolve(backend.unsetBatteryChargeRate(), (_: any[]) => { reloadGUI("BATTUnsetChargeRate"); }); } }} /> { get_value(CHARGE_RATE_BATT) != null && { backend.log(backend.LogLevel.Debug, "Charge rate is now " + val.toString()); const rateNow = get_value(CHARGE_RATE_BATT); if (val != rateNow) { backend.resolve(backend.setBatteryChargeRate(val), (rate: number) => { set_value(CHARGE_RATE_BATT, rate); reloadGUI("BATTChargeRate"); }); } }} />} } {chargeModeOptions.length != 0 && { if (value) { set_value(CHARGE_MODE_BATT, chargeModeOptions[0].data as string); reloadGUI("BATTChargeModeToggle"); } else { set_value(CHARGE_MODE_BATT, null); backend.resolve(backend.unsetBatteryChargeMode(), (_: any[]) => { reloadGUI("BATTUnsetChargeMode"); }); } }} /> {get_value(CHARGE_MODE_BATT) != null && { return val.data == get_value(CHARGE_MODE_BATT); })} strDefaultLabel={get_value(CHARGE_MODE_BATT)} onChange={(elem: SingleDropdownOption) => { backend.log(backend.LogLevel.Debug, "Charge mode dropdown selected " + elem.data.toString()); backend.resolve(backend.setBatteryChargeMode(elem.data as string), (mode: string) => { set_value(CHARGE_MODE_BATT, mode); reloadGUI("BATTChargeMode"); }); }} /> } } {(get_value(LIMITS_INFO) as backend.SettingsLimits).battery.charge_limit != null && { if (value) { set_value(CHARGE_LIMIT_BATT, (get_value(LIMITS_INFO) as backend.SettingsLimits).battery.charge_limit!.max); reloadGUI("BATTChargeLimitToggle"); } else { set_value(CHARGE_LIMIT_BATT, null); backend.resolve(backend.unsetBatteryChargeLimit(), (_: any[]) => { reloadGUI("BATTUnsetChargeRate"); }); } }} /> { get_value(CHARGE_LIMIT_BATT) != null && { backend.log(backend.LogLevel.Debug, "Charge limit is now " + val.toString()); const rateNow = get_value(CHARGE_LIMIT_BATT); if (val != rateNow) { backend.resolve(backend.setBatteryChargeLimit(val), (rate: number) => { set_value(CHARGE_LIMIT_BATT, rate); reloadGUI("BATTChargeLimit"); }); } }} />} }
); } }