Skip to content

Commit

Permalink
TBD-126:
Browse files Browse the repository at this point in the history
1. Added support to show existing pkg file for rekey confirmation
2. Updated create package flow to confirm all the entries with user and ti update - if needed
  • Loading branch information
fumer-fubotv committed Feb 6, 2024
1 parent ac5dc9b commit 7255903
Showing 1 changed file with 64 additions and 40 deletions.
104 changes: 64 additions & 40 deletions src/commands/RekeyAndPackageCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export class RekeyAndPackageCommand {
}));

context.subscriptions.push(vscode.commands.registerCommand('extension.brightscript.createPackage', async (hostParam?: string) => {
await this.createPackage();
await this.createPackage({});
}));

context.subscriptions.push(vscode.commands.registerCommand('extension.brightscript.rekeyAndPackage', async (hostParam?: string) => {
await this.rekeyDevice();
await this.createPackage();
await this.createPackage({});
}));
}

Expand Down Expand Up @@ -78,7 +78,7 @@ export class RekeyAndPackageCommand {
rekeyConfig.signingPassword = content.signingPassword;
}

if (content.rekeySignedPackage.includes('./')) {
if (content.rekeySignedPackage?.includes('./')) {
await this.brightScriptCommands.getWorkspacePath();
let workspacePath = this.brightScriptCommands.workspacePath;
rekeyConfig.rekeySignedPackage = workspacePath + content.rekeySignedPackage.replace('./', '/');
Expand Down Expand Up @@ -114,12 +114,22 @@ export class RekeyAndPackageCommand {
throw new Error('Cancelled');
}

let response = await vscode.window.showInformationMessage(
'Please choose a signed package (a .pkg file) to rekey your device',
{ modal: true },
'Open file picker'
);
if (response === 'Open file picker') {
let response = '';
if (rekeyConfig.rekeySignedPackage !== '') {
response = await vscode.window.showInformationMessage(
'Please choose a signed package (a .pkg file) to rekey your device',
{ modal: true,
detail: `Current file: ${rekeyConfig.rekeySignedPackage}` },
'Use the current file', 'Pick a different file'
);
} else {
response = await vscode.window.showInformationMessage(
'Please choose a signed package (a .pkg file) to rekey your device',
{ modal: true },
'Open file picker'
);
}
if ((response === 'Open file picker') || (response === 'Pick a different file')) {
const options: vscode.OpenDialogOptions = {
canSelectMany: false,
openLabel: 'Select signed package file',
Expand All @@ -133,6 +143,8 @@ export class RekeyAndPackageCommand {
if (fileUri?.[0]) {
rekeyConfig.rekeySignedPackage = fileUri[0].fsPath;
}
} else if (response === 'Use the current file') {
//Use the same package
} else {
throw new Error('Cancelled');
}
Expand All @@ -153,18 +165,18 @@ export class RekeyAndPackageCommand {
}
}

private async createPackage() {
private async createPackage(defaultValues) {
await this.brightScriptCommands.getWorkspacePath();
let workspacePath = this.brightScriptCommands.workspacePath;

let rokuDeployOptions = {
rootDir: '',
outDir: workspacePath + '/out',
outFile: '',
retainStagingDir: true,
host: '',
password: '',
signingPassword: ''
let rokuDeployOptions: RokuDeployOptions = {
rootDir: defaultValues?.rootDir ? defaultValues.rootDir : '',
outDir: defaultValues?.outDir ? defaultValues.outDir : workspacePath + '/out',
outFile: defaultValues?.outFile ? defaultValues.outFile : '',
retainStagingDir: defaultValues?.retainStagingDir ? defaultValues.retainStagingDir : true,
host: defaultValues?.host ? defaultValues.host : '',
password: defaultValues?.password ? defaultValues.password : '',
signingPassword: defaultValues?.signingPassword ? defaultValues.signingPassword : ''
};

let PACKAGE_FOLDER = 'Pick a folder';
Expand All @@ -188,43 +200,45 @@ export class RekeyAndPackageCommand {
break;
}

await this.brightScriptCommands.getRemoteHost(false);
await this.brightScriptCommands.getRemotePassword(false);
let host = this.brightScriptCommands.host;
let remotePassword = this.brightScriptCommands.password;
let signingPassword = await this.brightScriptCommands.getSigningPassword(false);

let hostValue = rokuDeployOptions.host ? rokuDeployOptions.host : host;
let passwordValue = rokuDeployOptions.password ? rokuDeployOptions.password : remotePassword;
let signingPasswordValue = rokuDeployOptions.signingPassword ? rokuDeployOptions.signingPassword : signingPassword;

rokuDeployOptions.host = await vscode.window.showInputBox({
title: 'Enter IP address of the Roku device',
value: hostValue ? hostValue : ''
});
rokuDeployOptions.host = await this.userInputManager.promptForHost();

rokuDeployOptions.password = await vscode.window.showInputBox({
title: 'Enter password for the Roku device',
value: passwordValue ? passwordValue : ''
placeHolder: 'Enter password for the Roku device',
value: rokuDeployOptions.password ?? ''
});
if (!rokuDeployOptions.password) {
throw new Error('Cancelled');
}

rokuDeployOptions.signingPassword = await vscode.window.showInputBox({
title: 'Enter signingPassword to be used to rekey the Roku',
value: signingPasswordValue ? signingPasswordValue : ''
value: rokuDeployOptions.signingPassword ?? ''
});

let confirmText = 'Create Package';
let cancelText = 'Cancel';
let response = await vscode.window.showInformationMessage(
'Please confirm details below to create package \n' + JSON.stringify(rokuDeployOptions),
...[confirmText, cancelText]
);
let changeText = 'I want to change something';
let response = await vscode.window.showInformationMessage('Create Package info:', {
modal: true,
detail: [
`host: ${rokuDeployOptions.host}`,
`password: ${rokuDeployOptions.password}`,
`signing password: ${rokuDeployOptions.signingPassword}`,
`outDir: ${rokuDeployOptions.outDir}`,
`outFile: ${rokuDeployOptions.outFile}`,
`rootDir: ${rokuDeployOptions.rootDir}`,
`retainStagingDir: ${rokuDeployOptions.retainStagingDir}`
].join('\n')
}, confirmText, changeText);

if (response === confirmText) {
//create a zip and pkg file of the app based on the selected launch config
await rokuDeploy.createPackage(rokuDeployOptions);
let remotePkgPath = await rokuDeploy.signExistingPackage(rokuDeployOptions);
await rokuDeploy.retrieveSignedPackage(remotePkgPath, rokuDeployOptions);
void vscode.window.showInformationMessage(`Package successfully created!`);

} else if (response === changeText) {
return this.createPackage(rokuDeployOptions);
}
}
}
Expand Down Expand Up @@ -354,4 +368,14 @@ interface RekeyConfig {
password: string;
}

interface RokuDeployOptions {
rootDir: string;
outDir: string;
outFile: string;
retainStagingDir: boolean;
host: string;
password: string;
signingPassword: string;
}

export const rekeyAndPackageCommand = new RekeyAndPackageCommand();

0 comments on commit 7255903

Please sign in to comment.