Voice: an app can supply what open_stories does

createApplicationTools took the Stories page as the open_stories action
even when the app's voice options gave its own. voice.openStories now
takes precedence, spoken or typed, with the Stories page as the default.
This commit is contained in:
Sameh Khamis committed 2026-11-16 16:33:46 -08:00
1 parent fa6d954702
commit b1b2ac91c0
4 files changed
+76 -9

No files matched your search

+11 -7
View File
@@ -1,5 +1,9 @@
import { onFollowChanged } from '../data/followed.js';
import { bootStories, stopVoiceForStories } from '../stories/boot.js';
import {
bootStories,
stopVoiceForStories,
storiesOpener,
} from '../stories/boot.js';
import { t } from '../i18n/index.js';
import { useStoriesStore } from '../ui/stores/stories.js';
import { SceneDirector } from '../scenes/director.js';
@@ -309,12 +313,12 @@ export function createApplicationTools({
voiceCommands = initGevVoiceCommands({
...voice,
canStartVoice: () => !isStoriesOpen(),
openStories: storiesStore.available
? ({ isCurrent }) =>
storiesStore.mode === 'closed'
? stories.open({ isCurrent })
: 'already-open'
: null,
// An app may supply what open_stories does; the Stories page by default.
openStories: storiesOpener({
openStories: voice.openStories,
store: storiesStore,
stories,
}),
floorServices: operations.surface.groundFloor,
annotationResolver: operations.annotationResolver,
searchNavigation: operations.searchAndFlyTo,
+17
View File
@@ -12,6 +12,23 @@ export function stopVoiceForStories(session) {
return wasActive;
}
/**
* What the `open_stories` action does, spoken or typed: the app's own
* `openStories` when it supplies one, else open the Stories page (none
* where Stories is not offered). It is called with `{ isCurrent }` and
* answers true when it opened, 'already-open', or false.
* @param {{openStories?: Function|null,
* store: {available: boolean, mode: string},
* stories: {open: (options: {isCurrent: () => boolean}) => unknown}}} options
* @returns {Function|null}
*/
export function storiesOpener({ openStories, store, stories }) {
if (typeof openStories === 'function') return openStories;
if (!store.available) return null;
return ({ isCurrent }) =>
store.mode === 'closed' ? stories.open({ isCurrent }) : 'already-open';
}
/**
* Stories, loaded on first use. The controller, the story catalog, the
* screens and their styles are separate chunks, fetched when the person
+44 -1
View File
@@ -34,7 +34,8 @@ globalThis.HTMLCanvasElement.prototype.getContext = (kind) =>
globalThis.requestAnimationFrame = () => 0;
globalThis.cancelAnimationFrame = () => {};
const { bootStories, stopVoiceForStories } = await import('./boot.js');
const { bootStories, stopVoiceForStories, storiesOpener } =
await import('./boot.js');
const { useStoriesStore } = await import('../ui/stores/stories.js');
const { bindRenderer } = await import('../render/rendererOf.js');
@@ -76,6 +77,48 @@ const director = {
styleManager: { runImmediateNavigation: () => true },
};
test('open_stories runs the app’s own openStories when it supplies one', async () => {
const calls = [];
const opened = [];
const own = async (options) => {
calls.push(options);
return true;
};
const open = storiesOpener({
openStories: own,
store: { available: true, mode: 'closed' },
stories: { open: (options) => opened.push(options) },
});
assert.equal(open, own);
const isCurrent = () => true;
assert.equal(await open({ isCurrent }), true);
assert.deepEqual(calls, [{ isCurrent }]);
assert.deepEqual(opened, [], 'the Stories page is not opened');
});
test('open_stories opens the Stories page by default', () => {
const opened = [];
const store = { available: true, mode: 'closed' };
const stories = {
open: (options) => {
opened.push(options);
return true;
},
};
const open = storiesOpener({ store, stories });
const isCurrent = () => true;
assert.equal(open({ isCurrent }), true);
assert.deepEqual(opened, [{ isCurrent }]);
store.mode = 'explore';
assert.equal(open({ isCurrent }), 'already-open');
assert.equal(opened.length, 1);
// Where Stories is not offered, there is nothing to open.
assert.equal(
storiesOpener({ store: { available: false, mode: 'closed' }, stories }),
null,
);
});
test('entering Stories stops microphone sessions and preserves typed chat', () => {
let textOnly = false;
let active = true;