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.
Note: User settings and tags can still be modified.
);
}
export function SettingsPage() {
const [disabled, setDisabled] = React.useState(false);
const [editSpecialDirectories, setEditSpecialDirectories] = React.useState(false);
const [qrCodeValue, setQrCodeValue] = React.useState('');
const [qrOpen, setQrOpen] = React.useState(false);
const [ready, setReady] = React.useState(false);
const [pendingSave, setPendingSave] = React.useState(false);
const {clearAll} = useMessageDismissal();
const dockerized = useDockerized();
// Trace level modal state
const [traceModalOpen, setTraceModalOpen] = React.useState(false);
const [traceCountdown, setTraceCountdown] = React.useState(5);
const [traceSwitching, setTraceSwitching] = React.useState(false);
const [isDevMode, setIsDevMode] = React.useState(false);
// Get current settings from the API.
const {settings, saveSettings, fetchSettings} = React.useContext(SettingsContext);
// Used to track changes to the settings form between saves/loads.
const [state, setState] = React.useState({});
const {configs, loading, importConfig, saveConfig, fetchConfigs} = useConfigs();
React.useEffect(() => {
fetchConfigs();
}, []);
// Check if we're running in dev mode (wrolpi-api-dev service)
React.useEffect(() => {
if (!dockerized) {
const checkDevMode = async () => {
try {
const services = await getServices();
const apiDevService = services.find(s => s.name === 'wrolpi-api-dev');
setIsDevMode(apiDevService?.status === 'running');
} catch (e) {
console.error('Failed to check dev mode status:', e);
}
};
checkDevMode();
}
}, [dockerized]);
const localFetchSettings = async () => {
console.debug('fetching settings...');
try {
await fetchSettings();
console.debug('successfully fetched settings');
} catch (e) {
console.error('failed to fetch settings!');
throw e;
}
}
const localSaveSettings = async (newSettings) => {
// Check if trace level is selected (5 = trace in frontend)
const isTraceLevel = newSettings.log_level === 5;
// In native mode, if trace is selected and not already in dev mode, show confirmation modal
if (isTraceLevel && !dockerized && !isDevMode) {
setTraceModalOpen(true);
return;
}
// Otherwise, save normally
await doSaveSettings(newSettings);
}
const doSaveSettings = async (newSettings) => {
setDisabled(true);
setPendingSave(true);
newSettings.download_timeout = parseInt(newSettings.download_timeout);
newSettings.download_wait = parseInt(newSettings.download_wait);
newSettings.log_level = toApiLogLevel(newSettings.log_level);
try {
await saveSettings(newSettings);
await localFetchSettings();
} finally {
setDisabled(false);
setPendingSave(false);
}
}
const handleTraceModalConfirm = async () => {
setTraceSwitching(true);
setTraceCountdown(5);
// Start countdown
const countdownInterval = setInterval(() => {
setTraceCountdown(prev => {
if (prev <= 1) {
clearInterval(countdownInterval);
return 0;
}
return prev - 1;
});
}, 1000);
// Wait for countdown
await new Promise(resolve => setTimeout(resolve, 5000));
try {
// Save settings first
await doSaveSettings({...state});
// Switch to dev mode: stop wrolpi-api, start wrolpi-api-dev
toast({
type: 'info',
title: 'Switching to Debug Mode',
description: 'Stopping production API and starting debug API...',
time: 3000,
});
await stopService('wrolpi-api');
await startService('wrolpi-api-dev');
toast({
type: 'success',
title: 'Debug Mode Enabled',
description: 'API is now running in debug mode with trace logging enabled.',
time: 5000,
});
setIsDevMode(true);
} catch (e) {
console.error('Failed to switch to dev mode:', e);
toast({
type: 'error',
title: 'Service Switch Failed',
description: `Failed to switch API services: ${e.message}. You may need to manually restart services.`,
time: 10000,
});
} finally {
setTraceSwitching(false);
setTraceModalOpen(false);
setTraceCountdown(5);
}
}
const handleTraceModalCancel = () => {
// Reset log level to previous value and close modal
setState({...state, log_level: fromApiLogLevel(settings.log_level)});
setTraceModalOpen(false);
}
const handleHotspotChange = async () => {
let {hotspot_ssid, hotspot_encryption, hotspot_password} = state;
// Special string which allows a mobile device to connect to a specific Wi-Fi.
setQrCodeValue(`WIFI:S:${hotspot_ssid};T:${hotspot_encryption};P:${hotspot_password};;`);
}
React.useEffect(() => {
console.debug('settings changed, replacing state...');
setReady(settings ? true : undefined);
setState({
// Only these settings can be changed on the SettingsPage.
archive_destination: settings.archive_destination,
download_on_startup: settings.download_on_startup,
download_timeout: settings.download_timeout,
download_wait: settings.download_wait,
hotspot_device: settings.hotspot_device,
hotspot_on_startup: settings.hotspot_on_startup,
hotspot_password: settings.hotspot_password,
hotspot_ssid: settings.hotspot_ssid,
check_for_upgrades: settings.check_for_upgrades,
ignore_outdated_zims: settings.ignore_outdated_zims,
log_level: fromApiLogLevel(settings.log_level),
map_destination: settings.map_destination,
nav_color: settings.nav_color,
media_directory: settings.media_directory,
tags_directory: settings.tags_directory,
throttle_on_startup: settings.throttle_on_startup,
videos_destination: settings.videos_destination,
zims_destination: settings.zims_destination,
save_ffprobe_json: settings.save_ffprobe_json,
});
}, [JSON.stringify(settings)]);
React.useEffect(() => {
handleHotspotChange();
}, [state.hotspot_ssid, state.hotspot_password, state.hotspot_device]);
const handleInputChange = async (e, name, value) => {
if (e) {
e.preventDefault()
}
setState({...state, [name]: value});
}
const handleTimeoutChange = async (e, name, value) => {
if (e) {
e.preventDefault()
}
// Restrict timeout to numbers.
value = value.replace(/[^\d]/, '');
setState({...state, [name]: value});
}
const handleQrOpen = async (e) => {
e.preventDefault();
setQrOpen(true);
}
const qrButton = ;
const navColorOptions = Object.keys(semanticUIColorMap).map(i => {
return {key: i, value: i, text: i.charAt(0).toUpperCase() + i.slice(1)}
});
const mediaDirectoryLabel = `${settings.media_directory}/`;
let body;
if (ready === true) {
// Settings have been fetched, display form.
body = <>
Any changes will be written to {settings.media_directory}/config/wrolpi.yaml.
>
} else if (ready === false) {
body =
} else {
body = Unable to fetch settings
}
const configsSegment =
These configs control this WROLPi; they are the source of truth. Any changes to configs will be applied to
the database when imported (typically at startup).
Root CA Certificate
Install the WROLPi Root CA certificate on your devices to trust all HTTPS connections to this WROLPi.
You only need to do this once per device.
;
return Settings
{body}
{configsSegment}
Browser SettingsShow All Hints
{/* Trace Level Modal - shown when user selects trace level in native mode */}
!traceSwitching && handleTraceModalCancel()}
size='small'
>
Enable Debug Mode for Trace Logging
{traceSwitching ? (
<>
{traceCountdown > 0
? `Switching to debug mode in ${traceCountdown} seconds...`
: 'Switching API services...'}
The API will restart. This page may temporarily lose connection.
>
) : (
<>
Trace logging requires running the API in debug mode, which has slightly reduced
performance (2 workers instead of 5).
This will save your settings and restart the API service. The page may temporarily
lose connection during the switch.
You can switch back to production mode later from the Controller page.