diff --git a/src/ui/applicationShell.js b/src/ui/applicationShell.js index 115220d56..3577513e0 100644 --- a/src/ui/applicationShell.js +++ b/src/ui/applicationShell.js @@ -198,6 +198,7 @@ export class StyleManager extends ShellFacade { getDataManager: () => this._dataManager, pinia: applicationPinia(), pickWorld: services.pickWorldFromScreen, + regionalBrief: services.fetchRegionalBrief, }); this.mapStackController = mapStackController; this.placeSearch = placeSearch; diff --git a/src/ui/entityContextBridge.js b/src/ui/entityContextBridge.js index 43aac3059..22fe04d49 100644 --- a/src/ui/entityContextBridge.js +++ b/src/ui/entityContextBridge.js @@ -37,6 +37,8 @@ const FOLLOWABLE = new Set([ * @param {(viewer: object, x: number, y: number) => ({lat: number, lon: number}|null)} [options.pickWorld] * The ground under a normalized screen point; the view's centre falls back * to the point under the camera without it. + * @param {(lat: number, lon: number) => Promise} [options.regionalBrief] + * The app's regional brief service, for the weather and news Context shows. * @returns {() => void} disconnects */ export function installEntityContext({ @@ -44,12 +46,21 @@ export function installEntityContext({ getDataManager, pinia, pickWorld, + regionalBrief, }) { const store = useEntityCardStore(pinia); const omnibar = useOmnibarStore(pinia); const voice = useVoiceStore(pinia); const cockpitStore = useCockpitStore(pinia); const doc = globalThis.document; + let disposed = false; + // When the card last asked the camera to follow its item: the tracking + // that starts right after is the card's own (see trackedEntityChanged). + let pickedAt = -Infinity; + /** The entity the camera follows for the card, once its tracking starts. */ + let cardTracked = null; + const inCockpit = () => + Boolean(doc?.body?.classList.contains('cockpit-mode')); function openPanel() { const button = doc?.querySelector( @@ -82,27 +93,44 @@ export function installEntityContext({ function follow(card) { const run = omnibar.runner; if (!run || !FOLLOWABLE.has(card.layerId)) return flyTo(card); - void run('track_entity', { - query: card.identity.id || card.title, - layerId: card.layerId, - }); + pickedAt = performance.now(); + Promise.resolve( + run('track_entity', { + query: card.identity.id || card.title, + layerId: card.layerId, + }), + ).catch(() => {}); + } + + // Closing the card lets go of the camera, when the camera follows the + // card's own item and nothing else took it over since. + function letGo() { + const run = omnibar.runner; + if (!run || !cardTracked || viewer.trackedEntity !== cardTracked) return; + cardTracked = null; + Promise.resolve(run('stop_tracking', {})).catch(() => {}); } // Aircraft can be flown from, and a satellite ridden in the orbital view: - // track the craft, then enter Cockpit on it. - const COCKPIT_LAYERS = new Set([ - 'flights', - 'military', - 'local-adsb', - 'satellites', - ]); + // track the craft, then enter Cockpit on it. Only layers the tracking + // action can follow are offered (local ADS-B cannot be tracked). + const COCKPIT_LAYERS = new Set(['flights', 'military', 'satellites']); async function cockpit(card) { + try { + await enterCockpit(card); + } catch { + // The craft left the feed or tracking failed; the card stays as it is. + } + } + async function enterCockpit(card) { const run = omnibar.runner; if (!run || !COCKPIT_LAYERS.has(card.layerId)) return; + pickedAt = performance.now(); await run('track_entity', { query: card.identity.id || card.title, layerId: card.layerId, }); + if (disposed) return; if (card.layerId !== 'satellites') { await run('control_cockpit', { action: 'enter' }); return; @@ -111,6 +139,8 @@ export function installEntityContext({ // the orbital view once the satellite is tracked. Wait for it to say so; // if it never does (a class that cannot be ridden), nothing is entered. for (let tries = 0; tries < 40; tries++) { + // Another pick or a closed card in the meantime calls the ride off. + if (disposed || store.card?.key !== card.key) return; const presence = cockpitStore.presence; if (presence?.entryAvailable && presence.entryKind === 'satellite') { doc?.getElementById('cockpit-entry')?.click(); @@ -142,6 +172,8 @@ export function installEntityContext({ openPanel, flyTo, follow, + letGo, + regionalBrief, ask, askText, cockpit, @@ -207,7 +239,7 @@ export function installEntityContext({ 1000 - (now - lastRead), ); }); - setTimeout(readView, 0); + const firstRead = setTimeout(readView, 0); /** Layers whose own map click already follows what was clicked. */ const CLICK_FOLLOWS = new Set([ @@ -227,8 +259,6 @@ export function installEntityContext({ // pick starts the tracking, so tracking something else (another control, // another craft) is not mistaken for following the card. let trackCheck = 0; - let cardTracked = null; - let pickedAt = -Infinity; const removeTrackedChanged = viewer.trackedEntityChanged.addEventListener( () => { clearTimeout(trackCheck); @@ -241,7 +271,11 @@ export function installEntityContext({ } const card = store.card; const fromPick = performance.now() - pickedAt < 1500; - if (fromPick && card && (store.following === card.key || CLICK_FOLLOWS.has(card.layerId))) { + if ( + fromPick && + card && + (store.following === card.key || CLICK_FOLLOWS.has(card.layerId)) + ) { cardTracked = tracked; store.following = card.key; } else if (tracked !== cardTracked) { @@ -273,7 +307,8 @@ export function installEntityContext({ // A tool that owns the pointer (draw, measure) keeps its clicks. const press = pressed; pressed = null; - if (!isPointerFree()) return; + // Cockpit has its own picks, and Context is hidden while it runs. + if (!isPointerFree() || inCockpit()) return; const samePlace = press && Math.hypot(press.x - position.x, press.y - position.y) < 6; const picked = samePlace ? press.picked : pickAt(position); @@ -299,7 +334,7 @@ export function installEntityContext({ // Layers that select through the context store (GeoJSON sites, fires, // installations) announce it; their selection opens the card too. const onSelected = ({ detail: record }) => { - if (!record?.layerId) return; + if (!record?.layerId || inCockpit()) return; store.select({ layerId: record.layerId, id: record.id, @@ -311,6 +346,8 @@ export function installEntityContext({ globalThis.addEventListener?.('gev:entity-selected', onSelected); return () => { + disposed = true; + clearTimeout(firstRead); handler.destroy(); removeMoveEnd(); removeChanged(); diff --git a/src/ui/spotConditions.js b/src/ui/spotConditions.js index a03d013c1..2e1185dcb 100644 --- a/src/ui/spotConditions.js +++ b/src/ui/spotConditions.js @@ -1,5 +1,5 @@ import { codeWord, distanceKm } from '../data/entityContext.js'; -import { msg, t, tn } from '../i18n/index.js'; +import { formatNumber, msg, t, tn } from '../i18n/index.js'; import { createUsgsEarthquakeSource } from '../layers/earthquakes/source.js'; import { createCycloneSource } from '../layers/cyclones/source.js'; import { createWfigsPerimeterSource } from '../layers/perimeters/source.js'; @@ -16,15 +16,24 @@ const BRIEF_TTL_MS = 10 * 60_000; const FEED_TTL_MS = 5 * 60_000; const briefs = new Map(); -/** The regional brief for a spot: `{weather, articles, place, newsSource}`. */ -export function regionalBrief(lat, lon) { +/** + * The regional brief for a spot: `{weather, articles, place, newsSource}`, + * read with `load`, the app's regional service. A failed read is not kept, + * so the next ask tries again. + * @param {number} lat + * @param {number} lon + * @param {(lat: number, lon: number) => Promise} load + */ +export function regionalBrief(lat, lon, load) { const key = `${lat.toFixed(2)},${lon.toFixed(2)}`; const kept = briefs.get(key); if (kept && Date.now() - kept.at < BRIEF_TTL_MS) return kept.promise; - const query = `latitude=${lat.toFixed(5)}&longitude=${lon.toFixed(5)}`; - const promise = fetch(`/api/regional-brief?${query}`) - .then((response) => (response.ok ? response.json() : null)) - .catch(() => null); + const promise = Promise.resolve() + .then(() => load(lat, lon)) + .catch(() => { + if (briefs.get(key)?.promise === promise) briefs.delete(key); + return null; + }); briefs.set(key, { at: Date.now(), promise }); if (briefs.size > 40) briefs.delete(briefs.keys().next().value); return promise; @@ -164,7 +173,7 @@ export async function hazardsNear( title: fire.name || t('Wildfire'), detail: [ Number.isFinite(acres) - ? t('{n} acres', { n: Math.round(acres).toLocaleString() }) + ? t('{n} acres', { n: formatNumber(Math.round(acres)) }) : '', Number.isFinite(fire.containedPct) ? t('{n}% contained', { n: fire.containedPct }) diff --git a/src/ui/stores/entityCard.js b/src/ui/stores/entityCard.js index 1a92c02a1..eb785e5b1 100644 --- a/src/ui/stores/entityCard.js +++ b/src/ui/stores/entityCard.js @@ -280,6 +280,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => { } function clear() { + if (following.value) shell.value?.letGo?.(); following.value = null; clearInterval(timer); timer = null; @@ -296,6 +297,11 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => { const isFollowing = () => Boolean(card.value && following.value === card.value.key); const ask = () => card.value && shell.value?.ask?.(card.value); + /** The regional brief (weather, local news) for a spot, from the shell. */ + const readBrief = (lat, lon) => + shell.value?.regionalBrief + ? shell.value.regionalBrief(lat, lon) + : Promise.resolve(null); const canFollow = () => Boolean(shell.value?.canFollow?.(card.value)); /** Loaded items whose name or id matches typed text, for the omnibar. */ const search = (query, options) => @@ -317,6 +323,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => { flyTo, follow, ask, + readBrief, canFollow, isFollowing, following, diff --git a/src/ui/styles/context-dock.css b/src/ui/styles/context-dock.css index 2720cd470..aea771f1d 100644 --- a/src/ui/styles/context-dock.css +++ b/src/ui/styles/context-dock.css @@ -196,3 +196,16 @@ body.mobile-shell .context-dock-btn { ) { display: none; } + +/* Right to left, the rail sits on the left edge (rtl.css), and so does the + expanded column. */ +html[dir='rtl'] body.context-docked #right-context-rail { + right: auto !important; + left: 0 !important; +} + +html[dir='rtl'] body.context-docked #global-context-panel .global-context-panel-inner { + border-left: 0; + border-right: 1px solid rgba(255, 255, 255, 0.08); + box-shadow: 18px 0 40px rgba(0, 0, 0, 0.35); +} diff --git a/src/ui/views/ContextView.vue b/src/ui/views/ContextView.vue index 773cd329d..71070f866 100644 --- a/src/ui/views/ContextView.vue +++ b/src/ui/views/ContextView.vue @@ -87,6 +87,9 @@ onBeforeUnmount(() => { globalThis.removeEventListener?.('gev:context-show-view', showView); clearInterval(layerTimer); contextReady.value = false; + // A later mount starts as the button says: not expanded, no tab classes. + setDocked(false); + for (const tab of LAYER_TABS) globalThis.document?.body.classList.remove(`ctx-tab-${tab.id}`); }); watch(availableTabs, (tabs) => { for (const tab of LAYER_TABS) @@ -97,6 +100,11 @@ watch(availableTabs, (tabs) => { watch(entityCard, (next, prev) => { if (next && next?.key !== prev?.key) activeTab.value = 'view'; }); +// The two tabs swap with the arrow keys, and focus follows (tabs pattern). +function switchTab() { + activeTab.value = activeTab.value === 'view' ? 'props' : 'view'; + void nextTick(() => globalThis.document?.getElementById(`context-tab-btn-${activeTab.value}`)?.focus()); +} const isShown = (id) => availableTabs.value.some((tab) => tab.id === id); // The names of the layers a section's settings act on. const layerNames = ref({}); @@ -131,10 +139,24 @@ const searchHint = computed(() => // panel closes. const docked = ref(false); const { panels: chromePanels } = storeToRefs(usePanelChromeStore()); +// The phone layout and Cockpit have no room for the column: either one +// arriving lets it go. +let bodyWatch = null; function setDocked(next) { docked.value = next; - globalThis.document?.body.classList.toggle('context-docked', next); + const body = globalThis.document?.body; + body?.classList.toggle('context-docked', next); + bodyWatch?.disconnect(); + bodyWatch = null; + if (next && body && globalThis.MutationObserver) { + bodyWatch = new MutationObserver(() => { + if (body.classList.contains('mobile-shell') || body.classList.contains('cockpit-mode')) setDocked(false); + }); + bodyWatch.observe(body, { attributes: true, attributeFilter: ['class'] }); + } } +// Only an open panel reads what is picked and in view; closed, it does no work. +const contextOpen = computed(() => chromePanels.value['global-context-panel']?.collapsed !== true); watch( () => chromePanels.value['global-context-panel']?.collapsed, (collapsed) => { @@ -176,15 +198,15 @@ watch(
- -
-
+

{{ t(tab.label) }}

    @@ -225,7 +247,7 @@ watch(
-
+
diff --git a/src/ui/views/panels/CctvPreview.vue b/src/ui/views/panels/CctvPreview.vue index c174ba6d7..f5aae41cf 100644 --- a/src/ui/views/panels/CctvPreview.vue +++ b/src/ui/views/panels/CctvPreview.vue @@ -29,6 +29,8 @@ const params = computed(() => { const name = computed(() => params.value.get('label') || ''); // The panel's meta line, e.g. "US-290 · HDG 248° · FOV 44° · RANGE 145m · … · TxDOT · …". const facts = computed(() => { + // The panel's line belongs to the camera it shows, which may be another. + if (!same.value) return []; const parts = String(view.value?.meta || '') .split(' · ') .map((p) => p.trim()) diff --git a/src/ui/views/panels/EntityCard.vue b/src/ui/views/panels/EntityCard.vue index 03c0a5372..9c05adbbd 100644 --- a/src/ui/views/panels/EntityCard.vue +++ b/src/ui/views/panels/EntityCard.vue @@ -178,7 +178,10 @@ watch( routePlaces.value = { from: route?.fromAt?.name || '', to: route?.toAt?.name || '' }; if (!route?.fromAt || !route?.toAt) return; const [from, to] = await Promise.all([airportPlace(route.fromAt), airportPlace(route.toAt)]); - if (card.value?.route?.fromAt?.code === route.fromAt.code) routePlaces.value = { from, to }; + // Only for the same route still: another flight from the same airport + // may have taken the card meanwhile. + const now = card.value?.route; + if (now?.fromAt?.code === route.fromAt.code && now?.toAt?.code === route.toAt.code) routePlaces.value = { from, to }; }, { immediate: true }, ); diff --git a/src/ui/views/panels/SpotConditions.vue b/src/ui/views/panels/SpotConditions.vue index 57314bbac..08bde3659 100644 --- a/src/ui/views/panels/SpotConditions.vue +++ b/src/ui/views/panels/SpotConditions.vue @@ -60,7 +60,7 @@ async function read(lat, lon) { const mineHazards = ++readingHazards; loading.value = true; const [nextBrief, nextHazards] = await Promise.all([ - regionalBrief(lat, lon), + regionalBrief(lat, lon, store.readBrief), hazardsNear(lat, lon, radiusKm.value, { fires: firesOn() }).catch(() => []), ]); if (reading !== mine) return; @@ -86,6 +86,17 @@ async function rereadHazards(km) { hazards.value = next; } watch(radiusKm, (km) => void rereadHazards(km)); +// A spot that stays put (a parked selection, a still view) reads its weather, +// news and hazards again once the kept copies are old. +const REREAD_MS = 5 * 60_000; +let rereadTimer = 0; +onMounted(() => { + rereadTimer = setInterval(() => { + readAt = null; + void read(props.lat, props.lon); + }, REREAD_MS); +}); +onBeforeUnmount(() => clearInterval(rereadTimer)); // Hazard rows are worded as they are read, so a new language reads them again. const stopLocale = onLocaleChange(() => void rereadHazards(radiusKm.value)); @@ -212,6 +223,11 @@ const hazardLayers = computed(() => { }), ); }); +// Turning FIRMS on or off adds or drops its fire hits at once. +watch( + () => Boolean(hazardLayers.value.hotspots?.on), + () => void rereadHazards(radiusKm.value), +); let layerTimer = 0; onMounted(() => { layerTimer = setInterval(() => layerTick.value++, 1500); diff --git a/src/ui/views/panels/ViewContext.vue b/src/ui/views/panels/ViewContext.vue index 1e11cd811..c6c9bdd4c 100644 --- a/src/ui/views/panels/ViewContext.vue +++ b/src/ui/views/panels/ViewContext.vue @@ -78,7 +78,9 @@ const where = computed(() => { }); const height = computed(() => { const m = view.value?.heightM ?? 0; - return m >= 10_000 ? t('{n} km up', { n: Math.round(m / 1000) }) : t('{n} m up', { n: Math.round(m) }); + return m >= 10_000 + ? t('{n} km up', { n: formatNumber(Math.round(m / 1000)) }) + : t('{n} m up', { n: formatNumber(Math.round(m)) }); }); const placeName = computed(() => { const found = place.value; @@ -142,6 +144,8 @@ watch( view, async (current) => { if (!current || current.heightM > 400_000) { + // Forget the last place too, so coming back down reads it again. + townsFor = ''; towns.value = []; return; } diff --git a/src/voice/sessionCommands.js b/src/voice/sessionCommands.js index 45dd48383..6e3a0589f 100644 --- a/src/voice/sessionCommands.js +++ b/src/voice/sessionCommands.js @@ -337,10 +337,15 @@ export function createVoiceCommands({ else adapter.bindControls?.(); window.__gevVoiceCommands = controls; // The omnibar runs the same actions directly, without a model. - const omnibar = useOmnibarStore(applicationPinia()); - omnibar.connectRunner((name, args) => runner(name, args)); - session.signal.addEventListener('abort', () => omnibar.connectRunner(null), { - once: true, - }); + // A session already gone leaves the omnibar without a runner. + if (!session.disposed) { + const omnibar = useOmnibarStore(applicationPinia()); + omnibar.connectRunner((name, args) => runner(name, args)); + session.signal.addEventListener( + 'abort', + () => omnibar.connectRunner(null), + { once: true }, + ); + } return controls; }