Repository navigation
Expand file tree
/
Copy pathinteractor.ts
More file actions
67 lines (63 loc) · 2.75 KB
/
Copy pathinteractor.ts
File metadata and controls
67 lines (63 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { isDeepLinkTarget } from '@agent-device/contracts/command';
import type { Interactor, RunnerContext } from '@agent-device/contracts/interactor-types';
import { createUnsupportedInteractor } from '@agent-device/contracts/unsupported-interactor';
import type { DeviceInfo } from '@agent-device/kernel/device';
import { AppError } from '@agent-device/kernel/errors';
import { closeVegaApp, openVegaApp, openVegaDevice } from './app-lifecycle.ts';
import { pressVegaTvRemote } from './input-actions.ts';
type VegaOpenOptions = Parameters<Interactor['open']>[1];
const UNSUPPORTED_VEGA_OPEN_VARIANTS = [
{
matches: (app: string, options: VegaOpenOptions) =>
isDeepLinkTarget(app) || Boolean(options?.url),
message: 'Vega open does not support URLs or deep links.',
hint: 'Use open <component-id> with an installed Vega app component ID.',
},
{
matches: (_app: string, options: VegaOpenOptions) => Boolean(options?.activity),
message: 'Vega open does not support Android activity selection.',
hint: 'Remove --activity and use the Vega component ID as the open target.',
},
{
matches: (_app: string, options: VegaOpenOptions) => Boolean(options?.launchConsole),
message: 'Vega open does not support launch-console output.',
hint: 'Remove --launch-console and open the Vega component ID directly.',
},
{
matches: (_app: string, options: VegaOpenOptions) => Boolean(options?.terminateRunningApp),
message: 'Vega open does not support terminating the running app before launch.',
hint: 'Close the Vega component explicitly before opening it again.',
},
{
matches: (_app: string, options: VegaOpenOptions) => Boolean(options?.launchArgs?.length),
message: 'Vega open does not support launch arguments.',
hint: 'Remove --launch-arg values and open the Vega component ID directly.',
},
] as const;
export function createVegaInteractor(
device: DeviceInfo,
_runnerContext: RunnerContext,
): Interactor {
return {
...createUnsupportedInteractor('Vega OS'),
open: async (app, options) => {
assertVegaOpenSupported(app, options);
await openVegaApp(device, app);
},
openDevice: () => openVegaDevice(device),
close: (app) => closeVegaApp(device, app),
back: () => pressVegaTvRemote(device, 'back'),
home: () => pressVegaTvRemote(device, 'home'),
tvRemote: (button, durationMs) => pressVegaTvRemote(device, button, durationMs),
};
}
function assertVegaOpenSupported(app: string, options?: VegaOpenOptions): void {
const unsupportedVariant = UNSUPPORTED_VEGA_OPEN_VARIANTS.find(({ matches }) =>
matches(app, options),
);
if (unsupportedVariant) {
throw new AppError('UNSUPPORTED_OPERATION', unsupportedVariant.message, {
hint: unsupportedVariant.hint,
});
}
}