Fix RPC customization settings

- Added logic to disable timestamp if not "listening to". - Added a
warning message if timestamp is unavailable.
This commit is contained in:
kmmiio99o 2025-11-16 17:10:12 +01:00
commit e3bbf71888

View file

@ -6,6 +6,7 @@ import {
Stack, Stack,
TableRowGroup, TableRowGroup,
TableSwitchRow, TableSwitchRow,
TableRow,
} from "./components/TableComponents"; } from "./components/TableComponents";
import { plugin } from "@vendetta"; import { plugin } from "@vendetta";
import Constants from "../../../constants"; import Constants from "../../../constants";
@ -16,6 +17,35 @@ export default function RPCCustomizationSettingsPage() {
useProxy(plugin.storage); useProxy(plugin.storage);
const [, forceUpdate] = React.useReducer((x) => x + 1, 0); const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
const isListeningTo = getStorage(
"listeningTo",
Constants.DEFAULT_SETTINGS.listeningTo,
);
const showTimestamp = getStorage(
"showTimestamp",
Constants.DEFAULT_SETTINGS.showTimestamp,
);
const handleListeningToChange = (value: boolean) => {
setStorage("listeningTo", value);
// If turning off "Show as Listening", also turn off "Show Timestamp"
if (!value && showTimestamp) {
setStorage("showTimestamp", false);
}
forceUpdate();
};
const handleTimestampChange = (value: boolean) => {
// Only allow turning on timestamp if "Show as Listening" is enabled
if (value && !isListeningTo) {
return;
}
setStorage("showTimestamp", value);
forceUpdate();
};
return ( return (
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 10 }}> <ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 10 }}>
<RPCPreview /> <RPCPreview />
@ -24,14 +54,8 @@ export default function RPCCustomizationSettingsPage() {
<TableSwitchRow <TableSwitchRow
label="Show as Listening" label="Show as Listening"
subLabel="Display as 'Listening to' instead of 'Playing'" subLabel="Display as 'Listening to' instead of 'Playing'"
value={getStorage( value={isListeningTo}
"listeningTo", onValueChange={handleListeningToChange}
Constants.DEFAULT_SETTINGS.listeningTo,
)}
onValueChange={(value: boolean) => {
setStorage("listeningTo", value);
forceUpdate();
}}
/> />
<TableSwitchRow <TableSwitchRow
label="Show Tooltip Text" label="Show Tooltip Text"
@ -42,18 +66,26 @@ export default function RPCCustomizationSettingsPage() {
forceUpdate(); forceUpdate();
}} }}
/> />
{/* Warning row when timestamp is disabled */}
{!isListeningTo && (
<TableRow
label="Timestamp Unavailable"
subLabel="Enable 'Show as Listening' to use timestamp feature"
disabled={true}
dimmed={true}
/>
)}
<TableSwitchRow <TableSwitchRow
label="Show Timestamp" label="Show Timestamp"
subLabel="Display track progress and duration" subLabel="Display track progress and duration"
value={getStorage( value={showTimestamp}
"showTimestamp", onValueChange={handleTimestampChange}
Constants.DEFAULT_SETTINGS.showTimestamp, disabled={!isListeningTo}
)} dimmed={!isListeningTo}
onValueChange={(value: boolean) => {
setStorage("showTimestamp", value);
forceUpdate();
}}
/> />
<TableSwitchRow <TableSwitchRow
label="Show Album in Tooltip" label="Show Album in Tooltip"
subLabel="Include album name in the tooltip text" subLabel="Include album name in the tooltip text"