mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
fix(cctv): keep the camera card's bigger view refreshing
An open bigger view now counts as a viewer of the camera's still, so it keeps refreshing after the layout turns phone and the Cameras sheet is not the one open. The card releases it in the watcher's cleanup, which also runs when the card unmounts in the same tick the popup closes.
This commit is contained in:
1 parent
d19ae89630
commit
2c5f9f89f7
5 files changed
+142
-12
No files matched your search
@@ -2007,7 +2007,8 @@ calibrating a camera bypasses visibility and the usual refresh interval, but
|
||||
still waits for an in-flight request and the provider's minimum interval.
|
||||
The panel's still and live video run only while the tab is visible and the
|
||||
panel is open (on phones, the Cameras sheet). The still also loads while
|
||||
Context shows the camera's card (on phones, the Context sheet).
|
||||
Context shows the camera's card (on phones, the Context sheet) or its bigger
|
||||
view is open.
|
||||
|
||||
Traffic owns its rendered-surface observer only while enabled, removes it on disable/destroy, and rebuilds no cached heights on frames where the surface identity is unchanged. Its dots and heat-lines are two renderer draw sets, it animates on the frame port's preRender, and it follows the camera through the camera port at its own 5% threshold rather than the shared `percentageChanged` ledger. The surface identity is the globe port's `surfaceVersion()` and tile readiness its `isSettled('surface')`, so the layer no longer reaches Cesium. Heat-lines are always asked for draped: where the Cesium renderer cannot drape (no depth textures) its draw port draws them (and every other draped line) over the surface, in their colour where the surface hides them and hidden past the horizon, recolouring a line in place when only its colour changes, rather than the layer dropping them.
|
||||
|
||||
|
||||
@@ -298,6 +298,8 @@ export function _renderCctvState(state) {
|
||||
tabShown &&
|
||||
this.store.previewCards > 0 &&
|
||||
(!phone || sheet === CONTEXT_SHEET);
|
||||
// Its bigger view is a popup over the map, shown on any phone sheet.
|
||||
const popupShown = tabShown && this.store.previewPopups > 0;
|
||||
if (this._cctvVideo) {
|
||||
const visible = liveIntent && panelShown;
|
||||
if (!visible || this._cctvVideoCameraId !== activeId) {
|
||||
@@ -324,7 +326,7 @@ export function _renderCctvState(state) {
|
||||
// immediate so navigation never waits on the prior camera's request.
|
||||
if (
|
||||
nextSrc &&
|
||||
(panelShown || cardShown) &&
|
||||
(panelShown || cardShown || popupShown) &&
|
||||
(cameraChanged || (!frameLoading && this._frame.currentSrc !== nextSrc))
|
||||
) {
|
||||
this._queueCctvFrame(nextSrc, nextCameraId, cameraChanged);
|
||||
|
||||
@@ -39,7 +39,12 @@ function fixture(t, { card = true } = {}) {
|
||||
preview = createApp(CctvPreview, { cameraId: 'a' }).use(pinia);
|
||||
preview.mount(cardHost);
|
||||
}
|
||||
function unmountCard() {
|
||||
preview?.unmount();
|
||||
preview = null;
|
||||
}
|
||||
if (card) mountCard();
|
||||
const store = useCctvStore(pinia);
|
||||
const controls = new CctvControls({
|
||||
elements: {
|
||||
_cctvPanel: document.getElementById('cctv-panel'),
|
||||
@@ -52,7 +57,7 @@ function fixture(t, { card = true } = {}) {
|
||||
setPanelCollapsed() {},
|
||||
syncViewport() {},
|
||||
},
|
||||
store: useCctvStore(pinia),
|
||||
store,
|
||||
});
|
||||
t.after(() => {
|
||||
controls.destroy();
|
||||
@@ -63,6 +68,8 @@ function fixture(t, { card = true } = {}) {
|
||||
controls,
|
||||
cardHost,
|
||||
mountCard,
|
||||
unmountCard,
|
||||
store,
|
||||
panelEl: document.getElementById('cctv-panel'),
|
||||
};
|
||||
}
|
||||
@@ -121,10 +128,12 @@ test('phone: a camera picked with the Context sheet open gets its still', async
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(
|
||||
requests.length >= 1,
|
||||
assert.equal(
|
||||
requests.length,
|
||||
1,
|
||||
'the Context card on the Context sheet requests the still',
|
||||
);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
requests.at(-1).onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
@@ -152,6 +161,48 @@ test('phone: the card on a closed Context sheet waits', async (t) => {
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
|
||||
test('phone: the bigger view keeps refreshing after the layout turns phone, and stops once closed', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
cardHost.querySelector('.cctv-preview__expand').click();
|
||||
await settle();
|
||||
await nextTick();
|
||||
const popup = document.body.querySelector('.cctv-popup');
|
||||
assert.ok(popup);
|
||||
assert.equal(popup.querySelector('img').getAttribute('src'), 'a1.jpg');
|
||||
|
||||
document.body.classList.add('mobile-shell');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(document.body.contains(popup));
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
requests[1].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(popup.querySelector('img').getAttribute('src'), 'a2.jpg');
|
||||
|
||||
popup.querySelector('.cctv-popup__close').click();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(document.body.querySelector('.cctv-popup'), null);
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 2);
|
||||
});
|
||||
|
||||
test('desktop: a card that mounts asks for the still', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl, mountCard } = fixture(t, { card: false });
|
||||
@@ -165,3 +216,66 @@ test('desktop: a card that mounts asks for the still', async (t) => {
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
|
||||
test('desktop: a card that unmounts stops the still, and a remount resumes it', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl, mountCard, unmountCard, store } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
|
||||
unmountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(store.previewCards, 0);
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 1);
|
||||
|
||||
mountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
});
|
||||
|
||||
test('desktop: the bigger view is released when the card unmounts, also in the tick it closes', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, cardHost, panelEl, mountCard, unmountCard, store } =
|
||||
fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
const openPopup = async () => {
|
||||
cardHost.querySelector('.cctv-preview__expand').click();
|
||||
await nextTick();
|
||||
assert.equal(store.previewPopups, 1);
|
||||
};
|
||||
|
||||
await openPopup();
|
||||
unmountCard();
|
||||
await nextTick();
|
||||
assert.equal(document.body.querySelector('.cctv-popup'), null);
|
||||
assert.equal(store.previewPopups, 0);
|
||||
|
||||
mountCard();
|
||||
await nextTick();
|
||||
await openPopup();
|
||||
// Closed and unmounted before the watcher runs, as when one Escape closes
|
||||
// the phone's Context sheet and the popup.
|
||||
document.body.querySelector('.cctv-popup__close').click();
|
||||
unmountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(store.previewPopups, 0);
|
||||
assert.equal(store.previewCards, 0);
|
||||
const before = requests.length;
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, before);
|
||||
});
|
||||
@@ -22,6 +22,8 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
const frame = shallowRef(null);
|
||||
/** Number of camera cards outside the panel showing its preview, including Context's card. */
|
||||
const previewCards = shallowRef(0);
|
||||
/** Number of open bigger views of a camera card (popups over the map). */
|
||||
const previewPopups = shallowRef(0);
|
||||
/** Whether the live video surface replaces the still frame. */
|
||||
const live = shallowRef(false);
|
||||
/** `{label, state}` for the source badge; null until first synced. */
|
||||
@@ -56,6 +58,11 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
previewCards.value = Math.max(0, previewCards.value + (shown ? 1 : -1));
|
||||
}
|
||||
|
||||
/** @param {boolean} shown */
|
||||
function showPreviewPopup(shown) {
|
||||
previewPopups.value = Math.max(0, previewPopups.value + (shown ? 1 : -1));
|
||||
}
|
||||
|
||||
/** @param {boolean} on */
|
||||
function setLive(on) {
|
||||
live.value = Boolean(on);
|
||||
@@ -81,6 +88,7 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
calEdit,
|
||||
frame,
|
||||
previewCards,
|
||||
previewPopups,
|
||||
live,
|
||||
sourceBadge,
|
||||
summary,
|
||||
@@ -89,6 +97,7 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
setCalEdit,
|
||||
setFrame,
|
||||
showPreviewCard,
|
||||
showPreviewPopup,
|
||||
setLive,
|
||||
setSourceBadge,
|
||||
setSummary,
|
||||
|
||||
@@ -54,15 +54,19 @@ const big = ref(false);
|
||||
const onKey = (e) => {
|
||||
if (e.key === 'Escape') big.value = false;
|
||||
};
|
||||
watch(big, (open) => {
|
||||
if (open) document.addEventListener('keydown', onKey);
|
||||
else document.removeEventListener('keydown', onKey);
|
||||
// The cleanup also runs when the card unmounts, even if `big` turned false in
|
||||
// the same tick and the watcher never saw it.
|
||||
watch(big, (open, _, onCleanup) => {
|
||||
if (!open) return;
|
||||
cctv.showPreviewPopup(true);
|
||||
document.addEventListener('keydown', onKey);
|
||||
onCleanup(() => {
|
||||
cctv.showPreviewPopup(false);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
});
|
||||
});
|
||||
onMounted(() => cctv.showPreviewCard(true));
|
||||
onBeforeUnmount(() => {
|
||||
cctv.showPreviewCard(false);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
});
|
||||
onBeforeUnmount(() => cctv.showPreviewCard(false));
|
||||
|
||||
function openPanel() {
|
||||
if (panels.value['cctv-panel']?.collapsed !== false) chrome.act('toggle', 'cctv-panel');
|
||||
|
||||
Reference in new issue
Block a user