Skip to content

Commit

Permalink
Better password handling. Use default temp screenshot dir
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 12, 2023
1 parent 0c9728a commit 0700ae8
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/commands/CaptureScreenshotCommand.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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');
}
});
}));
}
}
Expand Down

0 comments on commit 0700ae8

Please sign in to comment.