feat(cat): several radios, switched from the status bar
The answer to 'I have two rigs' was 'make two profiles', which is a heavy
instrument for a light question: a profile carries the whole station —
logbook, callsign, awards, cluster, macros — so switching one to change
which radio is connected takes all of that with it, including a change of
logbook when the profiles point at different databases.
Radios are a list now, the way amplifiers already are. The CAT chip in the
status bar opens it, one click connects the chosen rig, and nothing else
about the station moves.
The storage keeps the ACTIVE radio in the same settings keys everything
already reads (cat.backend, cat.icom_port, …), and switching writes the
chosen entry into them and reloads the link. So the consoles, the CAT
sharing, the band-follow and every panel see exactly what they saw before
and needed no change at all — the list is a second store beside the
configuration, not a replacement for it.
Details that matter more than they look:
- An operator who has run one rig for a year opens the list and finds it
there, because a missing list reads as the CURRENT settings rather
than as nothing. It is written on the first save, not on the first
read.
- Editing the CAT panel updates the active entry, or an edit made before
switching away would be lost on the way back.
- A new radio starts as a COPY of the current one: a second rig is
usually the same shape with one port changed, and an empty form is a
form to fill in twice.
- Switching saves the panel first, so edits to the radio being left
behind are kept.
- The chip only becomes a menu with more than one radio; with one it
opens the CAT settings exactly as it always did.
This commit is contained in:
+85
-6
@@ -1,7 +1,7 @@
|
||||
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Activity, AlertCircle, Antenna, Bell, Check, CheckCircle2, ChevronDown, Clock, CloudOff, Compass, Database, Ear, Eraser, Flame, Gauge, Hash, Loader2, Lock,
|
||||
Maximize2, Minimize2, Mic, MessageSquare, Pencil, Radar, Radio, RadioTower, RefreshCw, Satellite, Send, SatelliteDish, Settings, SlidersHorizontal, SpellCheck, Square, Terminal, Trash2, Unlock, X, Zap,
|
||||
ChevronUp, Maximize2, Minimize2, Mic, MessageSquare, Pencil, Radar, Radio, RadioTower, RefreshCw, Satellite, Send, SatelliteDish, Settings, SlidersHorizontal, SpellCheck, Square, Terminal, Trash2, Unlock, X, Zap,
|
||||
} from 'lucide-react';
|
||||
|
||||
import {
|
||||
@@ -56,6 +56,7 @@ import {
|
||||
} from '../wailsjs/go/main/App';
|
||||
import { Combobox } from '@/components/ui/combobox';
|
||||
import { applyAwardRefs, parseAwardRefs as parseManualRefs, spotRefList , withIOTARef, withRDARef } from '@/lib/awardRefs';
|
||||
import { ListRadios, SetActiveRadio } from '../wailsjs/go/main/App';
|
||||
import { EventsOn, BrowserOpenURL, WindowMinimise, WindowToggleMaximise, WindowIsMaximised, Quit } from '../wailsjs/runtime/runtime';
|
||||
import type { adif as adifModels, lookup as lookupModels, cat as catModels } from '../wailsjs/go/models';
|
||||
import type { QSOForm, WorkedBeforeView, StationSettingsForm, ListsSettingsForm, ModePresetForm } from '@/types';
|
||||
@@ -290,6 +291,79 @@ function FreqWheelDisplay({ mhz, onNudge, className, placeholder = '—.——
|
||||
// shortCatError condenses a backend error into a few words for the topbar
|
||||
// pill. The full message stays in the tooltip. Recognises the common cases
|
||||
// (OmniRig not installed, not registered) and otherwise truncates.
|
||||
// RadioChip — the CAT status chip, and the radio picker behind it.
|
||||
function RadioChip({ catUp, catState, onOpenSettings }: {
|
||||
catUp: boolean; catState: any; onOpenSettings: () => void;
|
||||
}) {
|
||||
const [radios, setRadios] = useState<any[]>([]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Re-read on every open rather than on a timer: the list changes when the
|
||||
// operator edits it in Settings, which is exactly when they are not looking
|
||||
// at this chip.
|
||||
const load = () => { ListRadios().then((r: any) => setRadios(r ?? [])).catch(() => {}); };
|
||||
useEffect(() => { load(); }, []);
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDoc = (e: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onDoc);
|
||||
return () => document.removeEventListener('mousedown', onDoc);
|
||||
}, [open]);
|
||||
|
||||
const label = catUp
|
||||
? (catState.rig || 'CAT')
|
||||
: (catState.enabled ? (shortCatError(catState.error) || 'CAT off') : 'CAT');
|
||||
const many = radios.length > 1;
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { if (!many) { onOpenSettings(); return; } load(); setOpen((o) => !o); }}
|
||||
title={many
|
||||
? 'Switch radio — right-click for the CAT settings'
|
||||
: (catUp ? `CAT: ${catState.rig || catState.backend || 'connected'}` : (catState.error || 'CAT'))}
|
||||
onContextMenu={(e) => { e.preventDefault(); onOpenSettings(); }}
|
||||
className={cn('inline-flex items-center gap-1.5 h-5 px-2 rounded-full border text-[11px] transition-colors',
|
||||
'border-border hover:bg-muted cursor-pointer')}
|
||||
>
|
||||
<span className={cn('size-2 rounded-full', catUp ? 'bg-success' : 'bg-muted-foreground/40')} />
|
||||
<span className="inline-flex items-center gap-1"><RadioTower className="size-3" />{label}</span>
|
||||
{many && <ChevronUp className="size-3 opacity-60" />}
|
||||
</button>
|
||||
{open && many && (
|
||||
<div className="absolute bottom-full left-0 mb-1 z-50 min-w-44 rounded-md border border-border bg-card shadow-lg py-1">
|
||||
{radios.map((r) => (
|
||||
<button
|
||||
key={r.id}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
if (r.active) return;
|
||||
SetActiveRadio(r.id).then(load).catch(() => {});
|
||||
}}
|
||||
className={cn('flex w-full items-center gap-2 px-2.5 py-1 text-left text-xs hover:bg-muted',
|
||||
r.active && 'font-semibold text-primary')}
|
||||
>
|
||||
<span className={cn('size-1.5 rounded-full shrink-0', r.active ? 'bg-success' : 'bg-muted-foreground/30')} />
|
||||
<span className="flex-1 truncate">{r.name}</span>
|
||||
<span className="text-[10px] text-muted-foreground uppercase">{r.backend}</span>
|
||||
</button>
|
||||
))}
|
||||
<div className="my-1 border-t border-border/60" />
|
||||
<button type="button" onClick={() => { setOpen(false); onOpenSettings(); }}
|
||||
className="w-full px-2.5 py-1 text-left text-xs text-muted-foreground hover:bg-muted">
|
||||
Radios…
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function shortCatError(err?: string): string {
|
||||
if (!err) return '';
|
||||
const e = err.toLowerCase();
|
||||
@@ -8312,11 +8386,16 @@ export default function App() {
|
||||
</span>
|
||||
<div className="w-px h-4 bg-border mx-1" />
|
||||
<Chip on={clusterUp} label="Cluster" title={clusterUp ? 'Cluster connected' : 'Cluster offline'} onClick={() => setActiveTab('cluster')} />
|
||||
<Chip
|
||||
on={catUp}
|
||||
label={<span className="inline-flex items-center gap-1"><RadioTower className="size-3" />{catUp ? (catState.rig || 'CAT') : (catState.enabled ? (shortCatError(catState.error) || 'CAT off') : 'CAT')}</span>}
|
||||
title={catUp ? `CAT: ${catState.rig || catState.backend || 'connected'}` : (catState.error || 'CAT')}
|
||||
onClick={() => { setSettingsSection('cat'); setShowSettings(true); }}
|
||||
{/* The CAT chip is also the radio switch.
|
||||
With one radio it behaves as it always did — click opens the CAT
|
||||
settings. With several it opens a menu: pick one and OpsLog
|
||||
reconnects to it, leaving the rest of the station alone. The
|
||||
answer to "I have two rigs" used to be "make two profiles",
|
||||
which moves the logbook with it. */}
|
||||
<RadioChip
|
||||
catUp={catUp}
|
||||
catState={catState}
|
||||
onOpenSettings={() => { setSettingsSection('cat'); setShowSettings(true); }}
|
||||
/>
|
||||
<Chip
|
||||
on={rotatorHeading.enabled && rotatorHeading.ok}
|
||||
|
||||
Reference in New Issue
Block a user