Skip to content

Commit

Permalink
feat(client): add pause commands to api
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Apr 4, 2022
1 parent 24ee142 commit 90e8303
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/lib/CoreSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export default class CoreSession implements IJsPathEventTarget {
}
}

public async pause(): Promise<void> {
await this.commandQueue.run('Session.pauseCommands');
}

private async doClose(force: boolean): Promise<{ didKeepAlive: boolean; message: string }> {
await this.commandQueue.flush();
for (const tab of this.tabsById.values()) {
Expand Down
5 changes: 5 additions & 0 deletions client/lib/Hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ export default class Hero extends AwaitedEventTarget<{
return await this.getComputedVisibility(element as any).then(x => x.isVisible);
}

public async pause(): Promise<void> {
const session = await this.#getCoreSessionOrReject();
await session.pause();
}

public querySelector(selector: string): ISuperNode {
return this.activeTab.querySelector(selector);
}
Expand Down
4 changes: 4 additions & 0 deletions core/lib/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { TypedEventEmitter } from '@ulixee/commons/lib/eventUtils';
export default class Commands extends TypedEventEmitter<{
start: ICommandMeta;
finish: ICommandMeta;
pause: void;
resume: void;
}> {
public readonly history: ICommandMeta[] = [];
public get last(): ICommandMeta | undefined {
Expand Down Expand Up @@ -54,11 +56,13 @@ export default class Commands extends TypedEventEmitter<{
if (!this.commandLockPromise || this.commandLockPromise.isResolved) {
this.commandLockPromise = new Resolvable();
}
this.emit('pause');
}

public resume(): void {
this.commandLockPromise.resolve();
this.commandLockPromise = null;
this.emit('resume');
}

public create(
Expand Down

0 comments on commit 90e8303

Please sign in to comment.