diff --git a/src/commands/CaptureScreenshotCommand.ts b/src/commands/CaptureScreenshotCommand.ts index c054694f..58d00a6f 100644 --- a/src/commands/CaptureScreenshotCommand.ts +++ b/src/commands/CaptureScreenshotCommand.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { extension } from '../extension'; +import * as fsExtra from 'fs-extra'; import * as rokuDeploy from 'roku-deploy'; import type { BrightScriptCommands } from '../BrightScriptCommands'; @@ -8,21 +8,46 @@ export const FILE_SCHEME = 'bs-captureScreenshot'; export class CaptureScreenshotCommand { public register(context: vscode.ExtensionContext, BrightScriptCommandsInstance: BrightScriptCommands) { + context.subscriptions.push(vscode.commands.registerCommand('extension.brightscript.captureScreenshot', async (hostParam?: string) => { + let host: string; + let password: string; - context.subscriptions.push(vscode.commands.registerCommand('extension.brightscript.captureScreenshot', async() => { - await BrightScriptCommandsInstance.getRemoteHost(); - await BrightScriptCommandsInstance.getRemotePassword(); - await BrightScriptCommandsInstance.getWorkspacePath(); + //if a hostParam was not provided, then go the normal flow for getting info + if (!hostParam) { + host = await BrightScriptCommandsInstance.getRemoteHost(); + password = await BrightScriptCommandsInstance.getRemotePassword(); - let host = BrightScriptCommandsInstance.host; - let pass = BrightScriptCommandsInstance.password; - let outDirPath = BrightScriptCommandsInstance.workspacePath + '/temp/screenshots/'; - let filename = 'screenshot-' + new Date(Date.now()).toISOString(); - let status = await rokuDeploy.takeScreenshot({ host: host, password: pass, outDir: outDirPath, outFile: filename }); - if (status) { - void vscode.window.showInformationMessage(`Screenshot saved at: ` + status); - void vscode.commands.executeCommand('vscode.open', vscode.Uri.file(status)); + //the host was provided, probably by clicking the "capture screenshot" link in the tree view. Do we have a password stored as well? If not, prompt for one + } else { + host = hostParam; + let remoteHost = await context.workspaceState.get('remoteHost'); + if (host === remoteHost) { + password = context.workspaceState.get('remotePassword'); + } else { + password = await vscode.window.showInputBox({ + placeHolder: `Please enter the developer password for host '${host}'`, + value: '' + }); + } } + + await vscode.window.withProgress({ + title: `Capturing screenshot from '${host}'`, + location: vscode.ProgressLocation.Notification + }, async () => { + try { + let screenshotPath = await rokuDeploy.takeScreenshot({ + host: host, + password: password + }); + if (screenshotPath) { + void vscode.window.showInformationMessage(`Screenshot saved at: ` + screenshotPath); + void vscode.commands.executeCommand('vscode.open', vscode.Uri.file(screenshotPath)); + } + } catch (e) { + void vscode.window.showErrorMessage('Could not capture screenshot'); + } + }); })); } }