mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
fix: prevent stopped Cockpit briefings from restarting
This commit is contained in:
1 parent
152d3e2352
commit
393c31d86e
2 files changed
+50
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
} from './cockpitPresentation.js';
|
||||
|
||||
export function showBriefPage(index, { manual = false } = {}) {
|
||||
if (this.destroyed) return;
|
||||
const count = COCKPIT_BRIEF_PAGES.length;
|
||||
this.briefPageIndex = ((Number(index) % count) + count) % count;
|
||||
const page = COCKPIT_BRIEF_PAGES[this.briefPageIndex];
|
||||
@@ -41,6 +42,7 @@ export function showBriefPage(index, { manual = false } = {}) {
|
||||
}
|
||||
|
||||
export function setBriefAutoRotate(enabled) {
|
||||
if (this.destroyed) return;
|
||||
this.briefAutoRotateEnabled = Boolean(enabled);
|
||||
if (this.briefAutoToggle) {
|
||||
this.briefAutoToggle.setAttribute(
|
||||
@@ -60,6 +62,7 @@ export function setBriefAutoRotate(enabled) {
|
||||
}
|
||||
|
||||
export function startBriefRotation({ reset = false } = {}) {
|
||||
if (this.destroyed) return;
|
||||
if (reset) this.stopBriefRotation();
|
||||
if (
|
||||
!this.briefAutoRotateEnabled ||
|
||||
@@ -71,6 +74,7 @@ export function startBriefRotation({ reset = false } = {}) {
|
||||
return;
|
||||
this.briefTimer = window.setTimeout(() => {
|
||||
this.briefTimer = null;
|
||||
if (this.destroyed) return;
|
||||
const hasPointer = this.signalStream?.matches(':hover') === true;
|
||||
const hasFocus =
|
||||
this.signalStream?.contains(document.activeElement) === true;
|
||||
@@ -99,6 +103,7 @@ export function updateLocalPosition(info) {
|
||||
}
|
||||
|
||||
export function maybeRefreshRegionalBrief(info) {
|
||||
if (this.destroyed) return;
|
||||
if (
|
||||
!this.active ||
|
||||
!Number.isFinite(info.latitude) ||
|
||||
|
||||
@@ -164,3 +164,48 @@ test('stopping Cockpit revokes camera actions before deferred disposal releases
|
||||
env.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('stopped Cockpit cannot rearm briefing rotation or request a fresh region', () => {
|
||||
const env = environment();
|
||||
try {
|
||||
const frames = new Map();
|
||||
let next = 0;
|
||||
let fetches = 0;
|
||||
let paints = 0;
|
||||
env.viewer.scene.screenSpaceCameraController.enableInputs = true;
|
||||
window.setTimeout = (callback) => {
|
||||
frames.set(++next, callback);
|
||||
return next;
|
||||
};
|
||||
window.clearTimeout = (id) => frames.delete(id);
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
services: {
|
||||
regionalDistanceM: () => Infinity,
|
||||
fetchRegionalBrief: () => {
|
||||
fetches++;
|
||||
return Promise.resolve({ articles: [] });
|
||||
},
|
||||
releaseContinuousRender() {},
|
||||
},
|
||||
});
|
||||
owner.active = true;
|
||||
owner.showBriefPage = () => {
|
||||
paints++;
|
||||
};
|
||||
owner.setBriefAutoRotate(true);
|
||||
assert.equal(frames.size, 1);
|
||||
const queued = [...frames.values()][0];
|
||||
owner.stop();
|
||||
assert.equal(frames.size, 0);
|
||||
queued();
|
||||
owner.setBriefAutoRotate(true);
|
||||
owner.startBriefRotation();
|
||||
owner.maybeRefreshRegionalBrief({ latitude: 30, longitude: -97 });
|
||||
assert.equal(frames.size, 0);
|
||||
assert.equal(paints, 0);
|
||||
assert.equal(fetches, 0);
|
||||
owner.dispose();
|
||||
} finally {
|
||||
env.restore();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user