feat(app): a host names the layers a bare address starts with

createApplicationControls takes startLayers, the layer ids that turn on when
the address carries no link (none by default). They restore through the
passive start-up path, so they are never written as the user's own choice, and
a link's own layers always win.
This commit is contained in:
Sameh Khamis committed 2026-11-19 14:19:45 -08:00
1 parent e02f6c6e39
commit ca98ed1919
6 files changed
+66 -1

No files matched your search

+3
View File
@@ -8824,6 +8824,9 @@ remembers" are different promises:
a link restores what its hash carries, and a bare URL starts with the default
layers and options (`src/ui/shareRestoration.js` passes
`allowLocalState: false`), so clearing the address always resets the view.
A host may name the layers a bare URL starts with (`startLayers` on
`createApplicationControls`, e.g. `['flights', 'satellites']`); they are
restored passively, never written to storage, and a link's own layers win.
- **Detection mode/density and scope feather have NO storage key at all.** Their
only durable carrier is the URL hash (`dm`/`dd`, `scf`), written on a 500 ms
debounce. A same-URL reload therefore keeps them only if that debounce already
+4
View File
@@ -21,6 +21,8 @@ export { START_VIEW };
* `homeView` is where the title's logo goes back to (with the clock live): the
* start view unless given, for a host whose `startView` only carries a view
* across a rebuild.
* `startLayers` are the layer ids a bare address (one that carries no link)
* starts with: none by default; a host may pass `['flights', 'satellites']`.
* `services.cockpitSubjects` adds the application's own first-person subjects
* to the Cockpit (src/cockpitSubjectProviders.js).
*/
@@ -36,6 +38,7 @@ export function createApplicationControls({
localePicker = true,
startView = START_VIEW,
homeView = startView,
startLayers = [],
}) {
// Every boot starts from the same view, before share restoration flies on.
applyStartView(viewer, startView);
@@ -59,6 +62,7 @@ export function createApplicationControls({
initialShareCode,
localePicker,
homeView,
startLayers,
});
defer(() => styleManager.orbitController.stop());
defer(() => styleManager.hud.destroy());
+43
View File
@@ -3231,3 +3231,46 @@ test('an application with every layer registered keeps every requested layer', a
]);
coordinator.destroy();
});
test('start layers turn on when nothing names any, and are never written as the user choice', async () => {
const storage = memoryStorage();
const manager = productionManager();
const coordinator = new LayerStateCoordinator(manager, shareSink(), {
storage,
});
const results = await coordinator.start({
allowLocalState: false,
startLayerIds: ['earthquakes', 'traffic', 'not-a-layer'],
});
assert.equal(coordinator.source, 'start');
assert.deepEqual(coordinator.getDurableState().enabledLayerIds, [
'earthquakes',
'traffic',
]);
assert.equal(manager.isEnabled('earthquakes'), true);
assert.equal(manager.isEnabled('traffic'), true);
assert.equal(
results.every((result) => result.persistenceWrite === false),
true,
);
assert.deepEqual(storage.writes, []);
coordinator.destroy();
});
test('a shared layer payload wins over start layers', async () => {
const manager = productionManager();
const coordinator = new LayerStateCoordinator(manager, shareSink(), {
storage: memoryStorage(),
});
const shared = createDefaultLayerState();
shared.enabledLayerIds = ['radio'];
await coordinator.start({
shareLayerState: shared,
allowLocalState: false,
startLayerIds: ['earthquakes'],
});
assert.equal(coordinator.source, 'share');
assert.deepEqual(coordinator.getDurableState().enabledLayerIds, ['radio']);
assert.equal(manager.isEnabled('earthquakes'), false);
coordinator.destroy();
});
+8 -1
View File
@@ -103,6 +103,7 @@ export class LayerStateCoordinator {
shareLayerState = null,
allowLocalState = true,
shareCreatedAtMs = null,
startLayerIds = [],
} = {}) {
if (this._destroyed)
throw new Error('Layer-state coordinator is destroyed');
@@ -125,7 +126,13 @@ export class LayerStateCoordinator {
selected = this._normalize(stored);
this._source = 'local';
}
} else {
}
if (!selected && startLayerIds.length) {
// The layers the application starts with when nothing names any:
// restored passively, so they are never written as the user's choice.
selected = this._normalize({ enabledLayerIds: startLayerIds });
this._source = 'start';
} else if (!selected && !allowLocalState) {
// A valid historical camera/style share with no v2 layer payload keeps
// the exact legacy default-layer behavior. It must not inherit an
// unrelated recipient's saved local layer preferences.
+4
View File
@@ -117,6 +117,8 @@ export class StyleManager extends ShellFacade {
* @param {{lon: number, lat: number, height: number, heading?: number,
* pitch?: number}|null} [options.homeView] - where the title's logo goes
* back to (degrees): the view the app started from.
* @param {string[]} [options.startLayers] - the layers a bare address (one
* that carries no link) starts with; none by default.
*/
constructor(
viewer,
@@ -128,6 +130,7 @@ export class StyleManager extends ShellFacade {
initialShareCode = null,
localePicker = true,
homeView = null,
startLayers = [],
} = {},
) {
super();
@@ -256,6 +259,7 @@ export class StyleManager extends ShellFacade {
updateFeedback: () => this._updateGlobalLoadingFeedback(),
applyFollowOffset: (followed, offset) =>
applyShareFollowOffset(viewer, followed, offset),
startLayers,
});
this._visualSettings = new VisualSettings({
+4
View File
@@ -167,7 +167,10 @@ export class ShareRestoration {
feedback,
updateFeedback,
applyFollowOffset = null,
startLayers = [],
}) {
// The layers a bare address starts with; a link names its own.
this._startLayers = startLayers;
Object.assign(this, {
viewer,
navigation,
@@ -421,6 +424,7 @@ export class ShareRestoration {
// with the default layers. Saved layer choices never come back on
// their own, so clearing the address always resets the view.
allowLocalState: false,
startLayerIds: this._initialShareState ? [] : this._startLayers,
});
if (this._initialShareSelectionSuperseded) {
this._layerStateCoordinator.cancelPendingShareTracking(