Skip to content

Commit

Permalink
feat!: foreground app with activateApp
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenroc committed Jun 12, 2024
1 parent ab371d3 commit 201bd65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
19 changes: 18 additions & 1 deletion src/commands/activateApp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { errors } from '@appium/base-driver';
import * as ecp from '@dlenroc/roku-ecp';
import type { Driver } from '../Driver.ts';
import * as appiumUtils from '../helpers/appium.js';

export async function activateApp(
this: Driver,
appId: string,
options?: unknown
): Promise<void> {
options ??= { odc_clear_registry: false };
options ??= {};

if (typeof options !== 'object' || Array.isArray(options)) {
throw new errors.InvalidArgumentError('Launch arguments must be an object');
Expand All @@ -17,4 +18,20 @@ export async function activateApp(
appId: appId as ecp.AppId,
params: options as Record<string, unknown>,
});

let screensaverDismissed = false;

await appiumUtils.retrying({
timeout: 1e4,
validate: (state, error) => !error && state === 4,
command: async () => {
const state = await this.queryAppState(appId);
if (!screensaverDismissed && state === 3) {
screensaverDismissed = true;
await this.sdk.ecp.keypress({ key: 'Enter' });
}

return state;
},
});
}
13 changes: 4 additions & 9 deletions src/commands/setUrl.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { errors } from '@appium/base-driver';
import type { AppId } from '@dlenroc/roku-ecp';
import { URL } from 'node:url';
import type { Driver } from '../Driver.ts';

export async function setUrl(this: Driver, url: string): Promise<void> {
const { host, pathname, searchParams } = new URL(url);
const app = pathname.slice(1) as AppId;

let params: Record<string, string> = {};
for (const [key, value] of searchParams) {
params[key] = value;
}
const app = pathname.slice(1);
const params = Object.fromEntries(searchParams);

switch (host) {
case 'launch':
return await this.sdk.ecp.launch({ appId: app, params });
return this.activateApp(app, params);
case 'input':
return await this.sdk.ecp.input(params);
return this.sdk.ecp.input(params);
default:
throw new errors.InvalidArgumentError('Unsupported URL format');
}
Expand Down

0 comments on commit 201bd65

Please sign in to comment.