feat(radio): answer the RTL-SDR card through the radio store

SdrCard calls LocalSdrControls through radio store actions instead of
DOM listeners, and renders its gain options from the receiver's own
R820T gain steps with page-language labels. The display and radio
stores share one owner list (createOwners): the newest connected owner
with an action answers it.
This commit is contained in:
Sameh Khamis committed 2026-11-01 10:52:50 -08:00
1 parent e5fa31d01e
commit 61d11ce369
12 files changed
+320 -206

No files matched your search

+4 -38
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia';
import { markRaw, shallowRef } from 'vue';
import { createOwners } from './owners.js';
/**
* The Display panel as its view renders it. VisualSettings presents its
@@ -67,44 +68,9 @@ export const useDisplayStore = defineStore('gev-display', () => {
mapSourceControls.value = controls && markRaw(controls);
}
/**
* The owners answering the panel's controls, oldest first: DisplayBindings
* the Display controls and the dock's style buttons, the draw tool and the
* file import their own.
* @type {Array<{actions: object}>}
*/
const owners = [];
/**
* Answer the actions named in `actions`; for those names this owner
* replaces any earlier one.
* @param {Record<string, Function>} actions
* @returns {object} Token for detach().
*/
function connect(actions) {
const token = { actions };
owners.push(token);
return token;
}
/** Stop answering for the owner holding `token`; the others stay. */
function detach(token) {
const index = owners.indexOf(token);
if (index >= 0) owners.splice(index, 1);
}
/**
* A control's change: call the newest connected owner's action of that
* name, if any.
* @param {string} name
* @param {...unknown} args
*/
function act(name, ...args) {
for (let index = owners.length - 1; index >= 0; index -= 1) {
const action = owners[index].actions[name];
if (action) return void action(...args);
}
}
// DisplayBindings answers the Display controls and the dock's style
// buttons, the draw tool and the file import their own.
const { connect, detach, act } = createOwners();
/** The phone shell's tab bar; null until the shell first presents it. */
const phoneShell = shallowRef(null);
+43
View File
@@ -0,0 +1,43 @@
/**
* The owners answering a store's controls. A view calls `act(name, ...args)`;
* the newest connected owner with an action of that name answers it, so an
* owner that connects again replaces itself, and owners of different actions
* sit side by side.
* @returns {{connect: Function, detach: Function, act: Function}}
*/
export function createOwners() {
/** @type {Array<{actions: object}>} Oldest first. */
const owners = [];
/**
* Answer the actions named in `actions`.
* @param {Record<string, Function>} actions
* @returns {object} Token for detach().
*/
function connect(actions) {
const token = { actions };
owners.push(token);
return token;
}
/** Stop answering for the owner holding `token`; the others stay. */
function detach(token) {
const index = owners.indexOf(token);
if (index >= 0) owners.splice(index, 1);
}
/**
* A control's change: call the newest connected owner's action of that
* name, if any.
* @param {string} name
* @param {...unknown} args
*/
function act(name, ...args) {
for (let index = owners.length - 1; index >= 0; index -= 1) {
const action = owners[index].actions[name];
if (action) return void action(...args);
}
}
return { connect, detach, act };
}
+28
View File
@@ -0,0 +1,28 @@
// src/ui/stores/owners.test.mjs — the newest connected owner with an action
// answers it; detaching hands the action back to the one before.
import test from 'node:test';
import assert from 'node:assert/strict';
import { createOwners } from './owners.js';
test('the newest owner with an action answers it, and detach hands it back', () => {
const { connect, detach, act } = createOwners();
const calls = [];
const first = connect({
play: (n) => calls.push(['first.play', n]),
stop: () => calls.push(['first.stop']),
});
const second = connect({ play: (n) => calls.push(['second.play', n]) });
act('play', 1);
act('stop');
act('missing');
detach(second);
act('play', 2);
detach(second);
detach(first);
act('play', 3);
assert.deepEqual(calls, [
['second.play', 1],
['first.stop'],
['first.play', 2],
]);
});
+8 -1
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia';
import { markRaw, shallowRef } from 'vue';
import { createOwners } from './owners.js';
/**
* The Radio panel as its view renders it. RadioControls presents the
@@ -7,7 +8,7 @@ import { markRaw, shallowRef } from 'vue';
* Cockpit's compact radio controls (`renderRadioState()`), which Cockpit
* utility popover is open, and the directory tuner, and publishes them here;
* it keeps its listeners. LocalSdrControls publishes the local RTL-SDR card
* beside it.
* beside it, and the card's controls reach it through act().
*/
export const useRadioStore = defineStore('gev-radio', () => {
/** The presented panel; null until the controls first render. */
@@ -42,6 +43,9 @@ export const useRadioStore = defineStore('gev-radio', () => {
tuner.value = markRaw(next);
}
// LocalSdrControls answers the RTL-SDR card's controls.
const { connect, detach, act } = createOwners();
return {
view,
publish,
@@ -51,5 +55,8 @@ export const useRadioStore = defineStore('gev-radio', () => {
publishUtility,
tuner,
publishTuner,
connect,
detach,
act,
};
});