mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-04 08:15:41 +00:00
api.host.features.sidePanel now says whether this plugin may offer the app-side-panel (ui:side-panel granted), not only that the webmail has it. A plugin enabled before an update added the permission can then say so instead of offering a switch that does nothing. The host computes the assistant's flags per plugin for a frame's init and for each push. plugin-host-features.test.ts: the host bridge assertions take the assistant's flags as the test plugin sees them (it lacks ui:side-panel, so sidePanel is false there).
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
// The assistant's host API areas, merged, host side (see README.md).
|
|
|
|
import type { InstalledPlugin, Permission } from '../../plugin-types';
|
|
import { NOT_MINE } from './not-mine';
|
|
import * as b from './b';
|
|
import * as c from './c';
|
|
import * as d from './d';
|
|
import * as f from './f';
|
|
import type { AssistantHostFeatures } from './types';
|
|
|
|
export { NOT_MINE };
|
|
const AREAS = [b, c, d, f];
|
|
|
|
/** Method → permission of every area, joined into PERM_PER_METHOD. */
|
|
export const ASSISTANT_PERMS: Readonly<Record<string, Permission | null>> = Object.assign({}, ...AREAS.map((a) => a.PERMS));
|
|
|
|
/** Runs an area's method; NOT_MINE when no area owns it. The permission is checked before. */
|
|
export async function dispatchAssistant(plugin: InstalledPlugin, method: string, args: unknown[]): Promise<unknown> {
|
|
for (const area of AREAS) {
|
|
if (!(method in area.PERMS)) continue;
|
|
return area.dispatch(plugin, method, args);
|
|
}
|
|
return NOT_MINE;
|
|
}
|
|
|
|
/**
|
|
* Every area's api.host.features flags, right now; with `plugin`, as that
|
|
* plugin's frames see them (a flag may depend on what it was granted).
|
|
*/
|
|
export function assistantFeatures(plugin?: InstalledPlugin): AssistantHostFeatures {
|
|
return Object.assign({}, ...AREAS.map((a) => (a.features as (p?: InstalledPlugin) => object)(plugin)));
|
|
}
|