Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Tune contextUpdated event generation #973

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/commands/bidi/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const BIDI_EVENT_NAME = 'bidiEvent';
export const CONTEXT_UPDATED_EVENT = 'appium.contextUpdated';
export const CONTEXT_UPDATED_EVENT = (domain: string) => `appium:${domain}.contextUpdated`;
/** @deprecated Use {@link CONTEXT_UPDATED_EVENT} instead */
export const CONTEXT_UPDATED_EVENT_OBSOLETE = 'appium.contextUpdated';
export const LOG_ENTRY_ADDED_EVENT = 'log.entryAdded';
21 changes: 18 additions & 3 deletions lib/commands/bidi/models.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import type { LogEntryAddedEvent, ContextUpdatedEvent } from './types';
import { NATIVE_WIN } from '../context/helpers';
import { CONTEXT_UPDATED_EVENT, LOG_ENTRY_ADDED_EVENT } from './constants';
import {
CONTEXT_UPDATED_EVENT,
LOG_ENTRY_ADDED_EVENT,
CONTEXT_UPDATED_EVENT_OBSOLETE,
} from './constants';
import type { LogcatRecord as LogEntry } from 'appium-adb';

export function makeContextUpdatedEvent(contextName: string): ContextUpdatedEvent {
function toContextUpdatedEvent(method: string, contextName: string): ContextUpdatedEvent {
return {
method: CONTEXT_UPDATED_EVENT,
method,
params: {
name: contextName,
type: contextName === NATIVE_WIN ? 'NATIVE' : 'WEB',
},
};
}

export const makeContextUpdatedEvent = (contextName: string, domain: string) => toContextUpdatedEvent(
CONTEXT_UPDATED_EVENT(domain), contextName
);

/**
* @deprecated Use {@link makeContextUpdatedEvent} instead
*/
export const makeObsoleteContextUpdatedEvent = (contextName: string) => toContextUpdatedEvent(
CONTEXT_UPDATED_EVENT_OBSOLETE, contextName
);

export function makeLogEntryAddedEvent(entry: LogEntry, context: string, type: string): LogEntryAddedEvent {
return {
context,
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/context/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './helpers';
import {APP_STATE} from '../app-management';
import { BIDI_EVENT_NAME } from '../bidi/constants';
import { makeContextUpdatedEvent } from '../bidi/models';
import { makeContextUpdatedEvent, makeObsoleteContextUpdatedEvent } from '../bidi/models';

// https://github.com/appium/appium/issues/20710
const DEFAULT_NATIVE_WINDOW_HANDLE = '1';
Expand Down Expand Up @@ -382,7 +382,8 @@ export function isChromedriverContext(viewName) {
*/
export async function notifyBiDiContextChange() {
const name = await this.getCurrentContext();
this.eventEmitter.emit(BIDI_EVENT_NAME, makeContextUpdatedEvent(name));
this.eventEmitter.emit(BIDI_EVENT_NAME, makeContextUpdatedEvent(_.toLower(String(this.opts.automationName)), name));
this.eventEmitter.emit(BIDI_EVENT_NAME, makeObsoleteContextUpdatedEvent(name));
}

/**
Expand Down
Loading