mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Make Space Missions an ordinary layer with its own panel
Space Missions no longer runs as a Context mode. The launches layer owns its Satellites dependency, including the rule that a Satellites off asked for after Space Missions was switched on ends it (request order decides), and a small controller connects the layer to its own panel and store. Context no longer isolates, snapshots or restores Space Missions or Satellites, so Contacts and Space Missions run together in either order, and scene playback no longer exits an isolating mode. Settled by the owner: Contacts leaves Satellites as it is, and only a person's or voice Satellites off ends Space Missions; a scene, story, preset or other programmatic off does not. Turning the layer on by hand or by voice, choosing it at first run, or picking a mission on the globe opens the Space Missions panel, and on a phone its Missions sheet. Asking voice to open the panel while the layer is off is refused with a reason, and voice never opens it while the Cockpit owns the screen. With no Context mode on, a voice Context off switches Space Missions off. A failed Satellites restore no longer cuts the layer's teardown short. Mission labels on the globe select their mission. The layer names a failed first index load itself, so the Context toast no longer imports Space Missions code. Also carries the satellites request ordering and DataLayerManager.waitForLayerIdle, the share token for the panel, voice panel ids, Cockpit folding the panel away and the phone tab ellipsis. The panel shares the rail gutters and hover border of the other side panels. On top of the Omnibar: "open space missions panel" reaches the new panel, and Open Context no longer answers to "missions". Co-authored-by: Sameh Khamis <[email protected]>
This commit is contained in:
1 parent
8b2ca602e5
commit
0a6fd5f43f
101 files changed
+2885
-1673
No files matched your search
Vendored
+94
-1
@@ -1,4 +1,23 @@
|
||||
import { formatNumber, t } from '../../i18n/index.js';
|
||||
|
||||
export function createControls({ state: layerState, services, parts, source }) {
|
||||
let unsubscribeRowControls = null;
|
||||
|
||||
function cycleMission(step) {
|
||||
const entries = layerState._missionRosterView?.entries;
|
||||
if (!layerState._enabled || !entries?.length) return;
|
||||
const index = entries.findIndex(
|
||||
({ id }) => id === layerState._selectedLaunchId,
|
||||
);
|
||||
const next =
|
||||
index < 0
|
||||
? step > 0
|
||||
? 0
|
||||
: entries.length - 1
|
||||
: (index + step + entries.length) % entries.length;
|
||||
parts.panel.selectMissionAt(entries[next].index);
|
||||
}
|
||||
|
||||
const methods = {
|
||||
id: 'rocket-launches',
|
||||
|
||||
@@ -10,6 +29,67 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
|
||||
updateInterval: 300000,
|
||||
|
||||
getRowControls() {
|
||||
const entries = layerState._missionRosterView?.entries;
|
||||
if (!layerState._enabled || !entries?.length) return null;
|
||||
const index = entries.findIndex(
|
||||
({ id }) => id === layerState._selectedLaunchId,
|
||||
);
|
||||
const disabled = entries.length === 1 && index >= 0;
|
||||
return {
|
||||
info:
|
||||
index < 0
|
||||
? t('SELECT A MISSION TO INSPECT')
|
||||
: `${formatNumber(index + 1)} / ${formatNumber(entries.length)} · ${entries[index].label}`,
|
||||
chips: [
|
||||
{
|
||||
id: 'previous-mission',
|
||||
label: t('Previous mission'),
|
||||
icon: 'chevron_left',
|
||||
action: true,
|
||||
disabled,
|
||||
onClick: () => cycleMission(-1),
|
||||
},
|
||||
{
|
||||
id: 'next-mission',
|
||||
label: t('Next mission'),
|
||||
icon: 'chevron_right',
|
||||
action: true,
|
||||
disabled,
|
||||
onClick: () => cycleMission(1),
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
setRowControlsListener(listener) {
|
||||
unsubscribeRowControls?.();
|
||||
unsubscribeRowControls = null;
|
||||
if (!listener) return;
|
||||
let previousRoster;
|
||||
let previousSelection;
|
||||
unsubscribeRowControls = parts.panel.subscribePanel(({ roster }) => {
|
||||
// Replay and telemetry can update without changing the roster or pick.
|
||||
const selection = layerState._selectedLaunchId;
|
||||
if (roster === previousRoster && selection === previousSelection)
|
||||
return;
|
||||
previousRoster = roster;
|
||||
previousSelection = selection;
|
||||
listener();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Hear each mission picked on the globe (a marker or its label), after
|
||||
* it is selected. The app reveals the Space Missions panel for it.
|
||||
* @param {(launchId: string) => void} listener
|
||||
* @returns {() => void} Unsubscribe.
|
||||
*/
|
||||
subscribeGlobePick(listener) {
|
||||
layerState._globePickListeners.add(listener);
|
||||
return () => layerState._globePickListeners.delete(listener);
|
||||
},
|
||||
|
||||
/** Release only Space Mission camera ownership, preserving layer and selection state. */
|
||||
releaseCameraOwnership() {
|
||||
// Navigation takes the camera; a failed entry must not restore the old view.
|
||||
@@ -54,19 +134,32 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* Why a start failed, for the person: the mission index never loaded.
|
||||
* Null when the failure is not the index's (the app then names it).
|
||||
* @returns {?string}
|
||||
*/
|
||||
enableFailureMessage() {
|
||||
return layerState._lastError && layerState._lastUpdate == null
|
||||
? t(
|
||||
'Space Missions unavailable: the mission index could not load. Try again later.',
|
||||
)
|
||||
: null;
|
||||
},
|
||||
|
||||
getStats() {
|
||||
return {
|
||||
count: layerState._count,
|
||||
orbitMatches: layerState._orbitMatches,
|
||||
lastUpdate: layerState._lastUpdate,
|
||||
error: layerState._lastError,
|
||||
errorAt: layerState._lastErrorAt,
|
||||
stale: layerState._stale,
|
||||
};
|
||||
},
|
||||
|
||||
attachDataManager(dataManager) {
|
||||
layerState._dataManager = dataManager;
|
||||
parts.satelliteIntents.connect(dataManager);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { DataLayerManager } from '../../data/manager.js';
|
||||
import { ContextControls } from '../../ui/contextControls.js';
|
||||
import { spaceMissionsIndexFailure } from '../../ui/contextActions.js';
|
||||
import { createLaunchSource } from './source.js';
|
||||
import { createState } from './state.js';
|
||||
import { createModel } from './model.js';
|
||||
import { createPolicyHelpers } from './policyHelpers.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createSatelliteIntents } from './satelliteIntents.js';
|
||||
import { createPanel } from './panel.js';
|
||||
import { createControls } from './controls.js';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
@@ -98,7 +98,7 @@ function fakeCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
async function fixture(t) {
|
||||
async function fixture(t, { beforeConnect } = {}) {
|
||||
const upstream = { status: 429, results: [launchRecord] };
|
||||
const source = createLaunchSource({
|
||||
async fetchImpl(url) {
|
||||
@@ -191,6 +191,7 @@ async function fixture(t) {
|
||||
parts.panel = createPanel(context);
|
||||
parts.replay = createReplay(context);
|
||||
parts.ingestion = createIngestion(context);
|
||||
parts.satelliteIntents = createSatelliteIntents(context);
|
||||
parts.controls = createControls(context);
|
||||
parts.lifecycle = createLifecycle(context);
|
||||
const missions = Object.assign(
|
||||
@@ -206,6 +207,7 @@ async function fixture(t) {
|
||||
manager.register(plainLayer('earthquakes', 'Earthquakes (24h)'));
|
||||
manager.register(plainLayer('satellites', 'Satellites'));
|
||||
manager.register(plainLayer('wind', 'Wind'));
|
||||
manager.register(plainLayer('military-awareness', 'Global Context'));
|
||||
manager.register(missions);
|
||||
missions.attachDataManager(manager);
|
||||
|
||||
@@ -224,12 +226,19 @@ async function fixture(t) {
|
||||
setPanelCollapsed: noop,
|
||||
},
|
||||
});
|
||||
beforeConnect?.(manager);
|
||||
controls.connect(manager);
|
||||
|
||||
t.after(async () => {
|
||||
controls.stop();
|
||||
controls.disconnect();
|
||||
for (const id of ['rocket-launches', 'satellites', 'earthquakes', 'wind'])
|
||||
for (const id of [
|
||||
'rocket-launches',
|
||||
'satellites',
|
||||
'earthquakes',
|
||||
'wind',
|
||||
'military-awareness',
|
||||
])
|
||||
await manager.setEnabled(id, false);
|
||||
await missions.destroy(viewer);
|
||||
});
|
||||
@@ -257,46 +266,37 @@ async function fixture(t) {
|
||||
state,
|
||||
camera,
|
||||
rosters,
|
||||
panel: parts.panel,
|
||||
enabledIds,
|
||||
view,
|
||||
settle,
|
||||
};
|
||||
}
|
||||
|
||||
const entries = {
|
||||
direct: (f) =>
|
||||
f.manager.setEnabled('rocket-launches', true, { origin: 'user' }),
|
||||
'Context-panel': async (f) =>
|
||||
(
|
||||
await f.controls.setContextMode('space-missions', {
|
||||
claimVisualAuthority: false,
|
||||
})
|
||||
).ok,
|
||||
};
|
||||
test('a Space Missions start that gets HTTP 429 rolls back and leaves other layers alone', async (t) => {
|
||||
const f = await fixture(t);
|
||||
await f.manager.setEnabled('earthquakes', true, { origin: 'user' });
|
||||
const before = f.view();
|
||||
|
||||
for (const [path, enter] of Object.entries(entries))
|
||||
test(`a ${path} Space Missions entry that gets HTTP 429 rolls back instead of isolating`, async (t) => {
|
||||
const f = await fixture(t);
|
||||
await f.manager.setEnabled('earthquakes', true, { origin: 'user' });
|
||||
const before = f.view();
|
||||
|
||||
const entered = await enter(f);
|
||||
await f.settle();
|
||||
|
||||
assert.equal(entered, false, 'a failed mission index fails the enable');
|
||||
assert.deepEqual(f.enabledIds(), ['earthquakes']);
|
||||
assert.equal(f.controls.getContextModeState().mode, null);
|
||||
assert.equal(f.controls.getContextModeState().active, false);
|
||||
assert.equal(f.missions.getStats().error, 'HTTP 429');
|
||||
assert.deepEqual(f.view(), before, 'the pre-entry view comes back');
|
||||
assert.ok(f.camera.cancelled > 0, 'the full-globe flight is cancelled');
|
||||
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('wind', true, { origin: 'user' }),
|
||||
true,
|
||||
'an unrelated layer is not blocked after the failed entry',
|
||||
);
|
||||
const entered = await f.manager.setEnabled('rocket-launches', true, {
|
||||
origin: 'user',
|
||||
});
|
||||
await f.settle();
|
||||
|
||||
assert.equal(entered, false, 'a failed mission index fails the enable');
|
||||
assert.deepEqual(f.enabledIds(), ['earthquakes']);
|
||||
assert.equal(f.controls.getContextModeState().mode, null);
|
||||
assert.equal(f.controls.getContextModeState().active, false);
|
||||
assert.equal(f.missions.getStats().error, 'HTTP 429');
|
||||
assert.deepEqual(f.view(), before, 'the pre-entry view comes back');
|
||||
assert.ok(f.camera.cancelled > 0, 'the full-globe flight is cancelled');
|
||||
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('wind', true, { origin: 'user' }),
|
||||
true,
|
||||
'an unrelated layer is not blocked after the failed entry',
|
||||
);
|
||||
});
|
||||
|
||||
// Holds the /api/launches reply until the returned release is called.
|
||||
function holdReply(f) {
|
||||
@@ -410,7 +410,12 @@ test('the roster reports a failed mission index instead of loading forever', asy
|
||||
await f.settle();
|
||||
assert.equal(f.rosters.slice(loadingFrom).includes(null), true);
|
||||
assert.equal(f.rosters.at(-1).entries.length, 1);
|
||||
assert.equal(f.controls.getContextModeState().mode, 'space-missions');
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), true);
|
||||
assert.equal(
|
||||
f.controls.getContextModeState().mode,
|
||||
null,
|
||||
'not a Context mode',
|
||||
);
|
||||
});
|
||||
|
||||
test('a valid empty mission index is a successful entry', async (t) => {
|
||||
@@ -422,7 +427,7 @@ test('a valid empty mission index is a successful entry', async (t) => {
|
||||
true,
|
||||
);
|
||||
await f.settle();
|
||||
assert.equal(f.controls.getContextModeState().mode, 'space-missions');
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), true);
|
||||
assert.equal(
|
||||
f.rosters.at(-1).empty,
|
||||
'NO MISSIONS AVAILABLE IN THE CURRENT 30-DAY WINDOW',
|
||||
@@ -430,7 +435,236 @@ test('a valid empty mission index is a successful entry', async (t) => {
|
||||
assert.ok(f.camera.flights > 0, 'a successful entry frames the globe');
|
||||
});
|
||||
|
||||
test('a refresh failure after a loaded index keeps the mode and its records', async (t) => {
|
||||
for (const phase of ['while starting', 'after start']) {
|
||||
test(`Space Missions runs beside Contacts and a later Satellites OFF ends it (${phase})`, async (t) => {
|
||||
const gate = Promise.withResolvers();
|
||||
const guardReached = Promise.withResolvers();
|
||||
const f = await fixture(t, {
|
||||
beforeConnect(manager) {
|
||||
if (phase !== 'while starting') return;
|
||||
manager.addVisibilityGuard(async ({ layerId, enabled }) => {
|
||||
if (layerId !== 'rocket-launches' || !enabled) return;
|
||||
guardReached.resolve();
|
||||
await gate.promise;
|
||||
});
|
||||
},
|
||||
});
|
||||
f.upstream.status = 200;
|
||||
await f.manager.setEnabled('satellites', true, { origin: 'user' });
|
||||
assert.equal(await f.controls._selectContextMode('flights'), true);
|
||||
await f.settle();
|
||||
assert.deepEqual(
|
||||
f.enabledIds(),
|
||||
['military-awareness', 'satellites'],
|
||||
'Contacts leaves Satellites alone',
|
||||
);
|
||||
|
||||
const launch = f.manager.setEnabled('rocket-launches', true, {
|
||||
origin: 'user',
|
||||
});
|
||||
try {
|
||||
if (phase === 'while starting') {
|
||||
await guardReached.promise;
|
||||
} else {
|
||||
assert.equal(await launch, true);
|
||||
assert.deepEqual(f.enabledIds(), [
|
||||
'military-awareness',
|
||||
'rocket-launches',
|
||||
'satellites',
|
||||
]);
|
||||
}
|
||||
assert.equal(
|
||||
f.controls.getContextModeState().mode,
|
||||
'flights',
|
||||
'starting Space Missions leaves Contacts on',
|
||||
);
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('satellites', false, { origin: 'voice' }),
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
gate.resolve();
|
||||
}
|
||||
assert.equal(await launch, phase === 'after start');
|
||||
await f.missions.waitForSatelliteIntents?.();
|
||||
await f.settle();
|
||||
assert.deepEqual(f.enabledIds(), ['military-awareness']);
|
||||
assert.equal(f.controls.getContextModeState().mode, 'flights');
|
||||
});
|
||||
}
|
||||
|
||||
test('Contacts started and ended while Space Missions runs leaves it and Satellites alone', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' }),
|
||||
true,
|
||||
);
|
||||
await f.settle();
|
||||
const missionParams = f.manager.getLayerParams('satellites');
|
||||
assert.equal(missionParams.showPoints, false, 'the mission display applied');
|
||||
|
||||
assert.equal(await f.controls._selectContextMode('flights'), true);
|
||||
await f.settle();
|
||||
assert.deepEqual(f.enabledIds(), [
|
||||
'military-awareness',
|
||||
'rocket-launches',
|
||||
'satellites',
|
||||
]);
|
||||
assert.equal(await f.controls._selectContextMode(null), true);
|
||||
await f.settle();
|
||||
assert.deepEqual(f.enabledIds(), ['rocket-launches', 'satellites']);
|
||||
assert.deepEqual(f.manager.getLayerParams('satellites'), missionParams);
|
||||
|
||||
await f.manager.setEnabled('rocket-launches', false, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.deepEqual(f.enabledIds(), []);
|
||||
const after = f.manager.getLayerParams('satellites');
|
||||
assert.notEqual(after.showPoints, false, 'Satellites shows its points again');
|
||||
assert.notEqual(after.showOrbits, false, 'and its orbits');
|
||||
});
|
||||
|
||||
test('a Satellites OFF requested before Space Missions entry does not cancel it', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
await f.manager.setEnabled('satellites', true, { origin: 'user' });
|
||||
const satellites = f.manager.layers.get('satellites').module;
|
||||
const disable = satellites.disable;
|
||||
const gate = Promise.withResolvers();
|
||||
const disabling = Promise.withResolvers();
|
||||
satellites.disable = async () => {
|
||||
disabling.resolve();
|
||||
await gate.promise;
|
||||
};
|
||||
let entry;
|
||||
try {
|
||||
const off = f.manager.setEnabled('satellites', false, { origin: 'user' });
|
||||
await disabling.promise;
|
||||
// The entry is requested while the earlier OFF is still settling.
|
||||
entry = f.manager.setEnabled('rocket-launches', true, { origin: 'user' });
|
||||
gate.resolve();
|
||||
assert.equal(await off, true);
|
||||
} finally {
|
||||
gate.resolve();
|
||||
satellites.disable = disable;
|
||||
}
|
||||
assert.equal(await entry, true, 'the later entry is not cancelled');
|
||||
await f.settle();
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), true);
|
||||
|
||||
// Leaving keeps the earlier Satellites OFF.
|
||||
await f.manager.setEnabled('rocket-launches', false, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.equal(f.manager.isEnabled('satellites'), false);
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), false);
|
||||
});
|
||||
|
||||
test('Space Missions is an ordinary layer: it neither isolates nor opens a Context session', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
await f.manager.setEnabled('earthquakes', true, { origin: 'user' });
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' }),
|
||||
true,
|
||||
);
|
||||
await f.settle();
|
||||
assert.deepEqual(f.enabledIds(), [
|
||||
'earthquakes',
|
||||
'rocket-launches',
|
||||
'satellites',
|
||||
]);
|
||||
assert.equal(f.controls._contextSessionSnapshot, null);
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('wind', true, { origin: 'user' }),
|
||||
true,
|
||||
'other layers are not refused while Space Missions is on',
|
||||
);
|
||||
await f.manager.setEnabled('rocket-launches', false, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.deepEqual(
|
||||
f.enabledIds(),
|
||||
['earthquakes', 'wind'],
|
||||
'Space Missions gives back only the Satellites it turned on',
|
||||
);
|
||||
});
|
||||
|
||||
test('a Satellites enable that never settles still lets mission disable complete', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' }),
|
||||
true,
|
||||
);
|
||||
await f.settle();
|
||||
f.state.satelliteSettleTimeoutMs = 50;
|
||||
const satellites = f.manager.layers.get('satellites').module;
|
||||
const enable = satellites.enable;
|
||||
const stuck = Promise.withResolvers();
|
||||
satellites.enable = () => stuck.promise;
|
||||
try {
|
||||
// A programmatic Satellites restart whose enable hangs.
|
||||
await f.manager.setEnabled('satellites', false);
|
||||
void f.manager.setEnabled('satellites', true);
|
||||
const exit = f.manager.setEnabled('rocket-launches', false, {
|
||||
origin: 'user',
|
||||
});
|
||||
const outcome = await Promise.race([
|
||||
exit.then(() => 'settled'),
|
||||
new Promise((resolve) => setTimeout(() => resolve('hung'), 2000)),
|
||||
]);
|
||||
assert.equal(
|
||||
outcome,
|
||||
'settled',
|
||||
'the mission disable does not wait forever',
|
||||
);
|
||||
assert.equal(f.missions.getAnalystRecords().length, 0);
|
||||
} finally {
|
||||
satellites.enable = enable;
|
||||
stuck.resolve();
|
||||
}
|
||||
await f.settle();
|
||||
});
|
||||
|
||||
test('a failed Satellites restore still clears the selected mission panel', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' }),
|
||||
true,
|
||||
);
|
||||
await f.settle();
|
||||
assert.equal(f.manager.isEnabled('satellites'), true);
|
||||
|
||||
let panelView;
|
||||
const unsubscribe = f.panel.subscribePanel((view) => {
|
||||
panelView = view;
|
||||
});
|
||||
const satellites = f.manager.layers.get('satellites').module;
|
||||
const disable = satellites.disable;
|
||||
try {
|
||||
f.state._selectedLaunchId = f.state._launches[0].id;
|
||||
f.panel.renderMissionPanel();
|
||||
assert.ok(panelView.mission);
|
||||
|
||||
satellites.disable = () => {
|
||||
throw new Error('injected Satellites restore failure');
|
||||
};
|
||||
assert.equal(
|
||||
await f.manager.setEnabled('rocket-launches', false, { origin: 'user' }),
|
||||
false,
|
||||
);
|
||||
const { enabled, uncertain } =
|
||||
f.manager.getLayerLifecycleState('rocket-launches');
|
||||
assert.equal(enabled, true);
|
||||
assert.equal(uncertain, true);
|
||||
assert.equal(panelView.mission, null);
|
||||
} finally {
|
||||
satellites.disable = disable;
|
||||
unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
test('a refresh failure after a loaded index keeps the layer and its records', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.upstream.status = 200;
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' });
|
||||
@@ -442,12 +676,11 @@ test('a refresh failure after a loaded index keeps the mode and its records', as
|
||||
await f.settle();
|
||||
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), true);
|
||||
assert.equal(f.controls.getContextModeState().mode, 'space-missions');
|
||||
assert.equal(f.missions.getStats().count, 1);
|
||||
assert.equal(f.missions.getStats().error, 'HTTP 429');
|
||||
assert.equal(f.rosters.at(-1).entries.length, 1);
|
||||
|
||||
// Leaving a loaded mode does not restore the pre-entry view.
|
||||
// Leaving after a loaded index does not restore the pre-entry view.
|
||||
await f.manager.setEnabled('rocket-launches', false, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.deepEqual(f.view(), framed);
|
||||
@@ -475,11 +708,9 @@ test('a failed first load tells the user the mission index is unavailable', asyn
|
||||
const f = await fixture(t);
|
||||
await f.manager.setEnabled('earthquakes', true, { origin: 'user' });
|
||||
|
||||
await f.controls.setContextMode('space-missions', {
|
||||
claimVisualAuthority: false,
|
||||
});
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.equal(f.controls.getContextModeState().mode, null, 'rolled back');
|
||||
assert.equal(f.manager.isEnabled('rocket-launches'), false, 'rolled back');
|
||||
assert.ok(
|
||||
f.toasts.some((message) => /mission index/i.test(message)),
|
||||
`visible feedback names the failure, got ${JSON.stringify(f.toasts)}`,
|
||||
@@ -504,10 +735,17 @@ test('navigation taking the camera keeps a mission flight it asked to preserve',
|
||||
assert.equal(f.camera.flight, other);
|
||||
});
|
||||
|
||||
test("an earlier attempt's index error is not blamed for a later failure", async (t) => {
|
||||
test('a refresh error after a loaded index is not blamed on the index', async (t) => {
|
||||
const f = await fixture(t);
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' });
|
||||
await f.settle();
|
||||
assert.match(spaceMissionsIndexFailure(f.manager), /mission index/);
|
||||
assert.equal(spaceMissionsIndexFailure(f.manager, Date.now() + 1), null);
|
||||
assert.match(f.missions.enableFailureMessage(), /mission index/);
|
||||
|
||||
f.upstream.status = 200;
|
||||
await f.manager.setEnabled('rocket-launches', true, { origin: 'user' });
|
||||
await f.settle();
|
||||
f.upstream.status = 429;
|
||||
await f.missions.update();
|
||||
assert.equal(f.missions.getStats().error, 'HTTP 429');
|
||||
assert.equal(f.missions.enableFailureMessage(), null);
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createPolicyHelpers } from './policyHelpers.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createSatelliteIntents } from './satelliteIntents.js';
|
||||
import { createOrbitRendering } from './orbitRendering.js';
|
||||
import { createOverlays } from './overlays.js';
|
||||
import { createSelection } from './selection.js';
|
||||
@@ -24,6 +25,7 @@ export function createRocketLaunchesLayer({ services, source }) {
|
||||
const context = { state, services, parts, source };
|
||||
parts.policyHelpers = createPolicyHelpers(context);
|
||||
parts.ingestion = createIngestion(context);
|
||||
parts.satelliteIntents = createSatelliteIntents(context);
|
||||
parts.orbitRendering = createOrbitRendering(context);
|
||||
parts.overlays = createOverlays(context);
|
||||
parts.selection = createSelection(context);
|
||||
@@ -45,6 +47,7 @@ export function createRocketLaunchesLayer({ services, source }) {
|
||||
parts.panel.commands,
|
||||
{
|
||||
subscribePanel: parts.panel.subscribePanel,
|
||||
waitForSatelliteIntents: parts.satelliteIntents.settled,
|
||||
subscribeReplayOverlay: parts.overlays.subscribeReplayOverlay,
|
||||
satelliteParamsForSpaceMissions:
|
||||
parts.policyHelpers.satelliteParamsForSpaceMissions,
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import { MAX_POST_TLE_RETRIES, POST_TLE_RETRY_DELAY_MS } from './policy.js';
|
||||
|
||||
/**
|
||||
* Let pending Satellites work finish, including requests that join it while
|
||||
* waiting, so the mission dependency cannot overtake it. Bounded: a
|
||||
* Satellites change that never settles cannot hold missions forever.
|
||||
*/
|
||||
async function waitForSatelliteVisibility(manager, { signal, timeoutMs }) {
|
||||
if (typeof manager.waitForLayerIdle !== 'function') return true;
|
||||
return manager.waitForLayerIdle('satellites', { signal, timeoutMs });
|
||||
}
|
||||
|
||||
export function createIngestion({
|
||||
state: layerState,
|
||||
services,
|
||||
@@ -97,28 +107,39 @@ export function createIngestion({
|
||||
}
|
||||
|
||||
async function captureSatelliteDependency() {
|
||||
if (!layerState._dataManager || layerState._satelliteStateBeforeMission)
|
||||
const manager = layerState._dataManager;
|
||||
if (!manager || layerState._satelliteStateBeforeMission) return;
|
||||
const token = layerState._lifecycleToken;
|
||||
// Let a pending Satellites action finish before reserving dependency ON.
|
||||
// A successful explicit OFF can cancel this mission entry while we wait.
|
||||
const idle = await waitForSatelliteVisibility(manager, {
|
||||
signal: layerState._sourceController?.signal,
|
||||
timeoutMs: layerState.satelliteSettleTimeoutMs,
|
||||
});
|
||||
if (token !== layerState._lifecycleToken) return;
|
||||
if (!idle && layerState._enabled)
|
||||
throw new Error(
|
||||
'Space Missions could not start: the satellites layer did not settle',
|
||||
);
|
||||
if (
|
||||
!layerState._enabled ||
|
||||
(manager.layers?.has('rocket-launches') &&
|
||||
!manager.isEffectivelyEnabled('rocket-launches'))
|
||||
)
|
||||
return;
|
||||
layerState._satelliteStateBeforeMission = {
|
||||
// Effective visibility: a user enable still mid-activation is intent ON —
|
||||
// capturing settled false would restore the user's enable away on exit.
|
||||
enabled:
|
||||
layerState._dataManager.isEffectivelyEnabled?.('satellites') ??
|
||||
layerState._dataManager.isEnabled('satellites'),
|
||||
enabled: manager.isEnabled('satellites'),
|
||||
params: parts.policyHelpers.satelliteParamsAfterSpaceMissions(
|
||||
layerState._dataManager.getLayerParams('satellites'),
|
||||
manager.getLayerParams('satellites'),
|
||||
),
|
||||
};
|
||||
layerState._dataManager.setLayerParams(
|
||||
manager.setLayerParams(
|
||||
'satellites',
|
||||
parts.policyHelpers.satelliteParamsForSpaceMissions(
|
||||
layerState._satelliteStateBeforeMission.params,
|
||||
),
|
||||
);
|
||||
const token = layerState._lifecycleToken;
|
||||
const activation = Promise.resolve(
|
||||
layerState._dataManager.setEnabled('satellites', true),
|
||||
);
|
||||
const activation = Promise.resolve(manager.setEnabled('satellites', true));
|
||||
layerState._satelliteActivationPromise = activation;
|
||||
try {
|
||||
const activated = await activation;
|
||||
@@ -128,8 +149,7 @@ export function createIngestion({
|
||||
if (
|
||||
token === layerState._lifecycleToken &&
|
||||
layerState._enabled &&
|
||||
(activated === false ||
|
||||
!layerState._dataManager.isEnabled('satellites'))
|
||||
(activated === false || !manager.isEnabled('satellites'))
|
||||
) {
|
||||
throw new Error(
|
||||
'Space Missions requires the satellites layer, which failed to start',
|
||||
@@ -146,21 +166,35 @@ export function createIngestion({
|
||||
}
|
||||
|
||||
async function restoreSatelliteDependency() {
|
||||
const manager = layerState._dataManager;
|
||||
const snapshot = layerState._satelliteStateBeforeMission;
|
||||
if (!snapshot || !layerState._dataManager) return;
|
||||
if (!snapshot || !manager) return;
|
||||
// Keep the snapshot available until any explicit Satellites action settles.
|
||||
const token = layerState._lifecycleToken;
|
||||
const idle = await waitForSatelliteVisibility(manager, {
|
||||
timeoutMs: layerState.satelliteSettleTimeoutMs,
|
||||
});
|
||||
if (
|
||||
token !== layerState._lifecycleToken ||
|
||||
layerState._satelliteStateBeforeMission !== snapshot
|
||||
)
|
||||
return;
|
||||
layerState._satelliteStateBeforeMission = null;
|
||||
layerState._satelliteActivationPromise = null;
|
||||
layerState._dataManager.setLayerParams(
|
||||
manager.setLayerParams(
|
||||
'satellites',
|
||||
parts.policyHelpers.satelliteParamsAfterSpaceMissions(snapshot.params),
|
||||
);
|
||||
const restored = await layerState._dataManager.setEnabled(
|
||||
'satellites',
|
||||
snapshot.enabled,
|
||||
);
|
||||
// An accepted Satellites action owns visibility through mission teardown.
|
||||
if (snapshot.restoreVisibility === false) return;
|
||||
if (!idle)
|
||||
throw new Error(
|
||||
'Space Missions could not restore the satellites layer: it did not settle',
|
||||
);
|
||||
const restored = await manager.setEnabled('satellites', snapshot.enabled);
|
||||
if (
|
||||
restored === false ||
|
||||
layerState._dataManager.isEnabled('satellites') !== snapshot.enabled
|
||||
manager.isEnabled('satellites') !== snapshot.enabled
|
||||
) {
|
||||
throw new Error('Space Missions could not restore the satellites layer');
|
||||
}
|
||||
@@ -230,7 +264,6 @@ export function createIngestion({
|
||||
} catch (error) {
|
||||
if (layerState._enabled && token === layerState._lifecycleToken) {
|
||||
layerState._lastError = error.message;
|
||||
layerState._lastErrorAt = Date.now();
|
||||
console.warn('[Data:RocketLaunches] Fetch error:', error);
|
||||
// No index yet: fail the enable so Context rolls back.
|
||||
// After a loaded index, a failed refresh keeps its records.
|
||||
|
||||
@@ -8,6 +8,7 @@ import { createLaunchSource } from './source.js';
|
||||
import { createState } from './state.js';
|
||||
import { createModel } from './model.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createSatelliteIntents } from './satelliteIntents.js';
|
||||
import { createControls } from './controls.js';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
import { layerFeedState } from '../../data/feedState.js';
|
||||
@@ -147,6 +148,7 @@ async function fixture({ legacySource = false } = {}) {
|
||||
const context = { state, services, parts, source };
|
||||
parts.model = createModel(context);
|
||||
parts.ingestion = createIngestion(context);
|
||||
parts.satelliteIntents = createSatelliteIntents(context);
|
||||
parts.controls = createControls(context);
|
||||
parts.lifecycle = createLifecycle(context);
|
||||
const current = () => {
|
||||
@@ -326,7 +328,11 @@ test('destroy followed by actual init starts a clean instance with owned handler
|
||||
assert.equal(typeof f.state._inputSubscription, 'function');
|
||||
await f.destroy();
|
||||
assert.equal(f.state._inputSubscription, null);
|
||||
assert.equal(input.subscriberCount(), before - 2, 'click and hover');
|
||||
assert.equal(
|
||||
input.subscriberCount(),
|
||||
before - 3,
|
||||
'label click, point click and hover',
|
||||
);
|
||||
|
||||
assert.equal(f.attachedSets(), 0);
|
||||
assert.equal(f.viewer.scene.preRender.numberOfListeners, 0);
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
// Clicks on painted mission labels, routed through the real input dispatcher.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Event } from 'cesium';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
import { createState } from './state.js';
|
||||
import {
|
||||
ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID,
|
||||
ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID,
|
||||
} from './policy.js';
|
||||
import {
|
||||
FAKE_EVENT_TYPES,
|
||||
FakeScreenSpaceEventHandler,
|
||||
fakeInput,
|
||||
} from '../../input/testDoubles.mjs';
|
||||
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
/** Parts whose every method is a no-op unless given. */
|
||||
function stub(methods = {}) {
|
||||
return new Proxy(methods, {
|
||||
get: (target, key) => (key in target ? target[key] : noop),
|
||||
});
|
||||
}
|
||||
|
||||
function rig(t, { overlayHit = null, geometryLaunchId = null } = {}) {
|
||||
const stock = new FakeScreenSpaceEventHandler();
|
||||
stock.setInputAction(noop, FAKE_EVENT_TYPES.LEFT_CLICK);
|
||||
const viewer = bindFakeCesiumCamera({
|
||||
isDestroyed: () => false,
|
||||
screenSpaceEventHandler: stock,
|
||||
camera: {
|
||||
moveStart: new Event(),
|
||||
moveEnd: new Event(),
|
||||
pickEllipsoid: () => null,
|
||||
},
|
||||
scene: {
|
||||
canvas: { style: { cursor: '' } },
|
||||
screenSpaceCameraController: { enableInputs: true },
|
||||
pick: () => undefined,
|
||||
drillPick: () => [],
|
||||
},
|
||||
});
|
||||
const pointer = fakeInput(viewer);
|
||||
const services = {
|
||||
overlays: {
|
||||
setOverlayEntries: noop,
|
||||
setOverlaySourceVisible: noop,
|
||||
clearOverlaySource: noop,
|
||||
hitTestWorldOverlay: () => overlayHit,
|
||||
},
|
||||
render: { holdContinuousRender: noop, releaseContinuousRender: noop },
|
||||
};
|
||||
const state = createState({ services });
|
||||
const focused = [];
|
||||
const restoreFailure = { error: null };
|
||||
const parts = {
|
||||
panel: stub(),
|
||||
overlays: stub(),
|
||||
replay: stub(),
|
||||
launchPad: stub(),
|
||||
orbitRendering: stub(),
|
||||
selection: stub({
|
||||
setSelectedMission: (id) => focused.push(id),
|
||||
}),
|
||||
satelliteIntents: stub(),
|
||||
ingestion: stub({
|
||||
async restoreSatelliteDependency() {
|
||||
if (restoreFailure.error) throw restoreFailure.error;
|
||||
},
|
||||
}),
|
||||
rendering: stub({
|
||||
missionsShown: () => true,
|
||||
missionHitsAt: () => [],
|
||||
launchIdFromPicks: () => geometryLaunchId,
|
||||
launchMarkerAt: () => null,
|
||||
}),
|
||||
};
|
||||
const lifecycle = createLifecycle({
|
||||
state,
|
||||
services,
|
||||
parts,
|
||||
source: {},
|
||||
}).methods;
|
||||
lifecycle.init(viewer);
|
||||
state._enabled = true;
|
||||
state._launches = [{ id: 'L1' }, { id: 'L2' }];
|
||||
// Another layer's ambient click handler, as aircraft or the cockpit has.
|
||||
const ambient = [];
|
||||
const offAmbient = pointer.input.onClick((event) => ambient.push(event));
|
||||
t.after(async () => {
|
||||
restoreFailure.error = null;
|
||||
offAmbient();
|
||||
await lifecycle.destroy(viewer);
|
||||
pointer.input.destroy();
|
||||
});
|
||||
return {
|
||||
focused,
|
||||
ambient,
|
||||
state,
|
||||
lifecycle,
|
||||
viewer,
|
||||
input: pointer.input,
|
||||
restoreFailure,
|
||||
setHit(hit) {
|
||||
overlayHit = hit;
|
||||
},
|
||||
click: () => pointer.tap({ x: 40, y: 30 }),
|
||||
};
|
||||
}
|
||||
|
||||
const label = (
|
||||
entryId,
|
||||
sourceId = ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID,
|
||||
) => ({
|
||||
sourceId,
|
||||
entryId,
|
||||
});
|
||||
|
||||
test('a mission label click focuses its launch and stops the click there', (t) => {
|
||||
const r = rig(t, { overlayHit: label('launch:L2') });
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, ['L2']);
|
||||
assert.equal(r.ambient.length, 0, 'the layers beneath do not see it');
|
||||
|
||||
r.setHit(label('launch:L1', ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID));
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, ['L2', 'L1'], 'the selected label routes too');
|
||||
});
|
||||
|
||||
test('a mission picked on the globe is announced, after it is selected', (t) => {
|
||||
const r = rig(t, { overlayHit: label('launch:L2') });
|
||||
const picks = [];
|
||||
r.state._globePickListeners.add((id) => picks.push([id, [...r.focused]]));
|
||||
r.click();
|
||||
assert.deepEqual(picks, [['L2', ['L2']]], 'the label pick is announced');
|
||||
|
||||
r.setHit(null);
|
||||
r.click();
|
||||
assert.equal(picks.length, 1, 'a click on nothing announces nothing');
|
||||
});
|
||||
|
||||
test('a throwing globe-pick listener does not stop the pick', (t) => {
|
||||
const r = rig(t, { overlayHit: label('launch:L1') });
|
||||
const warn = console.warn;
|
||||
console.warn = noop;
|
||||
t.after(() => {
|
||||
console.warn = warn;
|
||||
});
|
||||
const heard = [];
|
||||
r.state._globePickListeners.add(() => {
|
||||
throw new Error('listener failure');
|
||||
});
|
||||
r.state._globePickListeners.add((id) => heard.push(id));
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, ['L1']);
|
||||
assert.deepEqual(heard, ['L1']);
|
||||
assert.equal(r.ambient.length, 0);
|
||||
});
|
||||
|
||||
test('a mission label for an unknown launch falls through to other layers', (t) => {
|
||||
const r = rig(t, {
|
||||
overlayHit: label('launch:gone'),
|
||||
geometryLaunchId: 'L1',
|
||||
});
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, [], 'nothing is focused');
|
||||
assert.equal(r.ambient.length, 1, 'other layers still get the click');
|
||||
});
|
||||
|
||||
test("another layer's label keeps the click above mission geometry", (t) => {
|
||||
// An aircraft label painted over a mission path.
|
||||
const r = rig(t, {
|
||||
overlayHit: { sourceId: 'aircraft-labels', entryId: 'launch:L1' },
|
||||
geometryLaunchId: 'L1',
|
||||
});
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, [], 'the mission under the label is not picked');
|
||||
assert.equal(r.ambient.length, 1, "the label's owner gets the click");
|
||||
|
||||
// With no label there, the same click picks the mission geometry.
|
||||
r.setHit(null);
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, ['L1']);
|
||||
});
|
||||
|
||||
test('a mission label leaves the click to the cockpit while it is on', (t) => {
|
||||
const r = rig(t, { overlayHit: label('launch:L2') });
|
||||
const previous = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: {
|
||||
body: { classList: { contains: (name) => name === 'cockpit-mode' } },
|
||||
},
|
||||
});
|
||||
try {
|
||||
r.click();
|
||||
} finally {
|
||||
if (previous) Object.defineProperty(globalThis, 'document', previous);
|
||||
else delete globalThis.document;
|
||||
}
|
||||
assert.deepEqual(r.focused, []);
|
||||
assert.equal(r.ambient.length, 1, 'the cockpit click handler gets it');
|
||||
});
|
||||
|
||||
test('destroy releases the click handlers when the Satellites restore fails', async (t) => {
|
||||
const r = rig(t, { overlayHit: label('launch:L2') });
|
||||
const before = r.input.subscriberCount();
|
||||
r.restoreFailure.error = new Error('injected Satellites restore failure');
|
||||
await assert.rejects(r.lifecycle.destroy(r.viewer), /injected/);
|
||||
assert.equal(r.state._inputSubscription, null);
|
||||
// The rest of teardown still ran before the failure was reported.
|
||||
assert.equal(r.state._viewer, null, 'the viewer is released');
|
||||
assert.deepEqual(r.state._launches, [], 'the records are dropped');
|
||||
assert.equal(r.state._dataManager, null, 'the manager is released');
|
||||
assert.ok(r.input.subscriberCount() < before, 'the handlers unsubscribed');
|
||||
r.click();
|
||||
assert.deepEqual(r.focused, [], 'a later label click reaches no mission');
|
||||
assert.equal(r.ambient.length, 1);
|
||||
});
|
||||
@@ -2,6 +2,10 @@ import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { canvasOf, findCamera, findFrame } from '../../render/rendererOf.js';
|
||||
import { worldClock } from '../../time/worldClock.js';
|
||||
import {
|
||||
ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID,
|
||||
ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID,
|
||||
} from './policy.js';
|
||||
|
||||
const HOVER_PICK_INTERVAL_MS = 120;
|
||||
|
||||
@@ -150,6 +154,22 @@ function restoreCameraView(viewer, view, landedView) {
|
||||
/** The longest name a timeline mark carries, as in the mission index. */
|
||||
const MARK_LABEL_LENGTH = 27;
|
||||
|
||||
/** Whether the cockpit view is on. */
|
||||
function cockpitActive() {
|
||||
return Boolean(
|
||||
globalThis.document?.body?.classList?.contains?.('cockpit-mode'),
|
||||
);
|
||||
}
|
||||
|
||||
function markerLaunchId(hit) {
|
||||
if (
|
||||
hit?.sourceId !== ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID &&
|
||||
hit?.sourceId !== ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID
|
||||
)
|
||||
return null;
|
||||
return hit.entryId.startsWith('launch:') ? hit.entryId.slice(7) : null;
|
||||
}
|
||||
|
||||
export function createLifecycle({
|
||||
state: layerState,
|
||||
services,
|
||||
@@ -157,6 +177,25 @@ export function createLifecycle({
|
||||
source,
|
||||
}) {
|
||||
const { holdContinuousRender, releaseContinuousRender } = services.render;
|
||||
const overlayAt = (position) =>
|
||||
services.overlays?.hitTestWorldOverlay?.(position?.x, position?.y);
|
||||
const missionsShown = () =>
|
||||
layerState._enabled && parts.rendering.missionsShown();
|
||||
const focusLaunch = (id) => {
|
||||
if (!id) return false;
|
||||
const launch = layerState._launches.find((entry) => entry.id === id);
|
||||
if (!launch) return false;
|
||||
parts.selection.setSelectedMission(launch.id);
|
||||
parts.selection.focusMission(launch);
|
||||
for (const listener of [...layerState._globePickListeners]) {
|
||||
try {
|
||||
listener(launch.id);
|
||||
} catch (error) {
|
||||
console.warn('[Data:RocketLaunches] globe pick listener failed', error);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
let hover = null;
|
||||
// While on, the launches loaded span the time from the first to the last,
|
||||
// each one a mark labelled with its mission's name (the launch's where it
|
||||
@@ -204,25 +243,38 @@ export function createLifecycle({
|
||||
layerState._orbitMatches = 0;
|
||||
parts.overlays.clearMissionOverlaySources();
|
||||
const input = inputFor(viewer);
|
||||
const overlayClicks = new WeakSet();
|
||||
const unsubscribeLabelClick = input.onOverlayClick((event) => {
|
||||
// The cockpit reads ambient clicks; a mission label must not take them.
|
||||
if (!missionsShown() || cockpitActive()) return false;
|
||||
const hit = overlayAt(event.screenPosition);
|
||||
if (!hit) return false;
|
||||
// Capture the painted hit before other handlers can invalidate the
|
||||
// overlay. An unrelated label keeps the click above mission geometry.
|
||||
overlayClicks.add(event);
|
||||
return focusLaunch(markerLaunchId(hit));
|
||||
});
|
||||
const unsubscribeClick = input.onClick((event) => {
|
||||
if (!layerState._enabled || !parts.rendering.missionsShown()) return;
|
||||
// The click's pick position (CSS px), as the click picked it.
|
||||
const launchId = parts.rendering.launchIdFromPicks(
|
||||
parts.rendering.missionHitsAt(event.position, 12),
|
||||
);
|
||||
if (!launchId) return;
|
||||
parts.selection.setSelectedMission(launchId);
|
||||
parts.selection.focusMission(
|
||||
layerState._launches.find((launch) => launch.id === launchId),
|
||||
if (!missionsShown() || overlayClicks.has(event)) return;
|
||||
focusLaunch(
|
||||
parts.rendering.launchIdFromPicks(
|
||||
parts.rendering.missionHitsAt(event.position, 12),
|
||||
),
|
||||
);
|
||||
});
|
||||
hover = createLaunchHover({
|
||||
viewer,
|
||||
enabled: () => layerState._enabled && parts.rendering.missionsShown(),
|
||||
launchAt: parts.rendering.launchMarkerAt,
|
||||
enabled: missionsShown,
|
||||
launchAt(position) {
|
||||
const hit = overlayAt(position);
|
||||
return hit
|
||||
? Boolean(markerLaunchId(hit))
|
||||
: parts.rendering.launchMarkerAt(position);
|
||||
},
|
||||
});
|
||||
const unsubscribeHover = input.onPointer('move', hover.move);
|
||||
layerState._inputSubscription = () => {
|
||||
unsubscribeLabelClick();
|
||||
unsubscribeClick();
|
||||
unsubscribeHover();
|
||||
};
|
||||
@@ -321,8 +373,8 @@ export function createLifecycle({
|
||||
parts.overlays.hideReplayVehicleOverlay();
|
||||
layerState._selectedLaunchId = null;
|
||||
parts.overlays.clearMissionOverlaySources();
|
||||
await parts.ingestion.restoreSatelliteDependency();
|
||||
parts.panel.renderMissionPanel();
|
||||
await parts.ingestion.restoreSatelliteDependency();
|
||||
layerState.coverageChanged();
|
||||
},
|
||||
|
||||
@@ -336,14 +388,22 @@ export function createLifecycle({
|
||||
layerState._enabled = false;
|
||||
layerState._lifecycleToken++;
|
||||
layerState._updateDirty = false;
|
||||
await parts.ingestion.restoreSatelliteDependency();
|
||||
// A failed Satellites restore still tears everything else down; the
|
||||
// failure is reported once teardown is complete.
|
||||
let restoreError = null;
|
||||
try {
|
||||
await parts.ingestion.restoreSatelliteDependency();
|
||||
} catch (error) {
|
||||
restoreError = error;
|
||||
}
|
||||
layerState._inputSubscription?.();
|
||||
layerState._inputSubscription = null;
|
||||
parts.satelliteIntents.connect(null);
|
||||
parts.panel.clearMissionRosterHover();
|
||||
parts.replay.stopMissionReplay();
|
||||
layerState._cameraReleased = true;
|
||||
parts.selection.stopMissionZoomAnchor();
|
||||
parts.ingestion.clearPostTleRetry();
|
||||
layerState._inputSubscription?.();
|
||||
layerState._inputSubscription = null;
|
||||
if (layerState._declutterHandler) layerState._declutterHandler();
|
||||
layerState._declutterHandler = null;
|
||||
parts.launchPad.destroyLaunchPadZonePrimitive();
|
||||
@@ -370,6 +430,7 @@ export function createLifecycle({
|
||||
layerState._satelliteStateBeforeMission = null;
|
||||
layerState._satelliteActivationPromise = null;
|
||||
layerState._dataManager = null;
|
||||
if (restoreError) throw restoreError;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
// The Data Layers row's previous/next mission controls, and the Satellites
|
||||
// restore an explicit Satellites action takes over.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createControls } from './controls.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createSatelliteIntents } from './satelliteIntents.js';
|
||||
|
||||
const roster = (...ids) => ({
|
||||
entries: ids.map((id, index) => ({ id, index, label: `Mission ${id}` })),
|
||||
});
|
||||
|
||||
function rig({ ids = ['A', 'B', 'C'], selected = null, enabled = true } = {}) {
|
||||
const panelListeners = new Set();
|
||||
const state = {
|
||||
_enabled: enabled,
|
||||
_selectedLaunchId: selected,
|
||||
_missionRosterView: ids ? roster(...ids) : null,
|
||||
};
|
||||
const parts = {
|
||||
panel: {
|
||||
selectMissionAt(index) {
|
||||
state._selectedLaunchId = state._missionRosterView.entries[index].id;
|
||||
},
|
||||
subscribePanel(listener) {
|
||||
panelListeners.add(listener);
|
||||
return () => panelListeners.delete(listener);
|
||||
},
|
||||
},
|
||||
};
|
||||
const { methods } = createControls({ state, services: {}, parts });
|
||||
return {
|
||||
state,
|
||||
methods,
|
||||
chip: (id) => methods.getRowControls().chips.find((c) => c.id === id),
|
||||
publish: (view) => {
|
||||
for (const listener of [...panelListeners]) listener(view);
|
||||
},
|
||||
listenerCount: () => panelListeners.size,
|
||||
};
|
||||
}
|
||||
|
||||
test('next and previous wrap around the roster', () => {
|
||||
const r = rig({ selected: 'C' });
|
||||
r.chip('next-mission').onClick();
|
||||
assert.equal(
|
||||
r.state._selectedLaunchId,
|
||||
'A',
|
||||
'next after the last is the first',
|
||||
);
|
||||
r.chip('previous-mission').onClick();
|
||||
assert.equal(
|
||||
r.state._selectedLaunchId,
|
||||
'C',
|
||||
'previous before the first is the last',
|
||||
);
|
||||
r.chip('previous-mission').onClick();
|
||||
assert.equal(r.state._selectedLaunchId, 'B');
|
||||
assert.match(r.methods.getRowControls().info, /^2 \/ 3 · Mission B$/);
|
||||
});
|
||||
|
||||
test('with nothing selected, next picks the first mission and previous the last', () => {
|
||||
const next = rig();
|
||||
next.chip('next-mission').onClick();
|
||||
assert.equal(next.state._selectedLaunchId, 'A');
|
||||
const previous = rig();
|
||||
previous.chip('previous-mission').onClick();
|
||||
assert.equal(previous.state._selectedLaunchId, 'C');
|
||||
});
|
||||
|
||||
test('the controls disable only when the one mission is already selected', () => {
|
||||
const only = rig({ ids: ['A'], selected: 'A' });
|
||||
assert.equal(only.chip('next-mission').disabled, true);
|
||||
assert.equal(only.chip('previous-mission').disabled, true);
|
||||
// One mission, not yet picked: the controls can still select it.
|
||||
const unpicked = rig({ ids: ['A'] });
|
||||
assert.equal(unpicked.chip('next-mission').disabled, false);
|
||||
unpicked.chip('next-mission').onClick();
|
||||
assert.equal(unpicked.state._selectedLaunchId, 'A');
|
||||
assert.equal(rig({ selected: 'B' }).chip('next-mission').disabled, false);
|
||||
});
|
||||
|
||||
test('there are no controls while the layer is off or the roster is empty', () => {
|
||||
assert.equal(rig({ enabled: false }).methods.getRowControls(), null);
|
||||
assert.equal(rig({ ids: [] }).methods.getRowControls(), null);
|
||||
assert.equal(rig({ ids: null }).methods.getRowControls(), null);
|
||||
// A stale click after the layer stops selects nothing.
|
||||
const r = rig({ selected: 'A' });
|
||||
const next = r.chip('next-mission');
|
||||
r.state._enabled = false;
|
||||
next.onClick();
|
||||
assert.equal(r.state._selectedLaunchId, 'A');
|
||||
});
|
||||
|
||||
test('the row listener fires only when the roster or the selection changes', () => {
|
||||
const r = rig();
|
||||
let calls = 0;
|
||||
r.methods.setRowControlsListener(() => calls++);
|
||||
const view = r.state._missionRosterView;
|
||||
r.publish({ roster: view });
|
||||
assert.equal(calls, 1, 'the first view is a change');
|
||||
r.publish({ roster: view });
|
||||
assert.equal(calls, 1, 'a replay or telemetry update is not');
|
||||
r.state._selectedLaunchId = 'B';
|
||||
r.publish({ roster: view });
|
||||
assert.equal(calls, 2, 'a new selection is');
|
||||
r.publish({ roster: roster('A', 'B') });
|
||||
assert.equal(calls, 3, 'a new roster is');
|
||||
|
||||
// A new listener replaces the old one; null removes it.
|
||||
let replaced = 0;
|
||||
r.methods.setRowControlsListener(() => replaced++);
|
||||
assert.equal(r.listenerCount(), 1);
|
||||
r.methods.setRowControlsListener(null);
|
||||
assert.equal(r.listenerCount(), 0);
|
||||
r.publish({ roster: roster('C') });
|
||||
assert.equal(calls, 3);
|
||||
assert.equal(replaced, 0);
|
||||
});
|
||||
|
||||
function satelliteRig({ enabledBefore }) {
|
||||
const calls = [];
|
||||
let satellitesOn = true;
|
||||
const manager = {
|
||||
layers: new Map([['satellites', { toggleChain: null }]]),
|
||||
waitForLayerIdle: async () => true,
|
||||
isEnabled: () => satellitesOn,
|
||||
isEffectivelyEnabled: (id) =>
|
||||
id === 'satellites' ? satellitesOn : id === 'rocket-launches',
|
||||
setLayerParams: (id, params) => calls.push(['params', id, params]),
|
||||
async setEnabled(id, enabled) {
|
||||
calls.push(['enabled', id, enabled]);
|
||||
satellitesOn = enabled;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
const state = {
|
||||
_dataManager: manager,
|
||||
_satelliteStateBeforeMission: {
|
||||
enabled: enabledBefore,
|
||||
params: { mode: 'before' },
|
||||
},
|
||||
_satelliteActivationPromise: null,
|
||||
};
|
||||
const parts = {
|
||||
policyHelpers: { satelliteParamsAfterSpaceMissions: (params) => params },
|
||||
};
|
||||
const ingestion = createIngestion({ state, services: {}, parts, source: {} });
|
||||
parts.satelliteIntents = createSatelliteIntents({ state });
|
||||
const { methods } = createControls({ state, services: {}, parts });
|
||||
return { state, calls, ingestion, methods, intents: parts.satelliteIntents };
|
||||
}
|
||||
|
||||
test('an accepted Satellites action keeps its visibility through mission exit', async () => {
|
||||
const r = satelliteRig({ enabledBefore: false });
|
||||
// The person turns Satellites on themselves while the missions are on.
|
||||
r.intents.handleVisibility({
|
||||
type: 'visibility',
|
||||
layerId: 'satellites',
|
||||
enabled: true,
|
||||
origin: 'user',
|
||||
});
|
||||
await r.ingestion.restoreSatelliteDependency();
|
||||
assert.deepEqual(
|
||||
r.calls,
|
||||
[['params', 'satellites', { mode: 'before' }]],
|
||||
'the parameters come back, the visibility is left alone',
|
||||
);
|
||||
assert.equal(r.state._satelliteStateBeforeMission, null);
|
||||
});
|
||||
|
||||
test('without a Satellites action the exit restores the pre-mission visibility', async () => {
|
||||
const r = satelliteRig({ enabledBefore: false });
|
||||
await r.ingestion.restoreSatelliteDependency();
|
||||
assert.deepEqual(r.calls, [
|
||||
['params', 'satellites', { mode: 'before' }],
|
||||
['enabled', 'satellites', false],
|
||||
]);
|
||||
});
|
||||
@@ -135,7 +135,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
|
||||
protected: selected,
|
||||
paintLane: selected ? 'selected' : 'ambient-label',
|
||||
collisionGroup: 'ambient-label',
|
||||
interactive: false,
|
||||
interactive: true,
|
||||
distanceScale: {
|
||||
near: 1000,
|
||||
nearValue: 1.08,
|
||||
|
||||
@@ -2,6 +2,9 @@ import { TWO_PI, toRadians } from '../../geo/vector.js';
|
||||
|
||||
export const WINDOW_DAYS = 30;
|
||||
|
||||
/** Longest Space Missions waits for pending Satellites work to settle. */
|
||||
export const SATELLITE_SETTLE_TIMEOUT_MS = 30000;
|
||||
|
||||
export const ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID = 'rocket-missions';
|
||||
|
||||
export const ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID =
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Space Missions owns its Satellites dependency. While the layer is on or
|
||||
* starting, an explicit Satellites action from the person (a Data Layers
|
||||
* click, a voice command) wins over the dependency:
|
||||
* - the mission teardown leaves Satellites as that action set it, and
|
||||
* - a Satellites OFF asked for after the newest Space Missions ON ends Space
|
||||
* Missions, which cannot replay without it.
|
||||
* Whether an OFF ends the missions depends on which of the two was asked for
|
||||
* first, not on which settles first, so request order is recorded when each
|
||||
* intent is published.
|
||||
*/
|
||||
const ORDERED_REQUEST_LAYER_IDS = new Set(['rocket-launches', 'satellites']);
|
||||
const LAYER_ID = 'rocket-launches';
|
||||
|
||||
function isExplicitOrigin(origin) {
|
||||
return origin === 'user' || origin === 'voice';
|
||||
}
|
||||
|
||||
export function createSatelliteIntents({ state: layerState }) {
|
||||
const requestOrder = new Map();
|
||||
let sequence = 0;
|
||||
let unsubscribe = null;
|
||||
/** The Space Missions stop a Satellites OFF started, while it runs. */
|
||||
let pendingStop = null;
|
||||
|
||||
/**
|
||||
* Whether an accepted Satellites OFF was requested after the newest Space
|
||||
* Missions ON. An OFF asked for before the entry belongs to the view the
|
||||
* entry started from, so the entry it races with is kept. Without request
|
||||
* records the OFF is treated as the newer action.
|
||||
*/
|
||||
function offFollowsMissionsEntry(change) {
|
||||
const satellites = requestOrder.get('satellites');
|
||||
const missions = requestOrder.get(LAYER_ID);
|
||||
if (satellites?.intentEpoch !== change.intentEpoch || !missions?.enabled)
|
||||
return true;
|
||||
return satellites.sequence > missions.sequence;
|
||||
}
|
||||
|
||||
function recordRequest(change) {
|
||||
if (!ORDERED_REQUEST_LAYER_IDS.has(change?.layerId)) return;
|
||||
requestOrder.set(change.layerId, {
|
||||
enabled: change.enabled,
|
||||
intentEpoch: change.intentEpoch,
|
||||
sequence: ++sequence,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hand an explicit Satellites action its visibility while Space Missions is
|
||||
* on or starting.
|
||||
* @returns {Promise<boolean>|boolean} Whether Space Missions was asked to stop.
|
||||
*/
|
||||
function handleVisibility(change) {
|
||||
const manager = layerState._dataManager;
|
||||
if (
|
||||
!manager ||
|
||||
change?.type !== 'visibility' ||
|
||||
change.layerId !== 'satellites' ||
|
||||
!isExplicitOrigin(change.origin)
|
||||
)
|
||||
return false;
|
||||
const missionsRequested = manager.isEffectivelyEnabled(LAYER_ID);
|
||||
if (!missionsRequested && !layerState._satelliteStateBeforeMission)
|
||||
return false;
|
||||
// A newer Satellites request is queued; it will report for itself.
|
||||
if (manager.isEffectivelyEnabled('satellites') !== change.enabled)
|
||||
return false;
|
||||
// The person's choice survives the mission teardown.
|
||||
const previous = layerState._satelliteStateBeforeMission;
|
||||
if (previous) previous.restoreVisibility = false;
|
||||
if (
|
||||
change.enabled ||
|
||||
!missionsRequested ||
|
||||
!offFollowsMissionsEntry(change)
|
||||
)
|
||||
return false;
|
||||
const stop = Promise.resolve(
|
||||
manager.setEnabled(LAYER_ID, false, { origin: change.origin }),
|
||||
)
|
||||
.then(() => true)
|
||||
.catch((error) => {
|
||||
console.warn(
|
||||
'[Data:RocketLaunches] Satellites OFF could not stop Space Missions',
|
||||
error,
|
||||
);
|
||||
return false;
|
||||
})
|
||||
.finally(() => {
|
||||
if (pendingStop === stop) pendingStop = null;
|
||||
});
|
||||
pendingStop = stop;
|
||||
return stop;
|
||||
}
|
||||
|
||||
/** Settle once a Satellites OFF has finished stopping Space Missions. */
|
||||
function settled() {
|
||||
return pendingStop ?? Promise.resolve(false);
|
||||
}
|
||||
|
||||
/** Follow the manager the layer is attached to; null detaches. */
|
||||
function connect(manager) {
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
requestOrder.clear();
|
||||
if (!manager) return;
|
||||
const unsubscribeRequests =
|
||||
manager.subscribeVisibilityRequests?.(recordRequest) ?? null;
|
||||
const unsubscribeChanges =
|
||||
manager.subscribe?.((change) => {
|
||||
void handleVisibility(change);
|
||||
}) ?? null;
|
||||
unsubscribe = () => {
|
||||
unsubscribeRequests?.();
|
||||
unsubscribeChanges?.();
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
connect,
|
||||
settled,
|
||||
handleVisibility,
|
||||
recordRequest,
|
||||
offFollowsMissionsEntry,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// An explicit Satellites action while Space Missions is on or starting.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSatelliteIntents } from './satelliteIntents.js';
|
||||
|
||||
/** A manager whose effective and settled state can differ. */
|
||||
function rig({ effective, snapshot = { enabled: false } } = {}) {
|
||||
const calls = [];
|
||||
const listeners = { requests: new Set(), changes: new Set() };
|
||||
const manager = {
|
||||
isEffectivelyEnabled: (id) => Boolean(effective[id]),
|
||||
async setEnabled(id, enabled, options) {
|
||||
calls.push([id, enabled, options?.origin]);
|
||||
return true;
|
||||
},
|
||||
subscribeVisibilityRequests(listener) {
|
||||
listeners.requests.add(listener);
|
||||
return () => listeners.requests.delete(listener);
|
||||
},
|
||||
subscribe(listener) {
|
||||
listeners.changes.add(listener);
|
||||
return () => listeners.changes.delete(listener);
|
||||
},
|
||||
};
|
||||
const state = {
|
||||
_dataManager: manager,
|
||||
_satelliteStateBeforeMission: snapshot,
|
||||
};
|
||||
const intents = createSatelliteIntents({ state });
|
||||
intents.connect(manager);
|
||||
const request = (layerId, enabled, intentEpoch) => {
|
||||
for (const listener of listeners.requests)
|
||||
listener({
|
||||
type: 'visibility-requested',
|
||||
layerId,
|
||||
enabled,
|
||||
intentEpoch,
|
||||
});
|
||||
};
|
||||
const settle = (change) => {
|
||||
for (const listener of listeners.changes) listener(change);
|
||||
};
|
||||
return { calls, intents, listeners, manager, state, request, settle };
|
||||
}
|
||||
|
||||
const satellitesOff = {
|
||||
type: 'visibility',
|
||||
layerId: 'satellites',
|
||||
enabled: false,
|
||||
origin: 'user',
|
||||
intentEpoch: 7,
|
||||
};
|
||||
|
||||
test('a Satellites OFF asked for after the mission start ends Space Missions', async () => {
|
||||
const r = rig({ effective: { satellites: false, 'rocket-launches': true } });
|
||||
r.request('rocket-launches', true, 3);
|
||||
r.request('satellites', false, 7);
|
||||
r.settle(satellitesOff);
|
||||
assert.equal(await r.intents.settled(), true);
|
||||
assert.deepEqual(r.calls, [['rocket-launches', false, 'user']]);
|
||||
assert.equal(
|
||||
r.state._satelliteStateBeforeMission.restoreVisibility,
|
||||
false,
|
||||
'the teardown leaves Satellites as the person set it',
|
||||
);
|
||||
});
|
||||
|
||||
test('a Satellites OFF asked for before the mission start leaves the start alone', () => {
|
||||
const r = rig({ effective: { satellites: false, 'rocket-launches': true } });
|
||||
r.request('satellites', false, 7);
|
||||
r.request('rocket-launches', true, 3);
|
||||
r.settle(satellitesOff);
|
||||
assert.deepEqual(r.calls, []);
|
||||
assert.equal(r.state._satelliteStateBeforeMission.restoreVisibility, false);
|
||||
});
|
||||
|
||||
test('a Satellites OFF without request records is treated as the newer action', async () => {
|
||||
const r = rig({ effective: { satellites: false, 'rocket-launches': true } });
|
||||
assert.equal(await r.intents.handleVisibility(satellitesOff), true);
|
||||
assert.deepEqual(r.calls, [['rocket-launches', false, 'user']]);
|
||||
});
|
||||
|
||||
test('a superseded Satellites event is left to the newer request', () => {
|
||||
// A newer Satellites ON is queued, but this OFF has already settled.
|
||||
const r = rig({ effective: { satellites: true, 'rocket-launches': true } });
|
||||
assert.equal(r.intents.handleVisibility(satellitesOff), false);
|
||||
assert.deepEqual(r.calls, []);
|
||||
assert.equal(
|
||||
r.state._satelliteStateBeforeMission.restoreVisibility,
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
test('a Satellites ON while the missions are on is kept through their exit', () => {
|
||||
const r = rig({ effective: { satellites: true, 'rocket-launches': true } });
|
||||
assert.equal(
|
||||
r.intents.handleVisibility({ ...satellitesOff, enabled: true }),
|
||||
false,
|
||||
);
|
||||
assert.deepEqual(r.calls, []);
|
||||
assert.equal(r.state._satelliteStateBeforeMission.restoreVisibility, false);
|
||||
});
|
||||
|
||||
test('only direct user and voice Satellites actions count', () => {
|
||||
// Settled: a scene, story, preset or other programmatic Satellites OFF
|
||||
// neither ends Space Missions nor survives its teardown.
|
||||
for (const origin of [
|
||||
'programmatic',
|
||||
'context-restore',
|
||||
'dependency',
|
||||
'scene',
|
||||
'tool',
|
||||
]) {
|
||||
const r = rig({
|
||||
effective: { satellites: false, 'rocket-launches': true },
|
||||
});
|
||||
assert.equal(
|
||||
r.intents.handleVisibility({ ...satellitesOff, origin }),
|
||||
false,
|
||||
);
|
||||
assert.deepEqual(r.calls, []);
|
||||
assert.equal(
|
||||
r.state._satelliteStateBeforeMission.restoreVisibility,
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
const voice = rig({
|
||||
effective: { satellites: false, 'rocket-launches': true },
|
||||
});
|
||||
voice.settle({ ...satellitesOff, origin: 'voice' });
|
||||
assert.deepEqual(voice.calls, [['rocket-launches', false, 'voice']]);
|
||||
});
|
||||
|
||||
test('with Space Missions off, a Satellites action is not its business', () => {
|
||||
const r = rig({ effective: { satellites: false }, snapshot: null });
|
||||
assert.equal(r.intents.handleVisibility(satellitesOff), false);
|
||||
assert.deepEqual(r.calls, []);
|
||||
});
|
||||
|
||||
test('reconnecting and detaching release each manager subscription', () => {
|
||||
const r = rig({ effective: {} });
|
||||
assert.equal(r.listeners.requests.size, 1);
|
||||
assert.equal(r.listeners.changes.size, 1);
|
||||
r.intents.connect(r.manager);
|
||||
assert.equal(r.listeners.requests.size, 1, 'no duplicate subscription');
|
||||
assert.equal(r.listeners.changes.size, 1);
|
||||
r.intents.connect(null);
|
||||
assert.equal(r.listeners.requests.size, 0);
|
||||
assert.equal(r.listeners.changes.size, 0);
|
||||
});
|
||||
|
||||
test('a failed stop is reported, not thrown', async () => {
|
||||
const r = rig({ effective: { satellites: false, 'rocket-launches': true } });
|
||||
r.manager.setEnabled = async () => {
|
||||
throw new Error('injected stop failure');
|
||||
};
|
||||
const warn = console.warn;
|
||||
const warnings = [];
|
||||
console.warn = (...args) => warnings.push(args);
|
||||
try {
|
||||
assert.equal(await r.intents.handleVisibility(satellitesOff), false);
|
||||
} finally {
|
||||
console.warn = warn;
|
||||
}
|
||||
assert.equal(warnings.length, 1);
|
||||
assert.equal(await r.intents.settled(), false, 'nothing left pending');
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { worldClock, worldTimeFor } from '../../time/worldClock.js';
|
||||
import { SATELLITE_SETTLE_TIMEOUT_MS } from './policy.js';
|
||||
|
||||
export function createState({ services }) {
|
||||
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
|
||||
@@ -20,8 +21,6 @@ export function createState({ services }) {
|
||||
|
||||
state._lastError = null;
|
||||
|
||||
state._lastErrorAt = null;
|
||||
|
||||
state._entryCameraView = null;
|
||||
|
||||
state._entryLandedView = null;
|
||||
@@ -53,6 +52,9 @@ export function createState({ services }) {
|
||||
|
||||
state._lifecycleToken = 0;
|
||||
|
||||
/** Bound on waiting for pending Satellites work around a mission. */
|
||||
state.satelliteSettleTimeoutMs = SATELLITE_SETTLE_TIMEOUT_MS;
|
||||
|
||||
state._enabled = false;
|
||||
|
||||
state._selectedLaunchId = null;
|
||||
@@ -68,6 +70,7 @@ export function createState({ services }) {
|
||||
state._missionPanelSignature = null;
|
||||
|
||||
state._missionPanelListeners = new Set();
|
||||
state._globePickListeners = new Set();
|
||||
|
||||
state._missionRosterView = null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user