Skip to content

Commit

Permalink
Add on device brightscript repl (#564)
Browse files Browse the repository at this point in the history
* Add on device brightscript repl

* switch repl manifest version to 1.0.0

* Verify code is valid before sending to device, add better hinting at need to return a value

---------

Co-authored-by: Brian Leighty <bleighty@tubi.tv>
Co-authored-by: Bronley Plumb <bronley@gmail.com>
  • Loading branch information
3 people committed Apr 24, 2024
1 parent f0e4a1a commit e9df0c0
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 177 deletions.
243 changes: 128 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"glob": "^7.1.3",
"hex-rgb": "^5.0.0",
"iconv-lite": "0.4.24",
"jszip": "^3.10.1",
"just-throttle": "^4.0.1",
"net": "^1.0.2",
"node-cache": "^4.2.0",
Expand All @@ -77,7 +78,7 @@
"pretty-bytes": "^5.6.0",
"roku-debug": "^0.21.7",
"roku-deploy": "^3.12.0",
"roku-test-automation": "^2.0.4",
"roku-test-automation": "^2.0.6",
"semver": "^7.1.3",
"source-map": "^0.7.3",
"thenby": "^1.3.4",
Expand Down Expand Up @@ -241,6 +242,11 @@
"id": "rokuAutomationView",
"name": "Roku Automation",
"type": "webview"
},
{
"id": "rokuReplView",
"name": "Roku REPL",
"type": "webview"
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions src/managers/WebviewViewProviderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RokuAppOverlaysViewViewProvider } from '../viewProviders/RokuAppOverlay
import { RokuRegistryViewProvider } from '../viewProviders/RokuRegistryViewProvider';
import { SceneGraphInspectorViewProvider } from '../viewProviders/SceneGraphInspectorViewProvider';
import { RokuAutomationViewViewProvider } from '../viewProviders/RokuAutomationViewViewProvider';
import { RokuReplViewProvider } from '../viewProviders/RokuReplViewProvider';

