Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands to rekey device and create packages #509

Merged
merged 30 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
52c6de5
Add ability to capture device screenshots
fumer-fubotv Oct 9, 2023
a564c7b
Add ability to capture device screenshots
fumer-fubotv Oct 9, 2023
323c4f1
Merge branch 'master' into ROKU-1008
fumer-fubotv Oct 9, 2023
ab5629e
Feature request: add ability to rekey/sign apps
fumer-fubotv Oct 13, 2023
a83dc75
Conflict resoluiton
fumer-fubotv Oct 13, 2023
273d71c
remove stale code
fumer-fubotv Oct 13, 2023
53ee647
remove redundent code
fumer-fubotv Oct 13, 2023
01b9ac6
TBD-126
fumer-fubotv Oct 20, 2023
b83a203
TBD-126
fumer-fubotv Oct 27, 2023
1a1320e
Update BrightScriptCommands.ts
fumer-fubotv Oct 27, 2023
ddb09fc
Merge branch 'master' of https://github.com/rokucommunity/vscode-brig…
TwitchBronBron Nov 8, 2023
6aed36a
Refined the flow a bit
TwitchBronBron Jan 29, 2024
ac5dc9b
Merge branch 'master' of https://github.com/rokucommunity/vscode-brig…
TwitchBronBron Jan 29, 2024
7255903
TBD-126:
fumer-fubotv Feb 6, 2024
c000830
Merge branch 'master' into TBD-126
TwitchBronBron Feb 6, 2024
af5fb8b
TBD-126
fumer-fubotv Feb 8, 2024
cc1d493
Merge branch 'TBD-126' of https://github.com/rokucommunity/vscode-bri…
fumer-fubotv Feb 8, 2024
18ffa58
TBD-126
fumer-fubotv Feb 12, 2024
b4c9e93
Merge branch 'master' into TBD-126
fumer-fubotv Feb 13, 2024
7e4d3bb
Update RekeyAndPackageCommand.ts
fumer-fubotv Feb 14, 2024
f1d28ed
Merge branch 'TBD-126' of https://github.com/rokucommunity/vscode-bri…
fumer-fubotv Feb 14, 2024
a9f1f6b
TBD-126
fumer-fubotv Feb 16, 2024
804c139
Use `open` to open folder instead of custom function
TwitchBronBron Mar 12, 2024
c131512
Normalize a few file paths
TwitchBronBron Mar 12, 2024
d947737
Better rekeySignedPackage handling when empty string
TwitchBronBron Mar 12, 2024
efabd97
simplify default config
TwitchBronBron Mar 12, 2024
b0ddb52
Show .pkg in summary
TwitchBronBron Mar 12, 2024
63d251c
Use correct file paths in more dialogs
TwitchBronBron Mar 12, 2024
2f75871
Merge branch 'master' of https://github.com/rokucommunity/vscode-brig…
TwitchBronBron Mar 12, 2024
c65fa35
Remove unused funcs in BrightScriptCommands.ts
TwitchBronBron Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,21 @@
"category": "BrighterScript",
"icon": "./images/icons/inspect-active.svg"
},
{
"command": "extension.brightscript.rekeyDevice",
"title": "Rekey Device",
"category": "BrighterScript"
},
{
"command": "extension.brightscript.createPackage",
"title": "Create Package",
"category": "BrighterScript"
},
{
"command": "extension.brightscript.rekeyAndPackage",
"title": "Rekey Device and Create Package",
"category": "BrighterScript"
},
{
"command": "extension.brightscript.captureScreenshot",
"title": "Capture Screenshot",
Expand Down
113 changes: 113 additions & 0 deletions src/BrightScriptCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { util as rokuDebugUtil } from 'roku-debug/dist/util';
import type { RemoteControlManager, RemoteControlModeInitiator } from './managers/RemoteControlManager';
import type { WhatsNewManager } from './managers/WhatsNewManager';
import type { ActiveDeviceManager } from './ActiveDeviceManager';
import * as rokuDeploy from 'roku-deploy';
import * as path from 'path';

export class BrightScriptCommands {

Expand All @@ -26,6 +28,8 @@ export class BrightScriptCommands {
public host: string;
public password: string;
public workspacePath: string;
private signingPassword: string;
private signedPackagePath: string;
TwitchBronBron marked this conversation as resolved.
Show resolved Hide resolved
private keypressNotifiers = [] as ((key: string, literalCharacter: boolean) => void)[];

public registerCommands() {
Expand Down Expand Up @@ -201,9 +205,78 @@ export class BrightScriptCommands {
}
});

this.registerCommand('rekeyDevice', async () => {
await this.rekeyDevice();
});

this.registerCommand('createPackage', async () => {
await this.createPackage();
});

this.registerCommand('rekeyAndPackage', async () => {
await this.rekeyDevice().then(async () => {
await this.createPackage();
});
});

this.registerKeyboardInputs();
}

private async rekeyDevice() {
await this.getRemoteHost();
await this.getRemotePassword();
await this.getSigningPassword();
await this.getSignedPackagePath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should show a file picker for this.


await rokuDeploy.rekeyDevice({ host: this.host, password: this.password, signingPassword: this.signingPassword, rekeySignedPackage: this.signedPackagePath }
).then(() => void vscode.window.showInformationMessage(`Device successfully rekeyed!`));
}

private async createPackage() {
await this.getWorkspacePath();
let config = vscode.workspace.getConfiguration('launch', null);
const configurations = config.get<any[]>('configurations');
let configNames = [];
for (let config of configurations) {
configNames.push(config.name);
}

//show user a list of available launch configs to choose from
let selectedConfig = configurations[0];
let selectedConfigName = await vscode.window.showQuickPick(configNames, { placeHolder: 'Please select a config', canPickMany: false });
if (selectedConfigName) {
let selectedIndex = configNames.indexOf(selectedConfigName);
selectedConfig = configurations[selectedIndex];
}

if (selectedConfig.rootDir?.includes('${workspaceFolder}')) {
selectedConfig.rootDir = path.normalize(selectedConfig.rootDir.replace('${workspaceFolder}', this.workspacePath));
}

await this.getSigningPassword();
await this.getRemoteHost();
await this.getRemotePassword();

let rokuDeployOptions = {
rootDir: selectedConfig.rootDir,
files: selectedConfig.files,
outDir: this.workspacePath + '/out',
outFile: 'roku-' + selectedConfig.name.replace(/ /g, '-'),
retainStagingDir: true,
host: this.host,
password: this.password,
signingPassword: this.signingPassword
};

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

/**
* Registers all the commands for a-z, A-Z, 0-9, and all the primary character such as !, @, #, ', ", etc...
*/
Expand Down Expand Up @@ -408,6 +481,46 @@ export class BrightScriptCommands {
return this.workspacePath;
}

public async getSigningPassword() {
this.signingPassword = await this.context.workspaceState.get('signingPassword');
if (!this.signingPassword) {
let config = vscode.workspace.getConfiguration('brightscript.remoteControl', null);
this.signingPassword = config.get('signingPassword');
// eslint-disable-next-line no-template-curly-in-string
if (!this.signingPassword) {
this.signingPassword = await vscode.window.showInputBox({
placeHolder: 'Enter the signing password used for creating signed packages',
value: ''
});
}
}
if (!this.signingPassword) {
throw new Error('Can\'t send command: signingPassword is required.');
} else {
await this.context.workspaceState.update('signingPassword', this.signingPassword);
}
}

public async getSignedPackagePath() {
this.signedPackagePath = await this.context.workspaceState.get('signedPackagePath');
if (!this.signedPackagePath) {
let config = vscode.workspace.getConfiguration('brightscript.remoteControl', null);
this.signedPackagePath = config.get('signedPackagePath');
// eslint-disable-next-line no-template-curly-in-string
if (!this.signedPackagePath) {
this.signedPackagePath = await vscode.window.showInputBox({
placeHolder: 'Enter the path for the signed package',
value: ''
});
}
}
if (!this.signedPackagePath) {
throw new Error('Can\'t send command: Signed Package Path is required.');
} else {
await this.context.workspaceState.update('signedPackagePath', this.signedPackagePath);
}
}

public registerKeypressNotifier(notifier: (key: string, literalCharacter: boolean) => void) {
this.keypressNotifiers.push(notifier);
}
Expand Down