mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
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]>
226 lines
7.7 KiB
JavaScript
226 lines
7.7 KiB
JavaScript
import {
|
|
contextAllowedLayerIds,
|
|
mergeContextTransitionErrors,
|
|
} from '../contextModePolicy.js';
|
|
|
|
export async function _selectContextMode(
|
|
mode,
|
|
{ notificationToken = null, signal = null } = {},
|
|
) {
|
|
if (this.destroyed || !this._dataManager) return false;
|
|
if (this._clearSelectedLayersPromise) return false;
|
|
this._contextTransitionFailedLayerIds = [];
|
|
const generation = ++this._contextModeGeneration;
|
|
const isCurrent = () =>
|
|
!this.destroyed && generation === this._contextModeGeneration;
|
|
this._contextModeChanging = true;
|
|
this._syncContextModeButtons();
|
|
try {
|
|
// Cockpit does not need Contacts, so leaving it keeps the view; the
|
|
// restore below ends it only by turning off the layer it rides. Another
|
|
// mode takes the camera, so switching to one ends it.
|
|
if (mode && mode !== 'flights' && this.cockpitView?.active) {
|
|
this.cockpitView.exit({ restoreTracking: false });
|
|
}
|
|
if (!mode) {
|
|
this._contextMode = null;
|
|
this._syncContextModeButtons();
|
|
await this._restoreContextSession({ notificationToken, signal });
|
|
return isCurrent();
|
|
}
|
|
// A cross-mode switch dismantles the prior mode BEFORE the new one is
|
|
// committed. If the caller aborts in that window the switch never lands,
|
|
// and the resting state is Context OFF — reported as such by
|
|
// setContextMode rather than dressed up as a clean cancellation. See the
|
|
// note above _restoreContextSessionAfterLayerSettles.
|
|
const crossModeSwitch = Boolean(
|
|
this._contextMode && this._contextMode !== mode,
|
|
);
|
|
if (crossModeSwitch) {
|
|
this._contextMode = null;
|
|
await this._restoreContextSession({ notificationToken, signal });
|
|
if (!isCurrent()) return false;
|
|
if (signal?.aborted) return false;
|
|
}
|
|
this._captureContextSessionSnapshot();
|
|
this._contextMode = mode;
|
|
this._syncContextModeButtons();
|
|
try {
|
|
await this._clearLayersOutsideContextMode(mode, {
|
|
notificationToken,
|
|
signal,
|
|
});
|
|
} catch (error) {
|
|
if (!isCurrent()) return false;
|
|
let transitionError = error;
|
|
console.warn(`[Context] ${mode} isolation failed`, error);
|
|
this._contextMode = null;
|
|
this._syncContextModeButtons();
|
|
try {
|
|
await this._restoreContextSession({ notificationToken });
|
|
} catch (restoreError) {
|
|
transitionError = mergeContextTransitionErrors(
|
|
transitionError,
|
|
restoreError,
|
|
);
|
|
this._contextTransitionFailedLayerIds = [
|
|
...(transitionError.failedLayerIds || []),
|
|
];
|
|
throw transitionError;
|
|
}
|
|
this._contextTransitionFailedLayerIds = [
|
|
...(transitionError?.failedLayerIds || []),
|
|
];
|
|
return false;
|
|
}
|
|
if (!isCurrent()) return false;
|
|
// Entry is one transaction: isolation succeeded above, so a failed mode
|
|
// activation must roll the cleared layers back instead of stranding the
|
|
// user in a half-entered mode with an orphaned snapshot.
|
|
const entryLayerId = 'military-awareness';
|
|
this._dataManager.setLayerParams(entryLayerId, { passive: false });
|
|
let activated = false;
|
|
let activationError = null;
|
|
let activationIntent = null;
|
|
let terminalIntentOutcome = null;
|
|
try {
|
|
activationIntent = this._dataManager._setEnabledWithIntent(
|
|
entryLayerId,
|
|
true,
|
|
{ notificationToken, ...(signal ? { signal } : {}) },
|
|
);
|
|
activated = await activationIntent.promise;
|
|
terminalIntentOutcome =
|
|
await this._dataManager._waitForVisibilityIntent?.(
|
|
entryLayerId,
|
|
activationIntent.intentEpoch,
|
|
);
|
|
} catch (error) {
|
|
activationError = error;
|
|
}
|
|
if (!isCurrent()) return false;
|
|
if (
|
|
activationError ||
|
|
activated === false ||
|
|
!this._dataManager.isEnabled(entryLayerId)
|
|
) {
|
|
const cancelledAndSettled =
|
|
terminalIntentOutcome?.succeeded === false &&
|
|
['caller-abort', 'resource-abort', 'superseded'].includes(
|
|
terminalIntentOutcome.cancellationReason,
|
|
);
|
|
let transitionError = null;
|
|
if (!cancelledAndSettled) {
|
|
transitionError =
|
|
activationError instanceof Error
|
|
? activationError
|
|
: new Error(`Context activation failed for: ${entryLayerId}`);
|
|
transitionError.failedLayerIds = [
|
|
...new Set([...(transitionError.failedLayerIds || []), entryLayerId]),
|
|
];
|
|
this._contextTransitionFailedLayerIds = [
|
|
...transitionError.failedLayerIds,
|
|
];
|
|
console.warn(
|
|
`[Context] ${mode} activation failed; restoring previous layers`,
|
|
activationError || 'not enabled',
|
|
);
|
|
}
|
|
this._contextMode = null;
|
|
this._syncContextModeButtons();
|
|
try {
|
|
await this._restoreContextSession({
|
|
excludeLayerIds: [entryLayerId],
|
|
notificationToken,
|
|
});
|
|
} catch (restoreError) {
|
|
transitionError = mergeContextTransitionErrors(
|
|
transitionError,
|
|
restoreError,
|
|
);
|
|
this._contextTransitionFailedLayerIds = [
|
|
...(transitionError?.failedLayerIds || []),
|
|
];
|
|
throw transitionError;
|
|
}
|
|
// `null` means the requested entry was cancelled and its exact rollback
|
|
// completed. The action wrapper treats that as a silent non-commit,
|
|
// while callers still require literal `true` before expanding Context.
|
|
return cancelledAndSettled ? null : false;
|
|
}
|
|
return true;
|
|
} finally {
|
|
if (isCurrent()) {
|
|
this._contextModeChanging = false;
|
|
this._syncContextModeButtons();
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function _deactivateContextForLayerChange({
|
|
notificationToken = null,
|
|
} = {}) {
|
|
this._contextModeGeneration += 1;
|
|
this._contextModeChanging = true;
|
|
this._contextMode = null;
|
|
// A layer turned off ends Contacts but not the Cockpit: the view ends only
|
|
// when the layer it rides goes off (see _handleContextLayerChange).
|
|
this._syncContextModeButtons();
|
|
try {
|
|
await this._restoreContextSession({ notificationToken });
|
|
} finally {
|
|
this._contextModeChanging = false;
|
|
this._syncContextModeButtons();
|
|
}
|
|
}
|
|
|
|
export async function _clearLayersOutsideContextMode(
|
|
mode = null,
|
|
{ notificationToken = null, signal = null } = {},
|
|
) {
|
|
const allowed = contextAllowedLayerIds(mode);
|
|
const pending = [];
|
|
// Panels read this while their layer goes off (suspendsLayer): a layer
|
|
// isolation switches off is suspended, not switched off by the user.
|
|
const isolating = [];
|
|
let results;
|
|
try {
|
|
for (const [layerId] of this._dataManager.layers || []) {
|
|
// Effective visibility: a disallowed layer still mid-ENABLING must be
|
|
// isolated too, or it settles ON inside the exclusive mode.
|
|
if (
|
|
!allowed.has(layerId) &&
|
|
this._dataManager.isEffectivelyEnabled(layerId)
|
|
) {
|
|
if (!this._isolatingLayerIds.has(layerId)) {
|
|
this._isolatingLayerIds.add(layerId);
|
|
isolating.push(layerId);
|
|
}
|
|
pending.push({
|
|
layerId,
|
|
transition: this._dataManager.setEnabled(layerId, false, {
|
|
notificationToken,
|
|
...(signal ? { signal } : {}),
|
|
}),
|
|
});
|
|
}
|
|
}
|
|
results = await Promise.all(pending.map(({ transition }) => transition));
|
|
} finally {
|
|
for (const layerId of isolating) this._isolatingLayerIds.delete(layerId);
|
|
}
|
|
const failed = pending
|
|
.filter(
|
|
({ layerId }, index) =>
|
|
results[index] === false || this._dataManager.isEnabled(layerId),
|
|
)
|
|
.map(({ layerId }) => layerId);
|
|
if (failed.length > 0) {
|
|
const error = new Error(
|
|
`Context isolation failed for: ${failed.join(', ')}`,
|
|
);
|
|
error.failedLayerIds = failed;
|
|
throw error;
|
|
}
|
|
}
|