export class WebviewViewProviderManager {
constructor(
Expand Down Expand Up @@ -51,6 +52,9 @@ export class WebviewViewProviderManager {
}, {
constructor: SceneGraphInspectorViewProvider,
provider: undefined as SceneGraphInspectorViewProvider
}, {
constructor: RokuReplViewProvider,
provider: undefined as RokuReplViewProvider
}];

public getWebviewViewProviders() {
Expand Down
10 changes: 2 additions & 8 deletions src/viewProviders/BaseRdbViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export abstract class BaseRdbViewProvider extends BaseWebviewViewProvider {
this.addMessageCommandCallback(command, async (message) => {
const { command, context } = message;
const response = await this.dependencies.rtaManager.sendOdcRequest(this.id, command, context);
this.postOrQueueMessage({
...message,
response: response
});
this.postOrQueueMessage(this.createResponseMessage(message, response));
return true;
});
}
Expand All @@ -53,10 +50,7 @@ export abstract class BaseRdbViewProvider extends BaseWebviewViewProvider {

this.addMessageCommandCallback(ViewProviderCommand.getStoredNodeReferences, (message) => {
const response = this.dependencies.rtaManager.getStoredNodeReferences();
this.postOrQueueMessage({
...message,
response: response
});
this.postOrQueueMessage(this.createResponseMessage(message, response));
return Promise.resolve(true);
});
}
Expand Down
27 changes: 16 additions & 11 deletions src/viewProviders/BaseWebviewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ export abstract class BaseWebviewViewProvider implements vscode.WebviewViewProvi
return message;
}

public createResponseMessage(incomingMessage, response = undefined, error = undefined) {
const message = {
...incomingMessage,
response: response,
error: error
};

return message;
}

public postOrQueueMessage(message) {
if (this.viewReady) {
this.postMessage(message);
Expand Down Expand Up @@ -122,16 +132,11 @@ export abstract class BaseWebviewViewProvider implements vscode.WebviewViewProvi
} else if (command === ViewProviderCommand.updateWorkspaceState) {
const context = message.context;
await this.extensionContext.workspaceState.update(context.key, context.value);
this.postOrQueueMessage({
...message
});
this.postOrQueueMessage(this.createResponseMessage(message));
} else if (command === ViewProviderCommand.getWorkspaceState) {
const context = message.context;
const response = await this.extensionContext.workspaceState.get(context.key, context.defaultValue);
this.postOrQueueMessage({
...message,
response: response
});
this.postOrQueueMessage(this.createResponseMessage(message, response));
} else {
const callback = this.messageCommandCallbacks[command];
if (!callback || !await callback(message)) {
Expand All @@ -150,8 +155,8 @@ export abstract class BaseWebviewViewProvider implements vscode.WebviewViewProvi
});
}

protected registerCommandWithWebViewNotifier(context: vscode.ExtensionContext, command: string, callback: (() => any) | undefined = undefined) {
this.registerCommand(context, command, async () => {
protected registerCommandWithWebViewNotifier(command: string, callback: (() => any) | undefined = undefined) {
this.registerCommand(command, async () => {
if (callback) {
await callback();
}
Expand All @@ -163,8 +168,8 @@ export abstract class BaseWebviewViewProvider implements vscode.WebviewViewProvi
});
}

protected registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
context.subscriptions.push(vscode.commands.registerCommand(command, callback));
protected registerCommand(command: string, callback: (...args: any[]) => any) {
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(command, callback));
}

protected onViewReady() { }
Expand Down
2 changes: 1 addition & 1 deletion src/viewProviders/RokuAppOverlaysViewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RokuAppOverlaysViewViewProvider extends BaseRdbViewProvider {

const subscriptions = context.subscriptions;

this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuAppOverlaysViewRemoveAllOverlays);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuAppOverlaysViewRemoveAllOverlays);

subscriptions.push(vscode.commands.registerCommand(VscodeCommand.rokuAppOverlaysViewAddNewOverlay, async () => {
const options: vscode.OpenDialogOptions = {
Expand Down
24 changes: 9 additions & 15 deletions src/viewProviders/RokuAutomationViewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export class RokuAutomationViewViewProvider extends BaseRdbViewProvider {
constructor(context: vscode.ExtensionContext, dependencies) {
super(context, dependencies);

this.context = context;

this.addMessageCommandCallback(ViewProviderCommand.storeRokuAutomationConfigs, async (message) => {
this.rokuAutomationConfigs = message.context.configs;
// Make sure to use JSON.stringify or weird stuff happens
Expand All @@ -43,9 +41,7 @@ export class RokuAutomationViewViewProvider extends BaseRdbViewProvider {
}
});

const subscriptions = context.subscriptions;

subscriptions.push(vscode.commands.registerCommand(VscodeCommand.rokuAutomationViewStartRecording, async () => {
this.registerCommand(VscodeCommand.rokuAutomationViewStartRecording, async () => {
if (this.currentRunningStep === -1) {
// Only allow recording when we aren't currently running
await this.setIsRecording(true);
Expand All @@ -54,22 +50,22 @@ export class RokuAutomationViewViewProvider extends BaseRdbViewProvider {
// We reset the current step to update the timestamp of the first sleep
this.updateCurrentRunningStep(-1);
}
}));
});

subscriptions.push(vscode.commands.registerCommand(VscodeCommand.rokuAutomationViewStopRecording, async () => {
this.registerCommand(VscodeCommand.rokuAutomationViewStopRecording, async () => {
if (this.isRecording) {
await this.setIsRecording(false);
await vscode.commands.executeCommand(VscodeCommand.disableRemoteControlMode);
}
}));
});

subscriptions.push(vscode.commands.registerCommand(VscodeCommand.rokuAutomationViewEnableAutorunOnDeploy, async () => {
this.registerCommand(VscodeCommand.rokuAutomationViewEnableAutorunOnDeploy, async () => {
await this.setAutorunOnDeploy(true);
}));
});

subscriptions.push(vscode.commands.registerCommand(VscodeCommand.rokuAutomationViewDisableAutorunOnDeploy, async () => {
this.registerCommand(VscodeCommand.rokuAutomationViewDisableAutorunOnDeploy, async () => {
await this.setAutorunOnDeploy(false);
}));
});

let autorunOnDeploy: boolean = this.extensionContext.workspaceState.get(WorkspaceStateKey.rokuAutomationAutorunOnDeploy);
// Default to true if not set
Expand All @@ -87,11 +83,9 @@ export class RokuAutomationViewViewProvider extends BaseRdbViewProvider {
private async setAutorunOnDeploy(autorunOnDeploy: boolean) {
this.rokuAutomationAutorunOnDeploy = autorunOnDeploy;
await vscodeContextManager.set('brightscript.rokuAutomationView.autorunOnDeploy', autorunOnDeploy);
await this.context.workspaceState.update(WorkspaceStateKey.rokuAutomationAutorunOnDeploy, autorunOnDeploy);
await this.extensionContext.workspaceState.update(WorkspaceStateKey.rokuAutomationAutorunOnDeploy, autorunOnDeploy);
}

private context: vscode.ExtensionContext;

private isRecording = false;
private rokuAutomationConfigs: {
name: string;
Expand Down
30 changes: 12 additions & 18 deletions src/viewProviders/RokuDeviceViewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class RokuDeviceViewViewProvider extends BaseRdbViewProvider {
constructor(context: vscode.ExtensionContext, dependencies) {
super(context, dependencies);

this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewEnableNodeInspector);
this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewDisableNodeInspector);
this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewRefreshScreenshot);
this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewPauseScreenshotCapture);
this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewResumeScreenshotCapture);
this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuDeviceViewCopyScreenshot, () => {
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewEnableNodeInspector);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewDisableNodeInspector);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewRefreshScreenshot);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewPauseScreenshotCapture);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewResumeScreenshotCapture);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuDeviceViewCopyScreenshot, () => {
// In order for copy to be successful the webview has to have focus
this.view.show(false);
});
Expand All @@ -34,20 +34,14 @@ export class RokuDeviceViewViewProvider extends BaseRdbViewProvider {
});
}
const result = await this.dependencies.rtaManager.device.getScreenshot();
this.postOrQueueMessage({
...message,
response: {
success: true,
arrayBuffer: result.buffer.buffer
}
this.createResponseMessage(message, {
success: true,
arrayBuffer: result.buffer.buffer
});
} catch (e) {
this.postOrQueueMessage({
...message,
response: {
success: false
}
});
this.postOrQueueMessage(this.createResponseMessage(message, {
success: false
}));
}
return true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/viewProviders/RokuFileSystemViewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class RokuFileSystemViewViewProvider extends BaseRdbViewProvider {
constructor(context: vscode.ExtensionContext, dependencies) {
super(context, dependencies);

this.registerCommandWithWebViewNotifier(context, VscodeCommand.rokuFileSystemViewRefresh);
this.registerCommandWithWebViewNotifier(VscodeCommand.rokuFileSystemViewRefresh);

this.addMessageCommandCallback(ViewProviderCommand.openRokuFile, async (message) => {
const pathContentsInfo = message.context;
Expand Down
Loading

0 comments on commit e9df0c0

Please sign in to comment.