Files
gods-eye-view/src/voice/realtimePreferences.js
T
Sameh Khamis 73e789489b chore: drop exports nothing imports
Knip, configured with the application, package exports, scripts, QA
harnesses, workers, tools and tests as entry points, reports exports
that no module imports. Each was checked by hand against string-based
and namespace imports.

- Symbols that are still used inside their own module lose only the
  `export` keyword (176 constants and helpers).
- Unused re-exports are removed from barrel modules (flight, military,
  vessel, CCTV, directions, transit history, local ADS-B and street-level
  policy modules).
- Declarations that nothing uses at all are deleted, among them
  AIS_WATCHDOG_STATUSES, applyFilter, isRadioCountryCode, compactText,
  DENSITY_STOPS, the unused CCTV endpoint constants, and the SDR band
  constants.
- Default exports that nothing imports are removed. The ones in
  src/data/earthquakes.js, src/data/telegeographySubmarineCables.js,
  src/data/wind.js and src/data/bhoteKoshiLocator.js each constructed a
  layer instance at import time that nothing used; those instances are
  no longer created.

Every export of a package.json entry stays, as does TOMTOM_CREDIT,
which the traffic layer reads from the credits namespace it is given.
2026-10-22 19:00:40 -07:00

85 lines
2.5 KiB
JavaScript

import {
DEFAULT_VOICE_TIER,
isKnownVoiceTier,
normalizeCostLimits,
resolveVoiceModel,
serializeCostLimits,
} from './voiceCost.js';
// Voice cost control (repo-wide `godsEyeView.<feature>.<field>` convention;
// the neighbouring ERROR_STORAGE_KEY predates it).
const VOICE_TIER_STORAGE_KEY = 'godsEyeView.voiceCost.tier';
const VOICE_LIMITS_STORAGE_KEY = 'godsEyeView.voiceCost.limits';
/** Best-effort localStorage handle; absent in tests and locked-down browsers. */
function voiceStorage(storage) {
if (storage) return storage;
try {
return typeof localStorage === 'undefined' ? null : localStorage;
} catch {
return null; // privacy modes throw on mere access
}
}
/**
* Read the persisted voice model tier. Unknown/corrupt values resolve to the
* default, so a hand-edited localStorage entry can never pick a bad model.
*/
export function readStoredVoiceTier(storage) {
try {
const raw = voiceStorage(storage)?.getItem(VOICE_TIER_STORAGE_KEY);
return isKnownVoiceTier(raw)
? resolveVoiceModel(raw).tier
: DEFAULT_VOICE_TIER;
} catch {
return DEFAULT_VOICE_TIER;
}
}
/** Persist the voice model tier. Never throws. */
export function writeStoredVoiceTier(tier, storage) {
const resolved = resolveVoiceModel(tier).tier;
try {
voiceStorage(storage)?.setItem(VOICE_TIER_STORAGE_KEY, resolved);
} catch {
/* best effort */
}
return resolved;
}
/**
* Read the persisted spend thresholds, falling back to the generous defaults.
* Stored as `{"warnUsd":2,"capUsd":5}` under one key so both move together.
*/
export function readStoredVoiceLimits(storage) {
try {
const raw = voiceStorage(storage)?.getItem(VOICE_LIMITS_STORAGE_KEY);
if (!raw) return normalizeCostLimits(null);
return normalizeCostLimits(JSON.parse(raw));
} catch {
return normalizeCostLimits(null); // corrupt JSON must not disable the cap
}
}
/**
* Persist spend thresholds. Never throws.
*
* Serialized through `serializeCostLimits` because a DISABLED threshold is
* Infinity, and `JSON.stringify(Infinity)` is `null` — which reads back as
* "absent" and silently restores the default, re-arming a cap the user turned
* off. The 'off' sentinel round-trips instead.
*/
export function writeStoredVoiceLimits(limits, storage) {
const normalized = normalizeCostLimits(limits);
try {
voiceStorage(storage)?.setItem(
VOICE_LIMITS_STORAGE_KEY,
JSON.stringify(serializeCostLimits(normalized)),
);
} catch {
/* best effort */
}
return normalized;
}