Skip to content

Commit

Permalink
Battery UX fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
aredden committed Jan 5, 2021
1 parent 70bde6c commit 4872f1d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Components/Content/Battery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export default class Battery extends Component<Props, State> {
);
this.setState({ batteryLimitStatus: true });
store.dispatch(updateBatteryLimitStatus(true));
} else {
message.error('Error attempting to set battery limit.');
}
});
} else {
Expand All @@ -147,6 +149,23 @@ export default class Battery extends Component<Props, State> {
}
};

handleModifyEnabled = (limit: number) => {
const { batteryLimitStatus } = this.state;
if (batteryLimitStatus && limit && limit > 20) {
message.loading('Submitting battery charge limit...');
window.ipcRenderer
.invoke('setBatteryLimiter', limit)
.then((result: boolean) => {
if (result) {
message.success('Successfully set battery limit to: ' + limit);
store.dispatch(updateBatteryLimit(limit));
} else {
message.error('Error attempting to set battery limit.');
}
});
}
};

render() {
const { batteryLimit, batteryLimitStatus } = this.state;
return (
Expand Down Expand Up @@ -186,7 +205,7 @@ export default class Battery extends Component<Props, State> {
max={100}
step={5}
onAfterChange={(batteryLimit: number) =>
store.dispatch(updateBatteryLimit(batteryLimit))
this.handleModifyEnabled(batteryLimit)
}
value={batteryLimit ? batteryLimit : 0}
/>
Expand Down

0 comments on commit 4872f1d

Please sign in to comment.