Skip to content

Commit

Permalink
fix: solved battery saving mode state retrieval issues
Browse files Browse the repository at this point in the history
Data nature changed, in the previous FW the data was "true"/"false" strings, but now is 0:1
integers, that change breaks data treatment and needs to be compensated.
  • Loading branch information
AlexDygma committed Jul 7, 2023
1 parent 5ac2fc7 commit 0b1c8b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/renderer/modules/BatteryStatus/BatteryStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const BatteryStatus = props => {
setbRight(parseInt(right, 10));
setsLeft(leftStatus.includes("0x") ? 255 : parseInt(leftStatus, 10));
setsRight(rightStatus.includes("0x") ? 255 : parseInt(rightStatus, 10));
setIsSavingMode(savingMode);
setIsSavingMode(parseInt(savingMode, 10) > 0);
}

useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/modules/Settings/BatterySettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ function BatterySettings({ wireless, toggleSavingMode, changeWireless, isChargin
<BatteryStatusSide
side="left"
batteryLevel={wireless.battery ? wireless.battery.LeftLevel : 100}
isSavingMode={wireless.battery ? String(wireless.battery.savingMode).includes("true") : false}
isSavingMode={wireless.battery ? wireless.battery.savingMode : false}
batteryStatus={wireless.battery ? wireless.battery.LeftState : 0}
size="lg"
/>
<BatteryStatusSide
side="right"
batteryLevel={wireless.battery ? wireless.battery.RightLevel : 100}
isSavingMode={wireless.battery ? String(wireless.battery.savingMode).includes("true") : false}
isSavingMode={wireless.battery ? wireless.battery.savingMode : false}
batteryStatus={wireless.battery ? wireless.battery.RightState : 0}
size="lg"
/>
<SavingModeIndicator isSavingMode={wireless.battery ? String(wireless.battery.savingMode).includes("true") : false} />
<SavingModeIndicator isSavingMode={wireless.battery ? wireless.battery.savingMode : false} />
</div>
<Form className="batterySettingItem batterySetSavingMode">
<div className="batterySettingLabel">Saving Mode</div>
<Form.Check
type="switch"
id="settingSavingMode"
checked={wireless.battery ? String(wireless.battery.savingMode).includes("true") : false}
checked={wireless.battery ? wireless.battery.savingMode : false}
onChange={toggleSavingMode}
/>
</Form>
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/views/Wireless.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// General imports
import React, { useState, useEffect } from "react";
import i18n from "../i18n";
import Focus from "../../api/focus";

// Bootstrap components imports
import Styled from "styled-components";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Focus from "../../api/focus";
import i18n from "../i18n";

// Custom component imports
import PageHeader from "../modules/PageHeader";
Expand Down Expand Up @@ -52,7 +52,7 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont
wireless.battery.RightState = state ? parseInt(state, 10) : 0;
});
await focus.command("wireless.battery.savingMode").then(batteryMode => {
wireless.battery.savingMode = batteryMode;
wireless.battery.savingMode = parseInt(batteryMode, 10) > 0;
});

// Energy commands
Expand Down Expand Up @@ -107,9 +107,9 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont

async function toggleSavingMode() {
const focus = new Focus();
await focus.command("wireless.battery.savingMode", !String(wireless.battery.savingMode).includes("true"));
await focus.command("wireless.battery.savingMode", !wireless.battery.savingMode ? 1 : 0);
const newWireless = { ...wireless };
newWireless.battery.savingMode = !String(wireless.battery.savingMode).includes("true");
newWireless.battery.savingMode = !wireless.battery.savingMode;
setWireless(newWireless);
}

Expand All @@ -132,7 +132,7 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont
const focus = new Focus();

// Commands to be sent to the keyboard
await focus.command("wireless.battery.savingMode", wireless.battery.savingMode);
await focus.command("wireless.battery.savingMode", wireless.battery.savingMode ? 1 : 0);
await focus.command("wireless.energy.modes", wireless.energy.modes);
await focus.command("wireless.energy.currentMode", wireless.energy.currentMode);
await focus.command("wireless.energy.disable", wireless.energy.disable);
Expand Down

0 comments on commit 0b1c8b7

Please sign in to comment.