mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 09:26:17 -05:00
Creating Controller service which will control WROLPi services, admin, SMART, disks, and status. nginx will fallback to Controller UI when React UI is unavailable (such as during upgrades).
This commit is contained in:
parent
344fe9035f
commit
b9158b60fe
66 changed files with 9920 additions and 327 deletions
|
|
@ -119,9 +119,9 @@ function handleEvents(events) {
|
|||
|
||||
if (event === 'upgrade_started') {
|
||||
eventToast('Upgrade Started', message, 'info', 10000);
|
||||
// Redirect to maintenance page after a short delay
|
||||
// Redirect to Controller UI for upgrade status after a short delay
|
||||
setTimeout(() => {
|
||||
window.location.href = '/maintenance.html';
|
||||
window.location.href = '/controller/?upgrade=true';
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
|
|
|||
186
app/src/api/controller.js
Normal file
186
app/src/api/controller.js
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/**
|
||||
* Controller API client for WROLPi.
|
||||
*
|
||||
* These functions call the Controller service endpoints.
|
||||
* Controller handles system-level operations that need to work
|
||||
* even when the main API is down.
|
||||
*/
|
||||
|
||||
// Controller endpoints are served under /controller/api
|
||||
const CONTROLLER_BASE = '/controller/api';
|
||||
|
||||
/**
|
||||
* Fetch with error handling for Controller endpoints.
|
||||
*/
|
||||
async function controllerFetch(endpoint, options = {}) {
|
||||
const url = `${CONTROLLER_BASE}${endpoint}`;
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({detail: response.statusText}));
|
||||
throw new Error(error.detail || 'Controller request failed');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// --- Status Endpoints ---
|
||||
|
||||
/**
|
||||
* Get all system stats from the Controller.
|
||||
* Returns CPU, memory, load, drives, network, power, iostat, processes,
|
||||
* disk_bandwidth along with system info (dockerized, is_rpi, hotspot, throttle).
|
||||
*/
|
||||
export async function getControllerStats() {
|
||||
return controllerFetch('/stats');
|
||||
}
|
||||
|
||||
export async function getCpuStatus() {
|
||||
return controllerFetch('/status/cpu');
|
||||
}
|
||||
|
||||
export async function getMemoryStatus() {
|
||||
return controllerFetch('/status/memory');
|
||||
}
|
||||
|
||||
export async function getLoadStatus() {
|
||||
return controllerFetch('/status/load');
|
||||
}
|
||||
|
||||
export async function getDrivesStatus() {
|
||||
return controllerFetch('/status/drives');
|
||||
}
|
||||
|
||||
export async function getPrimaryDriveStatus() {
|
||||
return controllerFetch('/status/primary-drive');
|
||||
}
|
||||
|
||||
export async function getNetworkStatus() {
|
||||
return controllerFetch('/status/network');
|
||||
}
|
||||
|
||||
export async function getPowerStatus() {
|
||||
return controllerFetch('/status/power');
|
||||
}
|
||||
|
||||
// --- Admin Endpoints ---
|
||||
|
||||
export async function getHotspotStatus() {
|
||||
return controllerFetch('/hotspot/status');
|
||||
}
|
||||
|
||||
export async function enableHotspot() {
|
||||
return controllerFetch('/hotspot/enable', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function disableHotspot() {
|
||||
return controllerFetch('/hotspot/disable', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function getThrottleStatus() {
|
||||
return controllerFetch('/throttle/status');
|
||||
}
|
||||
|
||||
export async function enableThrottle() {
|
||||
return controllerFetch('/throttle/enable', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function disableThrottle() {
|
||||
return controllerFetch('/throttle/disable', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function shutdownSystem() {
|
||||
return controllerFetch('/shutdown', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function rebootSystem() {
|
||||
return controllerFetch('/reboot', {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function restartServices() {
|
||||
return controllerFetch('/restart', {method: 'POST'});
|
||||
}
|
||||
|
||||
// --- Service Endpoints ---
|
||||
|
||||
export async function getServices() {
|
||||
return controllerFetch('/services');
|
||||
}
|
||||
|
||||
export async function getServiceStatus(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}`);
|
||||
}
|
||||
|
||||
export async function startService(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}/start`, {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function stopService(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}/stop`, {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function restartService(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}/restart`, {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function enableService(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}/enable`, {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function disableService(serviceName) {
|
||||
return controllerFetch(`/services/${serviceName}/disable`, {method: 'POST'});
|
||||
}
|
||||
|
||||
export async function getServiceLogs(serviceName, lines = 100) {
|
||||
return controllerFetch(`/services/${serviceName}/logs?lines=${lines}`);
|
||||
}
|
||||
|
||||
// --- Disk Endpoints ---
|
||||
|
||||
export async function getDisks() {
|
||||
return controllerFetch('/disks');
|
||||
}
|
||||
|
||||
export async function getMounts() {
|
||||
return controllerFetch('/disks/mounts');
|
||||
}
|
||||
|
||||
export async function mountDisk(device, mountPoint) {
|
||||
return controllerFetch('/disks/mount', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({device, mount_point: mountPoint}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function unmountDisk(mountPoint, lazy = false) {
|
||||
return controllerFetch('/disks/unmount', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({mount_point: mountPoint, lazy}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function detectWrolpiDrives() {
|
||||
return controllerFetch('/disks/detect-wrolpi');
|
||||
}
|
||||
|
||||
export async function getSmartStatus() {
|
||||
return controllerFetch('/disks/smart');
|
||||
}
|
||||
|
||||
// --- Health Check ---
|
||||
|
||||
export async function healthCheck() {
|
||||
return controllerFetch('/health');
|
||||
}
|
||||
|
||||
// --- Controller Info ---
|
||||
|
||||
export async function getControllerInfo() {
|
||||
return controllerFetch('/info');
|
||||
}
|
||||
|
|
@ -27,6 +27,12 @@ import {
|
|||
StatisticGroup as SStatisticGroup,
|
||||
Tab as STab,
|
||||
Table as STable,
|
||||
TableBody as STableBody,
|
||||
TableCell as STableCell,
|
||||
TableFooter as STableFooter,
|
||||
TableHeader as STableHeader,
|
||||
TableHeaderCell as STableHeaderCell,
|
||||
TableRow as STableRow,
|
||||
TabPane as STabPane,
|
||||
TextArea as STextArea,
|
||||
AccordionProps,
|
||||
|
|
@ -55,6 +61,12 @@ import {
|
|||
StatisticGroupProps,
|
||||
TabProps,
|
||||
TableProps,
|
||||
TableBodyProps,
|
||||
TableCellProps,
|
||||
TableFooterProps,
|
||||
TableHeaderProps,
|
||||
TableHeaderCellProps,
|
||||
TableRowProps,
|
||||
TabPaneProps,
|
||||
TextAreaProps,
|
||||
} from "semantic-ui-react";
|
||||
|
|
@ -262,10 +274,7 @@ export function Segment(props: SegmentProps) {
|
|||
return <SSegment {...i} {...props}/>
|
||||
}
|
||||
|
||||
export function Table(props: TableProps) {
|
||||
const {i} = useContext(ThemeContext);
|
||||
return <STable {...i} {...props}/>
|
||||
}
|
||||
// Table is now a compound component - see COMPOUND COMPONENTS section below
|
||||
|
||||
export function TextArea(props: TextAreaProps) {
|
||||
const {i} = useContext(ThemeContext);
|
||||
|
|
@ -498,3 +507,61 @@ const BreadcrumbBase: React.FC<BreadcrumbProps> = (props) => {
|
|||
export const Breadcrumb: BreadcrumbComponent = Object.assign(BreadcrumbBase, {
|
||||
Divider: BreadcrumbDivider,
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Table Compound Component
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type TableBodyComponent = React.FC<TableBodyProps>;
|
||||
type TableCellComponent = React.FC<TableCellProps>;
|
||||
type TableFooterComponent = React.FC<TableFooterProps>;
|
||||
type TableHeaderComponent = React.FC<TableHeaderProps>;
|
||||
type TableHeaderCellComponent = React.FC<TableHeaderCellProps>;
|
||||
type TableRowComponent = React.FC<TableRowProps>;
|
||||
|
||||
interface TableComponent extends React.FC<TableProps> {
|
||||
Body: TableBodyComponent;
|
||||
Cell: TableCellComponent;
|
||||
Footer: TableFooterComponent;
|
||||
Header: TableHeaderComponent;
|
||||
HeaderCell: TableHeaderCellComponent;
|
||||
Row: TableRowComponent;
|
||||
}
|
||||
|
||||
const TableBody: TableBodyComponent = (props) => {
|
||||
return <STableBody {...props}/>
|
||||
};
|
||||
|
||||
const TableCell: TableCellComponent = (props) => {
|
||||
return <STableCell {...props}/>
|
||||
};
|
||||
|
||||
const TableFooter: TableFooterComponent = (props) => {
|
||||
return <STableFooter {...props}/>
|
||||
};
|
||||
|
||||
const TableHeader: TableHeaderComponent = (props) => {
|
||||
return <STableHeader {...props}/>
|
||||
};
|
||||
|
||||
const TableHeaderCell: TableHeaderCellComponent = (props) => {
|
||||
return <STableHeaderCell {...props}/>
|
||||
};
|
||||
|
||||
const TableRow: TableRowComponent = (props) => {
|
||||
return <STableRow {...props}/>
|
||||
};
|
||||
|
||||
const TableBase: React.FC<TableProps> = (props) => {
|
||||
const {i} = useContext(ThemeContext);
|
||||
return <STable {...i} {...props}/>
|
||||
};
|
||||
|
||||
export const Table: TableComponent = Object.assign(TableBase, {
|
||||
Body: TableBody,
|
||||
Cell: TableCell,
|
||||
Footer: TableFooter,
|
||||
Header: TableHeader,
|
||||
HeaderCell: TableHeaderCell,
|
||||
Row: TableRow,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,69 +1,10 @@
|
|||
import React from 'react';
|
||||
import {Container} from "semantic-ui-react";
|
||||
import {getStatus, saveSettings} from "../../api";
|
||||
import {PageContainer, TabLinks, Toggle} from "../Common";
|
||||
import {PageContainer, TabLinks} from "../Common";
|
||||
import {Route, Routes} from "react-router";
|
||||
import {ThemeContext} from "../../contexts/contexts";
|
||||
import {Header, Loader, Segment} from "../Theme";
|
||||
import {DownloadsPage} from "./Downloads";
|
||||
import {SettingsPage} from "./Settings";
|
||||
import {StatusPage} from "./Status";
|
||||
|
||||
class WROLMode extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
WROLMode: false,
|
||||
}
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
try {
|
||||
const {wrol_mode} = await getStatus();
|
||||
this.setState({ready: true, WROLMode: wrol_mode});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
toggleWROLMode = async (checked) => {
|
||||
// Handle WROL Mode toggling by itself so that other settings are not modified.
|
||||
let config = {
|
||||
wrol_mode: checked,
|
||||
}
|
||||
await saveSettings(config);
|
||||
this.setState({disabled: !this.state.WROLMode, WROLMode: checked});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.ready === false) {
|
||||
return <Loader active inline='centered'/>
|
||||
}
|
||||
|
||||
return <ThemeContext.Consumer>
|
||||
{({t}) => <Container fluid>
|
||||
|
||||
<Segment>
|
||||
<Header as="h1">WROL Mode</Header>
|
||||
<Header as='h4'>
|
||||
Enable read-only mode. No content can be deleted or modified. Enable this when the SHTF and you
|
||||
want to prevent any potential loss of data.
|
||||
</Header>
|
||||
<p {...t}>
|
||||
Note: User settings and tags can still be modified.
|
||||
</p>
|
||||
<Toggle
|
||||
checked={this.state.WROLMode}
|
||||
onChange={this.toggleWROLMode}
|
||||
label={this.state.WROLMode ? 'WROL Mode Enabled' : 'WROL Mode Disabled'}
|
||||
/>
|
||||
</Segment>
|
||||
|
||||
</Container>}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
}
|
||||
import {ControllerPage} from "./ControllerPage";
|
||||
|
||||
export default function AdminRoute() {
|
||||
|
||||
|
|
@ -71,7 +12,7 @@ export default function AdminRoute() {
|
|||
{text: 'Downloads', to: '/admin', key: 'admin', end: true},
|
||||
{text: 'Settings', to: '/admin/settings', key: 'settings'},
|
||||
{text: 'Status', to: '/admin/status', key: 'status'},
|
||||
{text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'},
|
||||
{text: 'Controller', to: '/admin/controller', key: 'controller'},
|
||||
];
|
||||
|
||||
return <PageContainer>
|
||||
|
|
@ -80,7 +21,7 @@ export default function AdminRoute() {
|
|||
<Route path='/' exact element={<DownloadsPage/>}/>
|
||||
<Route path='settings' exact element={<SettingsPage/>}/>
|
||||
<Route path='status' exact element={<StatusPage/>}/>
|
||||
<Route path='wrol' exact element={<WROLMode/>}/>
|
||||
<Route path='controller' exact element={<ControllerPage/>}/>
|
||||
</Routes>
|
||||
</PageContainer>
|
||||
}
|
||||
|
|
|
|||
609
app/src/components/admin/ControllerPage.js
Normal file
609
app/src/components/admin/ControllerPage.js
Normal file
|
|
@ -0,0 +1,609 @@
|
|||
import React from 'react';
|
||||
import {Container, Icon} from "semantic-ui-react";
|
||||
import {Button, Header, Loader, Modal, Segment, Table} from "../Theme";
|
||||
import {
|
||||
APIButton,
|
||||
HotspotToggle,
|
||||
ThrottleToggle,
|
||||
Toggle,
|
||||
} from "../Common";
|
||||
import {useDockerized} from "../../hooks/customHooks";
|
||||
import {
|
||||
getServices,
|
||||
startService,
|
||||
stopService,
|
||||
restartService,
|
||||
enableService,
|
||||
disableService,
|
||||
getServiceLogs,
|
||||
getDisks,
|
||||
getMounts,
|
||||
getSmartStatus,
|
||||
restartServices,
|
||||
} from "../../api/controller";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {RestartButton, ShutdownButton} from "./Settings";
|
||||
|
||||
|
||||
// Service status color mapping
|
||||
const statusColors = {
|
||||
running: 'green',
|
||||
stopped: 'red',
|
||||
failed: 'red',
|
||||
unknown: 'yellow',
|
||||
};
|
||||
|
||||
|
||||
function ServiceRow({service, onAction, dockerized}) {
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [logsOpen, setLogsOpen] = React.useState(false);
|
||||
const [logs, setLogs] = React.useState('');
|
||||
const [logsLoading, setLogsLoading] = React.useState(false);
|
||||
|
||||
const handleAction = async (action, actionFn) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await actionFn(service.name);
|
||||
toast({
|
||||
type: 'success',
|
||||
title: `${action} ${service.name}`,
|
||||
description: `Successfully ${action.toLowerCase()}ed ${service.name}`,
|
||||
time: 3000,
|
||||
});
|
||||
if (onAction) onAction();
|
||||
} catch (e) {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: `${action} Failed`,
|
||||
description: e.message,
|
||||
time: 5000,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewLogs = async () => {
|
||||
setLogsOpen(true);
|
||||
setLogsLoading(true);
|
||||
try {
|
||||
const result = await getServiceLogs(service.name, 100);
|
||||
setLogs(result.logs || 'No logs available');
|
||||
} catch (e) {
|
||||
setLogs(`Error fetching logs: ${e.message}`);
|
||||
} finally {
|
||||
setLogsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const isRunning = service.status === 'running';
|
||||
const isStopped = service.status === 'stopped';
|
||||
const statusColor = statusColors[service.status] || 'grey';
|
||||
|
||||
// Build view URL if service is viewable
|
||||
let viewUrl = null;
|
||||
if (service.viewable && service.port && isRunning) {
|
||||
const protocol = service.use_https ? 'https' : 'http';
|
||||
const host = window.location.hostname;
|
||||
const path = service.view_path || '';
|
||||
viewUrl = `${protocol}://${host}:${service.port}${path}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
<strong>{service.name}</strong>
|
||||
{service.description && <div style={{fontSize: '0.9em', color: '#888'}}>{service.description}</div>}
|
||||
</Table.Cell>
|
||||
<Table.Cell>{service.port || '-'}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon name='circle' color={statusColor}/>
|
||||
{service.status}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{isRunning ? (
|
||||
<Button
|
||||
size='small'
|
||||
icon='stop'
|
||||
color='red'
|
||||
disabled={loading}
|
||||
loading={loading}
|
||||
onClick={() => handleAction('Stop', stopService)}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
size='small'
|
||||
icon='play'
|
||||
color='green'
|
||||
disabled={loading}
|
||||
loading={loading}
|
||||
onClick={() => handleAction('Start', startService)}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
size='small'
|
||||
icon='refresh'
|
||||
color='yellow'
|
||||
disabled={loading}
|
||||
loading={loading}
|
||||
onClick={() => handleAction('Restart', restartService)}
|
||||
/>
|
||||
<Modal
|
||||
open={logsOpen}
|
||||
onClose={() => setLogsOpen(false)}
|
||||
onOpen={handleViewLogs}
|
||||
trigger={<Button size='small' icon='file text' content='Logs' color='blue'/>}
|
||||
size='fullscreen'
|
||||
>
|
||||
<Modal.Header>Logs: {service.name}</Modal.Header>
|
||||
<Modal.Content scrolling>
|
||||
{logsLoading ? (
|
||||
<Loader active inline='centered'/>
|
||||
) : (
|
||||
<pre style={{
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordWrap: 'break-word',
|
||||
maxHeight: '400px',
|
||||
overflow: 'auto',
|
||||
backgroundColor: '#1a1a1a',
|
||||
color: '#00ff00',
|
||||
padding: '1em',
|
||||
fontFamily: 'monospace',
|
||||
fontSize: '0.85em',
|
||||
}}>
|
||||
{logs}
|
||||
</pre>
|
||||
)}
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={() => setLogsOpen(false)}>Close</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
{viewUrl && (
|
||||
<Button
|
||||
size='small'
|
||||
icon='external'
|
||||
content='View'
|
||||
as='a'
|
||||
href={viewUrl}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
color='violet'
|
||||
/>
|
||||
)}
|
||||
</Table.Cell>
|
||||
{!dockerized && (
|
||||
<Table.Cell>
|
||||
<Toggle
|
||||
checked={service.enabled === true}
|
||||
disabled={service.enabled === null || loading}
|
||||
onChange={async (checked) => {
|
||||
if (checked) {
|
||||
await handleAction('Enable', enableService);
|
||||
} else {
|
||||
await handleAction('Disable', disableService);
|
||||
}
|
||||
}}
|
||||
label={service.enabled ? 'Enabled' : 'Disabled'}
|
||||
/>
|
||||
</Table.Cell>
|
||||
)}
|
||||
</Table.Row>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function ServicesSection() {
|
||||
const [services, setServices] = React.useState([]);
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState(null);
|
||||
const [restarting, setRestarting] = React.useState(false);
|
||||
const dockerized = useDockerized();
|
||||
|
||||
const handleRestartServices = async () => {
|
||||
setRestarting(true);
|
||||
try {
|
||||
await restartServices();
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Services Restarting',
|
||||
description: 'All WROLPi services are being restarted.',
|
||||
time: 5000,
|
||||
});
|
||||
// Refresh service list after restart initiated
|
||||
fetchServices();
|
||||
} catch (e) {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Restart Failed',
|
||||
description: e.message,
|
||||
time: 5000,
|
||||
});
|
||||
} finally {
|
||||
setRestarting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchServices = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await getServices();
|
||||
setServices(Array.isArray(result) ? result : []);
|
||||
} catch (e) {
|
||||
setError(e.message);
|
||||
setServices([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchServices();
|
||||
// Refresh every 10 seconds
|
||||
const interval = setInterval(fetchServices, 10000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
if (loading && services.length === 0) {
|
||||
return <Segment>
|
||||
<Header as='h3'>Services</Header>
|
||||
<Loader active inline='centered'/>
|
||||
</Segment>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <Segment>
|
||||
<Header as='h3'>Services</Header>
|
||||
<p style={{color: 'red'}}>Error loading services: {error}</p>
|
||||
<Button onClick={fetchServices}>Retry</Button>
|
||||
</Segment>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Segment>
|
||||
<Header as='h3'>
|
||||
<Icon name='server'/>
|
||||
Services
|
||||
</Header>
|
||||
<Table unstackable striped>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Service</Table.HeaderCell>
|
||||
<Table.HeaderCell>Port</Table.HeaderCell>
|
||||
<Table.HeaderCell>Status</Table.HeaderCell>
|
||||
<Table.HeaderCell>Actions</Table.HeaderCell>
|
||||
{!dockerized && <Table.HeaderCell>Boot</Table.HeaderCell>}
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{services.map(service => (
|
||||
<ServiceRow
|
||||
dockerized={dockerized}
|
||||
key={service.name}
|
||||
service={service}
|
||||
onAction={fetchServices}
|
||||
/>
|
||||
))}
|
||||
</Table.Body>
|
||||
<Table.Footer>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell colSpan={dockerized ? 4 : 5}>
|
||||
<APIButton
|
||||
color='yellow'
|
||||
onClick={handleRestartServices}
|
||||
confirmContent='Are you sure you want to restart all WROLPi services?'
|
||||
confirmButton='Restart Services'
|
||||
disabled={restarting}
|
||||
>
|
||||
<Icon name='refresh'/>
|
||||
{restarting ? 'Restarting...' : 'Restart All Services'}
|
||||
</APIButton>
|
||||
</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Footer>
|
||||
</Table>
|
||||
{services.length === 0 && (
|
||||
<p>No services found. Services may not be available in this environment.</p>
|
||||
)}
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Helper to get health status color from SMART assessment
|
||||
const getHealthColor = (assessment) => {
|
||||
if (!assessment) return 'grey';
|
||||
const upper = assessment.toUpperCase();
|
||||
if (upper === 'PASS') return 'green';
|
||||
if (upper === 'WARN') return 'yellow';
|
||||
if (upper === 'FAIL') return 'red';
|
||||
return 'grey';
|
||||
};
|
||||
|
||||
// Helper to format power-on hours
|
||||
const formatPowerOnHours = (hours) => {
|
||||
if (hours === null || hours === undefined) return '-';
|
||||
const days = Math.floor(hours / 24);
|
||||
const years = Math.floor(days / 365);
|
||||
if (years > 0) return `${hours.toLocaleString()} hrs (${years}y ${days % 365}d)`;
|
||||
if (days > 0) return `${hours.toLocaleString()} hrs (${days}d)`;
|
||||
return `${hours} hrs`;
|
||||
};
|
||||
|
||||
|
||||
function SmartDetailsModal({drive, open, onClose}) {
|
||||
if (!drive) return null;
|
||||
|
||||
const healthColor = getHealthColor(drive.assessment);
|
||||
|
||||
return (
|
||||
<Modal open={open} onClose={onClose} size='small'>
|
||||
<Modal.Header>
|
||||
<Icon name='heartbeat'/>
|
||||
SMART Details: {drive.device}
|
||||
</Modal.Header>
|
||||
<Modal.Content>
|
||||
<Table definition unstackable>
|
||||
<Table.Body>
|
||||
<Table.Row>
|
||||
<Table.Cell width={6}>Model</Table.Cell>
|
||||
<Table.Cell>{drive.model || '-'}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Serial</Table.Cell>
|
||||
<Table.Cell>{drive.serial || '-'}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Capacity</Table.Cell>
|
||||
<Table.Cell>{drive.capacity || '-'}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Assessment</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon name='circle' color={healthColor}/>
|
||||
{drive.assessment || 'Unknown'}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Temperature</Table.Cell>
|
||||
<Table.Cell>
|
||||
{drive.temperature !== null && drive.temperature !== undefined
|
||||
? `${drive.temperature}°C`
|
||||
: '-'}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Power-On Hours</Table.Cell>
|
||||
<Table.Cell>{formatPowerOnHours(drive.power_on_hours)}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Reallocated Sectors</Table.Cell>
|
||||
<Table.Cell style={{color: drive.reallocated_sectors > 0 ? 'orange' : 'inherit'}}>
|
||||
{drive.reallocated_sectors !== null && drive.reallocated_sectors !== undefined
|
||||
? drive.reallocated_sectors
|
||||
: '-'}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Pending Sectors</Table.Cell>
|
||||
<Table.Cell style={{color: drive.pending_sectors > 0 ? 'orange' : 'inherit'}}>
|
||||
{drive.pending_sectors !== null && drive.pending_sectors !== undefined
|
||||
? drive.pending_sectors
|
||||
: '-'}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>SMART Enabled</Table.Cell>
|
||||
<Table.Cell>{drive.smart_enabled ? 'Yes' : 'No'}</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={onClose}>Close</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function DiskSection() {
|
||||
const [disks, setDisks] = React.useState([]);
|
||||
const [mounts, setMounts] = React.useState([]);
|
||||
const [smartDrives, setSmartDrives] = React.useState([]);
|
||||
const [smartAvailable, setSmartAvailable] = React.useState(true);
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState(null);
|
||||
const [selectedDrive, setSelectedDrive] = React.useState(null);
|
||||
const [detailsOpen, setDetailsOpen] = React.useState(false);
|
||||
const dockerized = useDockerized();
|
||||
|
||||
const fetchDiskInfo = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const [disksResult, mountsResult, smartResult] = await Promise.allSettled([
|
||||
getDisks(),
|
||||
getMounts(),
|
||||
getSmartStatus(),
|
||||
]);
|
||||
|
||||
if (disksResult.status === 'fulfilled') {
|
||||
setDisks(Array.isArray(disksResult.value) ? disksResult.value : []);
|
||||
}
|
||||
if (mountsResult.status === 'fulfilled') {
|
||||
setMounts(Array.isArray(mountsResult.value) ? mountsResult.value : []);
|
||||
}
|
||||
if (smartResult.status === 'fulfilled' && smartResult.value) {
|
||||
// Handle new API format: {available: bool, drives: [...]}
|
||||
const smartData = smartResult.value;
|
||||
setSmartAvailable(smartData.available !== false);
|
||||
setSmartDrives(Array.isArray(smartData.drives) ? smartData.drives : []);
|
||||
} else {
|
||||
setSmartAvailable(false);
|
||||
setSmartDrives([]);
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleShowDetails = (drive) => {
|
||||
setSelectedDrive(drive);
|
||||
setDetailsOpen(true);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchDiskInfo();
|
||||
}, []);
|
||||
|
||||
if (dockerized) {
|
||||
return (
|
||||
<Segment>
|
||||
<Header as='h3'>
|
||||
<Icon name='disk'/>
|
||||
Disk Management
|
||||
</Header>
|
||||
<p>Disk management is not available in Docker environments.</p>
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Segment>
|
||||
<Header as='h3'>Disk Management</Header>
|
||||
<Loader active inline='centered'/>
|
||||
</Segment>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Segment>
|
||||
<Header as='h3'>
|
||||
<Icon name='disk'/>
|
||||
Disk Management
|
||||
</Header>
|
||||
|
||||
{error && <p style={{color: 'orange'}}>Some disk information unavailable: {error}</p>}
|
||||
|
||||
<Header as='h4'>Current Mounts</Header>
|
||||
{mounts.length > 0 ? (
|
||||
<Table unstackable striped compact>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Device</Table.HeaderCell>
|
||||
<Table.HeaderCell>Mount Point</Table.HeaderCell>
|
||||
<Table.HeaderCell>Filesystem</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{mounts.map((mount, idx) => (
|
||||
<Table.Row key={idx}>
|
||||
<Table.Cell>{mount.device}</Table.Cell>
|
||||
<Table.Cell>{mount.mount_point}</Table.Cell>
|
||||
<Table.Cell>{mount.fstype}</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
) : (
|
||||
<p>No mounts found.</p>
|
||||
)}
|
||||
|
||||
<Header as='h4'>SMART Health</Header>
|
||||
{!smartAvailable ? (
|
||||
<p style={{color: '#888'}}>SMART monitoring not available (pySMART not installed or not supported)</p>
|
||||
) : smartDrives.length > 0 ? (
|
||||
<Table unstackable striped compact>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Device</Table.HeaderCell>
|
||||
<Table.HeaderCell>Health</Table.HeaderCell>
|
||||
<Table.HeaderCell>Temperature</Table.HeaderCell>
|
||||
<Table.HeaderCell>Actions</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{smartDrives.map((drive) => (
|
||||
<Table.Row key={drive.device}>
|
||||
<Table.Cell>{drive.device}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon
|
||||
name='circle'
|
||||
color={getHealthColor(drive.assessment)}
|
||||
/>
|
||||
{drive.assessment || 'Unknown'}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{drive.temperature !== null && drive.temperature !== undefined
|
||||
? `${drive.temperature}°C`
|
||||
: '-'}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Button
|
||||
size='small'
|
||||
icon='info'
|
||||
content='Details'
|
||||
onClick={() => handleShowDetails(drive)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
) : (
|
||||
<p>No SMART-capable drives detected.</p>
|
||||
)}
|
||||
|
||||
<SmartDetailsModal
|
||||
drive={selectedDrive}
|
||||
open={detailsOpen}
|
||||
onClose={() => setDetailsOpen(false)}
|
||||
/>
|
||||
|
||||
<Button onClick={fetchDiskInfo} style={{marginTop: '1em'}}>
|
||||
<Icon name='refresh'/>
|
||||
Refresh
|
||||
</Button>
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function AdminControlsSection() {
|
||||
const dockerized = useDockerized();
|
||||
|
||||
return (
|
||||
<Segment>
|
||||
<Header as='h3'>
|
||||
<Icon name='settings'/>
|
||||
Hardware Controls
|
||||
</Header>
|
||||
|
||||
<HotspotToggle/>
|
||||
<ThrottleToggle/>
|
||||
|
||||
{!dockerized && (
|
||||
<div style={{marginTop: '1em'}}>
|
||||
<RestartButton/>
|
||||
<ShutdownButton/>
|
||||
</div>
|
||||
)}
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function ControllerPage() {
|
||||
return (
|
||||
<Container fluid>
|
||||
<AdminControlsSection/>
|
||||
<ServicesSection/>
|
||||
<DiskSection/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
export default ControllerPage;
|
||||
169
app/src/components/admin/ControllerPage.test.js
Normal file
169
app/src/components/admin/ControllerPage.test.js
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
import React from 'react';
|
||||
import {render, screen, waitFor} from '@testing-library/react';
|
||||
import {BrowserRouter} from 'react-router';
|
||||
import {ThemeContext, SettingsContext} from '../../contexts/contexts';
|
||||
import {ControllerPage} from './ControllerPage';
|
||||
|
||||
// Mock the controller API
|
||||
jest.mock('../../api/controller', () => ({
|
||||
getServices: jest.fn().mockResolvedValue([
|
||||
{
|
||||
name: 'wrolpi-api',
|
||||
port: 8081,
|
||||
status: 'running',
|
||||
viewable: true,
|
||||
view_path: '/docs',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: 'wrolpi-app',
|
||||
port: 3000,
|
||||
status: 'running',
|
||||
viewable: true,
|
||||
view_path: '',
|
||||
enabled: true,
|
||||
},
|
||||
]),
|
||||
startService: jest.fn().mockResolvedValue({success: true}),
|
||||
stopService: jest.fn().mockResolvedValue({success: true}),
|
||||
restartService: jest.fn().mockResolvedValue({success: true}),
|
||||
enableService: jest.fn().mockResolvedValue({success: true}),
|
||||
disableService: jest.fn().mockResolvedValue({success: true}),
|
||||
getServiceLogs: jest.fn().mockResolvedValue({logs: 'Sample log output'}),
|
||||
getDisks: jest.fn().mockResolvedValue([]),
|
||||
getMounts: jest.fn().mockResolvedValue([]),
|
||||
getSmartStatus: jest.fn().mockResolvedValue({}),
|
||||
restartServices: jest.fn().mockResolvedValue({success: true}),
|
||||
}));
|
||||
|
||||
|
||||
// Mock useDockerized hook
|
||||
jest.mock('../../hooks/customHooks', () => ({
|
||||
useDockerized: jest.fn().mockReturnValue(false),
|
||||
useHotspot: jest.fn().mockReturnValue({on: true, setHotspot: jest.fn()}),
|
||||
useThrottle: jest.fn().mockReturnValue({on: false, setThrottle: jest.fn()}),
|
||||
}));
|
||||
|
||||
// Mock Common.js components that have complex dependencies
|
||||
jest.mock('../Common', () => {
|
||||
const actual = jest.requireActual('../Common');
|
||||
return {
|
||||
...actual,
|
||||
HotspotToggle: () => <div data-testid="hotspot-toggle">HotspotToggle</div>,
|
||||
ThrottleToggle: () => <div data-testid="throttle-toggle">ThrottleToggle</div>,
|
||||
Toggle: ({label, checked, onChange}) => (
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked || false}
|
||||
onChange={e => onChange && onChange(e.target.checked)}
|
||||
/>
|
||||
{label}
|
||||
</label>
|
||||
),
|
||||
APIButton: ({children, onClick, disabled}) => (
|
||||
<button onClick={onClick} disabled={disabled}>{children}</button>
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
// Mock Settings.js components
|
||||
jest.mock('./Settings', () => ({
|
||||
RestartButton: () => <button data-testid="restart-button">Restart</button>,
|
||||
ShutdownButton: () => <button data-testid="shutdown-button">Shutdown</button>,
|
||||
}));
|
||||
|
||||
const defaultTheme = {
|
||||
t: {style: {}},
|
||||
inverted: false,
|
||||
};
|
||||
|
||||
const defaultSettings = {
|
||||
settings: {},
|
||||
saveSettings: jest.fn(),
|
||||
fetchSettings: jest.fn(),
|
||||
};
|
||||
|
||||
const renderControllerPage = () => {
|
||||
return render(
|
||||
<BrowserRouter>
|
||||
<ThemeContext.Provider value={defaultTheme}>
|
||||
<SettingsContext.Provider value={defaultSettings}>
|
||||
<ControllerPage/>
|
||||
</SettingsContext.Provider>
|
||||
</ThemeContext.Provider>
|
||||
</BrowserRouter>
|
||||
);
|
||||
};
|
||||
|
||||
describe('ControllerPage', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Reset useDockerized to false for regular tests
|
||||
const {useDockerized} = require('../../hooks/customHooks');
|
||||
useDockerized.mockReturnValue(false);
|
||||
});
|
||||
|
||||
test('renders Services section', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Services')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test('renders Disk Management section', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Disk Management')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test('renders Hardware Controls section', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Hardware Controls')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test('calls getServices on mount', async () => {
|
||||
const {getServices} = require('../../api/controller');
|
||||
renderControllerPage();
|
||||
// Verify getServices was called
|
||||
await waitFor(() => {
|
||||
expect(getServices).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
test('shows Restart and Shutdown buttons in non-Docker mode', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('restart-button')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('shutdown-button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ControllerPage in Docker mode', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
const {useDockerized} = require('../../hooks/customHooks');
|
||||
useDockerized.mockReturnValue(true);
|
||||
});
|
||||
|
||||
test('hides reboot/shutdown buttons in Docker mode', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Hardware Controls')).toBeInTheDocument();
|
||||
});
|
||||
// Shutdown and Restart buttons should not be visible
|
||||
expect(screen.queryByTestId('shutdown-button')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('restart-button')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('shows disk management unavailable message in Docker mode', async () => {
|
||||
renderControllerPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Disk management is not available in Docker environments.')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import {SettingsContext, StatusContext} from "../../contexts/contexts";
|
||||
import {checkUpgrade, postRestart, postShutdown, triggerUpgrade} from "../../api";
|
||||
import {checkUpgrade, postRestart, postShutdown, saveSettings as saveSettingsApi, triggerUpgrade} from "../../api";
|
||||
import {
|
||||
Button,
|
||||
Divider,
|
||||
|
|
@ -14,10 +14,8 @@ import {ButtonGroup, Container, Dimmer, Dropdown, GridColumn, GridRow, Icon, Inp
|
|||
import {
|
||||
APIButton,
|
||||
ErrorMessage,
|
||||
HotspotToggle,
|
||||
InfoPopup,
|
||||
RefreshHeader,
|
||||
ThrottleToggle,
|
||||
Toggle,
|
||||
useMessageDismissal,
|
||||
WROLModeMessage
|
||||
|
|
@ -107,8 +105,8 @@ function UpgradeSegment() {
|
|||
try {
|
||||
const response = await triggerUpgrade();
|
||||
if (response.ok) {
|
||||
// Redirect to maintenance page
|
||||
window.location.href = '/maintenance.html';
|
||||
// Redirect to Controller UI for upgrade status
|
||||
window.location.href = '/controller/?upgrade=true';
|
||||
}
|
||||
} catch (e) {
|
||||
setUpgrading(false);
|
||||
|
|
@ -250,6 +248,47 @@ function toApiLogLevel(logLevel) {
|
|||
}[logLevel]
|
||||
}
|
||||
|
||||
function WROLModeSection() {
|
||||
const {settings, fetchSettings} = React.useContext(SettingsContext);
|
||||
const wrolMode = settings?.wrol_mode || false;
|
||||
|
||||
const toggleWROLMode = async (checked) => {
|
||||
try {
|
||||
await saveSettingsApi({wrol_mode: checked});
|
||||
await fetchSettings(); // Refresh context immediately
|
||||
} catch (e) {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Failed to toggle WROL Mode',
|
||||
description: e.message,
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Segment>
|
||||
<Header as='h3'>
|
||||
<Icon name='shield'/>
|
||||
WROL Mode
|
||||
</Header>
|
||||
<p>
|
||||
Enable read-only mode. No content can be deleted or modified.
|
||||
Enable this when the SHTF and you want to prevent any potential loss of data.
|
||||
</p>
|
||||
<p style={{fontSize: '0.9em', color: '#888'}}>
|
||||
Note: User settings and tags can still be modified.
|
||||
</p>
|
||||
<Toggle
|
||||
checked={wrolMode}
|
||||
onChange={toggleWROLMode}
|
||||
label={wrolMode ? 'WROL Mode Enabled' : 'WROL Mode Disabled'}
|
||||
/>
|
||||
</Segment>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function SettingsPage() {
|
||||
const [disabled, setDisabled] = React.useState(false);
|
||||
const [editSpecialDirectories, setEditSpecialDirectories] = React.useState(false);
|
||||
|
|
@ -579,15 +618,6 @@ export function SettingsPage() {
|
|||
body = <ErrorMessage>Unable to fetch settings</ErrorMessage>
|
||||
}
|
||||
|
||||
const controlSegment = <Segment>
|
||||
<Header as='h3'>Control WROLPi</Header>
|
||||
<HotspotToggle/>
|
||||
<ThrottleToggle/>
|
||||
|
||||
<RestartButton/>
|
||||
<ShutdownButton/>
|
||||
</Segment>;
|
||||
|
||||
const configsSegment = <Segment>
|
||||
<RefreshHeader
|
||||
header='Configs'
|
||||
|
|
@ -610,8 +640,6 @@ export function SettingsPage() {
|
|||
return <Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
||||
{controlSegment}
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>Settings</Header>
|
||||
{body}
|
||||
|
|
@ -621,6 +649,8 @@ export function SettingsPage() {
|
|||
|
||||
<UpgradeSegment/>
|
||||
|
||||
<WROLModeSection/>
|
||||
|
||||
<Segment>
|
||||
<Header as='h1'>Browser Settings</Header>
|
||||
<APIButton onClick={clearAll}>Show All Hints</APIButton>
|
||||
|
|
|
|||
|
|
@ -30,11 +30,16 @@ import {
|
|||
searchDirectories,
|
||||
searchVideos,
|
||||
searchZim,
|
||||
setHotspot,
|
||||
setThrottle,
|
||||
updateChannel,
|
||||
updateDomain,
|
||||
} from "../api";
|
||||
import {
|
||||
enableHotspot,
|
||||
disableHotspot,
|
||||
enableThrottle,
|
||||
disableThrottle,
|
||||
getControllerStats,
|
||||
} from "../api/controller";
|
||||
import {createSearchParams, useLocation, useSearchParams} from "react-router";
|
||||
import {enumerate, filterToMimetypes, humanFileSize, secondsToFullDuration} from "../components/Common";
|
||||
import {QueryContext, SettingsContext, StatusContext} from "../contexts/contexts";
|
||||
|
|
@ -790,9 +795,23 @@ export const useHotspot = () => {
|
|||
}
|
||||
}, [status]);
|
||||
|
||||
const localSetHotspot = async (on) => {
|
||||
const localSetHotspot = async (enable) => {
|
||||
setOn(null);
|
||||
await setHotspot(on);
|
||||
try {
|
||||
if (enable) {
|
||||
await enableHotspot();
|
||||
} else {
|
||||
await disableHotspot();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Hotspot error:', e);
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Hotspot Error',
|
||||
description: e.message || 'Could not modify hotspot. See server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {on, inUse, hotspotSsid: hotspot_ssid, setOn, setHotspot: localSetHotspot, dockerized};
|
||||
|
|
@ -866,23 +885,38 @@ export const useConfigs = () => {
|
|||
|
||||
export const useThrottle = () => {
|
||||
const [on, setOn] = useState(null);
|
||||
const {settings, fetchSettings} = React.useContext(SettingsContext);
|
||||
const {status, fetchStatus} = React.useContext(StatusContext);
|
||||
|
||||
useEffect(() => {
|
||||
const status = settings['throttle_status'];
|
||||
if (status === 'powersave') {
|
||||
const throttleStatus = status?.throttle_status;
|
||||
if (throttleStatus === 'powersave') {
|
||||
setOn(true);
|
||||
} else if (status === 'ondemand') {
|
||||
} else if (throttleStatus === 'ondemand') {
|
||||
setOn(false);
|
||||
} else {
|
||||
setOn(null);
|
||||
}
|
||||
}, [JSON.stringify(settings)]);
|
||||
}, [status?.throttle_status]);
|
||||
|
||||
const localSetThrottle = async (on) => {
|
||||
const localSetThrottle = async (enable) => {
|
||||
setOn(null);
|
||||
await setThrottle(on);
|
||||
await fetchSettings();
|
||||
try {
|
||||
if (enable) {
|
||||
await enableThrottle();
|
||||
} else {
|
||||
await disableThrottle();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Throttle error:', e);
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Throttle Error',
|
||||
description: e.message || 'Could not modify throttle. See server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
// Refetch status to get updated throttle state
|
||||
await fetchStatus();
|
||||
}
|
||||
|
||||
return {on, setOn, setThrottle: localSetThrottle};
|
||||
|
|
@ -973,7 +1007,24 @@ export const useStatus = () => {
|
|||
|
||||
const fetchStatus = async () => {
|
||||
try {
|
||||
setStatus(await getStatus());
|
||||
// Fetch from both endpoints in parallel
|
||||
const [appStatus, controllerStats] = await Promise.all([
|
||||
getStatus().catch(e => {
|
||||
if (e instanceof ApiDownError) {
|
||||
window.apiDown = true;
|
||||
return {};
|
||||
}
|
||||
throw e;
|
||||
}),
|
||||
getControllerStats().catch(e => {
|
||||
// Controller may be down, continue with app status only
|
||||
console.debug('Controller stats unavailable:', e.message);
|
||||
return {};
|
||||
}),
|
||||
]);
|
||||
|
||||
// Merge both responses - controller stats override app status for system info
|
||||
setStatus({...appStatus, ...controllerStats});
|
||||
window.apiDown = false;
|
||||
} catch (e) {
|
||||
if (e instanceof ApiDownError) {
|
||||
|
|
@ -1484,8 +1535,8 @@ export const useVINDecoder = (defaultVINNumber = '') => {
|
|||
|
||||
export const useWROLMode = () => {
|
||||
// Returns the current boolean WROL Mode, during fetch this returns null.
|
||||
const {status} = useContext(StatusContext);
|
||||
return status ? status.wrol_mode : null;
|
||||
const {settings} = useContext(SettingsContext);
|
||||
return settings ? settings.wrol_mode : null;
|
||||
}
|
||||
|
||||
export const useDockerized = () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue