Skip to content

Commit c310d90

Browse files
authored
Opens the website when a vendordep is installed through Dep Manager (#731)
1 parent a1d5b59 commit c310d90

3 files changed

Lines changed: 73 additions & 13 deletions

File tree

vscode-wpilib/package.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"onCommand:wpilibcore.changeDesktop",
5454
"onCommand:wpilibcore.openApiDocumentation",
5555
"onCommand:wpilibcore.getProjectInformation",
56-
"onCommand:wpilibcore.runGradleClean"
56+
"onCommand:wpilibcore.runGradleClean",
57+
"onCommand:extension.showWebsite"
5758
],
5859
"main": "./out/extension",
5960
"contributes": {
@@ -177,17 +178,6 @@
177178
}
178179
},
179180
"commands": [
180-
{
181-
"command": "calicoColors.addColor",
182-
"category": "Calico Colors",
183-
"title": "Add Color"
184-
},
185-
{
186-
"command": "calicoColors.clearColors",
187-
"category": "Calico Colors",
188-
"title": "Clear Colors",
189-
"icon": "$(clear-all)"
190-
},
191181
{
192182
"command": "wpilibcore.startRioLog",
193183
"title": "%wpilibcore.startRioLog.title%",
@@ -416,6 +406,10 @@
416406
"title": "%wpilibcore.runGradleClean.title%",
417407
"category": "WPILib",
418408
"enablement": "isWorkspaceTrusted"
409+
},
410+
{
411+
"command": "extension.showWebsite",
412+
"title": "Show Website"
419413
}
420414
],
421415
"views": {

vscode-wpilib/src/dependencyView.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface IJsonList {
1515
uuid: string;
1616
description: string;
1717
website: string;
18+
instructions: string;
1819
}
1920

2021
export interface IDepInstalled { name: string; currentVersion: string; versionInfo: { version: string, buttonText: string }[]; }
@@ -226,6 +227,9 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
226227
const success = await this.vendorLibraries.installDependency(dep, this.vendorLibraries.getWpVendorFolder(this.wp), true);
227228

228229
if (success) {
230+
if (avail.instructions) {
231+
await vscode.commands.executeCommand('extension.showWebsite', avail.instructions, dep.name);
232+
}
229233
this.changed = Date.now();
230234

231235
if (dep.requires) {
@@ -236,6 +240,7 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
236240
const newDep = await this.listToDependency(reqDep);
237241
if (reqDep && newDep) {
238242
await this.vendorLibraries.installDependency(newDep, this.vendorLibraries.getWpVendorFolder(this.wp), true);
243+
// Do not show install instructions for required deps only selected.
239244
}
240245
}
241246
}
@@ -406,7 +411,8 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
406411
version: i18n('ui', homedep.version),
407412
uuid: i18n('ui', homedep.uuid),
408413
description: i18n('ui', 'Loaded from Local Copy'),
409-
website: i18n('ui', 'Loaded from Local Copy')
414+
website: i18n('ui', 'Loaded from Local Copy'),
415+
instructions: i18n('ui', 'Loaded from Local Copy')
410416
};
411417
const found = this.onlineDeps.find(onlinedep => onlinedep.uuid === depList.uuid && onlinedep.version === depList.version);
412418
if (!found) {

vscode-wpilib/src/extension.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,70 @@ export async function activate(context: vscode.ExtensionContext) {
438438

439439
await handleAfterTrusted(externalApi, context, creationError, extensionResourceLocation, gradle2020import, help);
440440

441+
// Register the command with arguments
442+
let disposable = vscode.commands.registerCommand(
443+
'extension.showWebsite',
444+
(url: string, tabTitle: string) => {
445+
// If no arguments were passed, you can prompt the user (optional):
446+
if (!url) {
447+
vscode.window.showErrorMessage('URL not provided!');
448+
return;
449+
}
450+
if (!tabTitle) {
451+
tabTitle = "My Website"; // fallback title if not provided
452+
}
453+
454+
// Create and show a new webview panel
455+
const panel = vscode.window.createWebviewPanel(
456+
'myWebview', // internal identifier
457+
tabTitle, // use the dynamic title
458+
vscode.ViewColumn.One,
459+
{
460+
enableScripts: true,
461+
retainContextWhenHidden: true
462+
}
463+
);
464+
465+
// Set the HTML content of the webview
466+
panel.webview.html = getWebviewContent(url);
467+
}
468+
);
469+
470+
context.subscriptions.push(disposable);
471+
441472
return externalApi;
442473
}
443474

444475
// this method is called when your extension is deactivated
445476
export function deactivate() {
446477
closeLogger();
447478
}
479+
480+
function getWebviewContent(url: string): string {
481+
// Basic HTML that includes an iframe to your target website.
482+
// NOTE: This will only work if the site allows iframes.
483+
return `<!DOCTYPE html>
484+
<html lang="en">
485+
<head>
486+
<meta charset="UTF-8">
487+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
488+
<style>
489+
body, html {
490+
padding: 0;
491+
margin: 0;
492+
height: 100%;
493+
overflow: hidden;
494+
background: #fff;
495+
}
496+
iframe {
497+
border: none;
498+
width: 100%;
499+
height: 100%;
500+
}
501+
</style>
502+
</head>
503+
<body>
504+
<iframe src="${url}" sandbox="allow-scripts allow-same-origin"></iframe>
505+
</body>
506+
</html>`;
507+
}

0 commit comments

Comments
 (0)