mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
CPU can be throttled in UI.
This commit is contained in:
parent
703f916c53
commit
1222a39867
8 changed files with 199 additions and 5 deletions
|
|
@ -487,3 +487,54 @@ export async function setHotspot(on) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getThrottleStatus() {
|
||||
let response = await apiGet(`${API_URI}/throttle`);
|
||||
if (response.status === 200) {
|
||||
let {status} = await response.json();
|
||||
return status;
|
||||
} else {
|
||||
let code = (await response.json())['code'];
|
||||
if (response.status === 400 && code === 34) {
|
||||
// Must not be running on a RPi. Don't warn the user.
|
||||
return null;
|
||||
} else {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: "Can't get throttle status",
|
||||
description: 'Failed to get CPU Throttle status. Check client and server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function setThrottle(on) {
|
||||
let response;
|
||||
if (on) {
|
||||
response = await apiPost(`${API_URI}/throttle/on`);
|
||||
} else {
|
||||
response = await apiPost(`${API_URI}/throttle/off`);
|
||||
}
|
||||
if (response.status === 204) {
|
||||
return null;
|
||||
} else {
|
||||
let code = (await response.json())['code'];
|
||||
if (code === 34) {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Unsupported!',
|
||||
description: 'Throttle is only supported on a Raspberry Pi!',
|
||||
time: 5000,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Error!',
|
||||
description: 'Could not modify throttle. See server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import {
|
|||
secondsToFrequency,
|
||||
TabLinks,
|
||||
textEllipsis,
|
||||
ThrottleToggle,
|
||||
WROLModeMessage
|
||||
} from "./Common";
|
||||
import {Route} from "react-router-dom";
|
||||
|
|
@ -80,6 +81,8 @@ class Settings extends React.Component {
|
|||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
||||
<HotspotToggle/>
|
||||
<br/>
|
||||
<ThrottleToggle style={{marginTop: '0.5em'}}/>
|
||||
|
||||
<Divider/>
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import Button from "semantic-ui-react/dist/commonjs/elements/Button";
|
|||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {getConfig} from "../api";
|
||||
import {useDownloaders, useHotspot} from "../hooks/customHooks";
|
||||
import {useDownloaders, useHotspot, useThrottle} from "../hooks/customHooks";
|
||||
|
||||
export const API_URI = `http://${window.location.host}/api`;
|
||||
export const VIDEOS_API = `${API_URI}/videos`;
|
||||
|
|
@ -645,9 +645,9 @@ export function CardGroupCentered(props) {
|
|||
)
|
||||
}
|
||||
|
||||
export function HotspotToggle() {
|
||||
export function HotspotToggle(props) {
|
||||
let {on, setHotspot} = useHotspot();
|
||||
return <Checkbox toggle
|
||||
return <Checkbox toggle {...props}
|
||||
label='WiFi Hotspot'
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
|
|
@ -655,6 +655,16 @@ export function HotspotToggle() {
|
|||
/>;
|
||||
}
|
||||
|
||||
export function ThrottleToggle(props) {
|
||||
let {on, setThrottle} = useThrottle();
|
||||
return <Checkbox toggle {...props}
|
||||
label='CPU Power-save'
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setThrottle(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function DisableDownloadsToggle() {
|
||||
let {on, setDownloads} = useDownloaders();
|
||||
return <Checkbox toggle
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import {
|
|||
getDownloaders,
|
||||
getFiles,
|
||||
getHotspotStatus,
|
||||
getThrottleStatus,
|
||||
getVersion,
|
||||
killDownloads,
|
||||
searchArchives,
|
||||
searchVideos,
|
||||
setHotspot,
|
||||
setThrottle,
|
||||
startDownloads
|
||||
} from "../api";
|
||||
import {useHistory} from "react-router-dom";
|
||||
|
|
@ -247,3 +249,30 @@ export const useDownloaders = () => {
|
|||
|
||||
return {on, setOn, downloaders, setDownloads: localSetDownloads};
|
||||
}
|
||||
|
||||
export const useThrottle = () => {
|
||||
const [on, setOn] = useState(null);
|
||||
|
||||
const fetchThrottleStatus = async () => {
|
||||
const status = await getThrottleStatus();
|
||||
if (status === 'powersave') {
|
||||
setOn(true);
|
||||
} else if (status === 'ondemand') {
|
||||
setOn(false);
|
||||
} else {
|
||||
setOn(null);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchThrottleStatus();
|
||||
}, []);
|
||||
|
||||
const localSetThrottle = async (on) => {
|
||||
setOn(null);
|
||||
await setThrottle(on);
|
||||
await fetchThrottleStatus();
|
||||
}
|
||||
|
||||
return {on, setOn, setThrottle: localSetThrottle};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue