Keep history entries untouched by unfinished globe picks and restore each visited entry's layers

A picked engine now lives in the switch until it runs; only then is the
address written, so a pick superseded by Back or one that fails rewrites no
entry. An engine-changing history visit holds the outgoing share link, which
neither restores nor writes the visited entry, and the running engine takes
the address back once the switch settles, restoring any entry visited while
it was held or not yet listening. Handed-off layers keep running where the
incoming address agrees with the outgoing one and follow a visited entry
where it differs. A failed recovery keeps the error on the loading screen
with an engine picker for a retry, and a failing reveal of the new globe no
longer blocks the cover removal or later requests.
This commit is contained in:
German Khokhlov committed 2026-11-03 15:24:20 +04:00
1 parent 9cc34e324f
commit a066a2d1ca
10 files changed
+539 -113

No files matched your search

+22 -1
View File
@@ -45,6 +45,24 @@ function currentLayerOutcome(dataManager, layerId) {
};
}
/**
* Whether a layer handed off by an engine switch runs on the incoming engine.
* The handoff records the layer's running state and whether the outgoing
* address listed it. Where the incoming address agrees with that, the layer
* keeps running as it was, operational intents included (a Contacts session
* runs layers its address never lists). Where it differs, the person visited
* an entry with another layer set (Back/Forward), and the entry wins, as it
* does for a same-engine Back.
* @param {{enabled?: boolean, durable?: boolean}|undefined} live
* @param {boolean} addressEnabled
*/
export function handoffTargetEnabled(live, addressEnabled) {
if (typeof live?.enabled !== 'boolean') return addressEnabled;
if (typeof live.durable === 'boolean' && live.durable !== addressEnabled)
return addressEnabled;
return live.enabled;
}
/**
* Owns durable user layer preferences independently from transient runtime
* choreography, and coordinates passive post-registration restoration.
@@ -382,7 +400,10 @@ export class LayerStateCoordinator {
LAYER_STATE_REGISTRY.map(async (entry) => {
const controller = controllers.get(entry.id);
const live = handoffLayers?.get(entry.id);
const targetEnabled = live?.enabled ?? enabled.has(entry.id);
const targetEnabled = handoffTargetEnabled(
live,
enabled.has(entry.id),
);
// A same-document engine choice retains operational layer intents.
// The share still owns durable preferences and later history visits.
if (live && this.dataManager.layers.get(entry.id) === live.entry &&