Skip to content
23 changes: 20 additions & 3 deletions apps/web/src/components/PageComponents/ModuleConfig/RangeTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ const EMPTY_MODULES_SIGNAL = {
rangeTest?: Protobuf.ModuleConfig.ModuleConfig_RangeTestConfig;
},
peek: () =>
({}) as { rangeTest?: Protobuf.ModuleConfig.ModuleConfig_RangeTestConfig },
({}) as {
rangeTest?: Protobuf.ModuleConfig.ModuleConfig_RangeTestConfig;
Comment thread
dubsector marked this conversation as resolved.
Outdated
},
subscribe: () => () => {},
} as const;

export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {
useWaitForConfig({ moduleConfigCase: "rangeTest" });

const { moduleConfig, getEffectiveModuleConfig } = useDevice();
const { moduleConfig, channels, getEffectiveModuleConfig } = useDevice();
const editor = useConfigEditor();
const modules = useSignal(editor?.modules ?? EMPTY_MODULES_SIGNAL);
const effective =
Expand All @@ -39,11 +41,21 @@ export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {

const { t } = useTranslation("moduleConfig");

// A PSK shorter than 2 bytes means either cleartext (0 bytes) or the
// well-known default shortstring code (1 byte). Both are effectively
// public — Range Test must not run on them to avoid flooding the shared
// mesh. Use the CLI to override if intentional.
const primaryPsk = channels.get(0 as Protobuf.Channel.ChannelNumber)?.settings?.psk;
const isPrimaryChannelPublic = (primaryPsk?.length ?? 0) < 2;

const onSubmit = (data: RangeTestValidation) => {
if (!editor) return;
editor.setModuleSection(
"rangeTest",
data as unknown as Protobuf.ModuleConfig.ModuleConfig_RangeTestConfig,
{
...data,
enabled: isPrimaryChannelPublic ? false : data.enabled,
} as unknown as Protobuf.ModuleConfig.ModuleConfig_RangeTestConfig,
Comment thread
dubsector marked this conversation as resolved.
);
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Expand All @@ -64,19 +76,24 @@ export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {
name: "enabled",
label: t("rangeTest.enabled.label"),
description: t("rangeTest.enabled.description"),
disabled:
isPrimaryChannelPublic &&
!(effective?.enabled ?? moduleConfig.rangeTest?.enabled ?? false),
Comment thread
dubsector marked this conversation as resolved.
Outdated
},
{
type: "number",
name: "sender",
label: t("rangeTest.sender.label"),
description: t("rangeTest.sender.description"),
properties: { suffix: t("unit.second.plural") },
disabled: isPrimaryChannelPublic,
},
{
type: "toggle",
name: "save",
label: t("rangeTest.save.label"),
description: t("rangeTest.save.description"),
disabled: isPrimaryChannelPublic,
},
],
},
Expand Down