Skip to content

Commit

Permalink
Add new custom event to trigger tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jan 18, 2024
1 parent dec7881 commit d6c552d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/LaunchConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,32 @@ export interface LaunchConfiguration extends DebugProtocol.LaunchRequestArgument
* @default false
*/
deleteDevChannelBeforeInstall: boolean;

/**
* Task to run instead of roku-deploy to produce the .zip file that will be uploaded to the Roku.
*/
packageTask: string;

/**
* Path to the .zip that will be uploaded to the Roku
*/
packagePath: string;

/**
* Overrides for values used during the roku-deploy zip upload process, like the route and various form data. You probably don't need to change these..
*/
packageUploadOverrides: {
/**
* The route to use for uploading to the Roku device. Defaults to 'plugin_install'
* @default 'plugin_install'
*/
route: string;

/**
* A dictionary of form fields to be included in the package upload request. Set a value to null to delete from the form
*/
formData: Record<string, any>;
};
}

export interface ComponentLibraryConfiguration {
Expand Down
41 changes: 36 additions & 5 deletions src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import {
ChanperfEvent,
DebugServerLogOutputEvent,
ChannelPublishedEvent,
PopupMessageEvent
PopupMessageEvent,
CustomRequestEvent,
ClientToServerCustomEventName
} from './Events';
import type { LaunchConfiguration, ComponentLibraryConfiguration } from '../LaunchConfiguration';
import { FileManager } from '../managers/FileManager';
Expand Down Expand Up @@ -208,6 +210,31 @@ export class BrightScriptDebugSession extends BaseDebugSession {
this.logger.trace('[showPopupMessage]', severity, message);
this.sendEvent(new PopupMessageEvent(message, severity, modal));
}

private static requestIdSequence = 0;

private async sendCustomRequest<T = any>(name: string, data: T) {
const requestId = BrightScriptDebugSession.requestIdSequence++;
const responsePromise = new Promise<any>((resolve, reject) => {
this.on(ClientToServerCustomEventName.customRequestEventResponse, (response) => {
if (response.requestId === requestId) {
if (response.error) {
throw response.error;
} else {
resolve(response);
}
}
});
});
this.sendEvent(
new CustomRequestEvent({
requestId: requestId,
name: name,
...data ?? {}
}));
await responsePromise;
}

/**
* Get the cwd from the launchConfiguration, or default to process.cwd()
*/
Expand All @@ -233,7 +260,6 @@ export class BrightScriptDebugSession extends BaseDebugSession {
}

public async launchRequest(response: DebugProtocol.LaunchResponse, config: LaunchConfiguration) {

this.logger.log('[launchRequest] begin');
//send the response right away so the UI immediately shows the debugger toolbar
this.sendResponse(response);
Expand All @@ -245,6 +271,8 @@ export class BrightScriptDebugSession extends BaseDebugSession {
logger.logLevel = this.launchConfiguration.logLevel;
}

await this.sendCustomRequest('executeTask', { task: config.packageTask });

//do a DNS lookup for the host to fix issues with roku rejecting ECP
try {
this.launchConfiguration.host = await util.dnsLookup(this.launchConfiguration.host);
Expand Down Expand Up @@ -655,14 +683,17 @@ export class BrightScriptDebugSession extends BaseDebugSession {
* Accepts custom events and requests from the extension
* @param command name of the command to execute
*/
protected customRequest(command: string) {
protected customRequest(command: string, response: DebugProtocol.Response, args: any) {
if (command === 'rendezvous.clearHistory') {
this.rokuAdapter.clearRendezvousHistory();
}

if (command === 'chanperf.clearHistory') {
} else if (command === 'chanperf.clearHistory') {
this.rokuAdapter.clearChanperfHistory();

} else if (command === 'customRequestEventResponse') {
this.emit('customRequestEventResponse', args);
}
this.sendResponse(response);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/debugSession/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ export function isChannelPublishedEvent(event: any): event is ChannelPublishedEv
return !!event && event.event === ChannelPublishedEvent.name;
}

/**
* Event that asks the client to execute a command.
*/
export class CustomRequestEvent<T = any, R = T & { name: string; requestId: number }> extends CustomEvent<R> {
constructor(body: R) {
super(body);
}
}

/**
* Is the object a `CustomRequestEvent`
*/
export function isCustomRequestEvent(event: any): event is CustomRequestEvent {
return !!event && event.event === CustomRequestEvent.name;
}

export function isExecuteTaskCustomRequest(event: any): event is CustomRequestEvent<{ task: string }> {
return !!event && event.event === CustomRequestEvent.name && event.body.name === 'executeTask';
}

export enum ClientToServerCustomEventName {
customRequestEventResponse = 'customRequestEventResponse'
}

export enum StoppedEventReason {
step = 'step',
breakpoint = 'breakpoint',
Expand Down

0 comments on commit d6c552d

Please sign in to comment.