Skip to content

Commit

Permalink
Opens the website when a vendordep is installed through Dep Manager (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondaming authored Dec 16, 2024
1 parent a1d5b59 commit c310d90
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
18 changes: 6 additions & 12 deletions vscode-wpilib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"onCommand:wpilibcore.changeDesktop",
"onCommand:wpilibcore.openApiDocumentation",
"onCommand:wpilibcore.getProjectInformation",
"onCommand:wpilibcore.runGradleClean"
"onCommand:wpilibcore.runGradleClean",
"onCommand:extension.showWebsite"
],
"main": "./out/extension",
"contributes": {
Expand Down Expand Up @@ -177,17 +178,6 @@
}
},
"commands": [
{
"command": "calicoColors.addColor",
"category": "Calico Colors",
"title": "Add Color"
},
{
"command": "calicoColors.clearColors",
"category": "Calico Colors",
"title": "Clear Colors",
"icon": "$(clear-all)"
},
{
"command": "wpilibcore.startRioLog",
"title": "%wpilibcore.startRioLog.title%",
Expand Down Expand Up @@ -416,6 +406,10 @@
"title": "%wpilibcore.runGradleClean.title%",
"category": "WPILib",
"enablement": "isWorkspaceTrusted"
},
{
"command": "extension.showWebsite",
"title": "Show Website"
}
],
"views": {
Expand Down
8 changes: 7 additions & 1 deletion vscode-wpilib/src/dependencyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IJsonList {
uuid: string;
description: string;
website: string;
instructions: string;
}

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

if (success) {
if (avail.instructions) {
await vscode.commands.executeCommand('extension.showWebsite', avail.instructions, dep.name);
}
this.changed = Date.now();

if (dep.requires) {
Expand All @@ -236,6 +240,7 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
const newDep = await this.listToDependency(reqDep);
if (reqDep && newDep) {
await this.vendorLibraries.installDependency(newDep, this.vendorLibraries.getWpVendorFolder(this.wp), true);
// Do not show install instructions for required deps only selected.
}
}
}
Expand Down Expand Up @@ -406,7 +411,8 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
version: i18n('ui', homedep.version),
uuid: i18n('ui', homedep.uuid),
description: i18n('ui', 'Loaded from Local Copy'),
website: i18n('ui', 'Loaded from Local Copy')
website: i18n('ui', 'Loaded from Local Copy'),
instructions: i18n('ui', 'Loaded from Local Copy')
};
const found = this.onlineDeps.find(onlinedep => onlinedep.uuid === depList.uuid && onlinedep.version === depList.version);
if (!found) {
Expand Down
60 changes: 60 additions & 0 deletions vscode-wpilib/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,70 @@ export async function activate(context: vscode.ExtensionContext) {

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

// Register the command with arguments
let disposable = vscode.commands.registerCommand(
'extension.showWebsite',
(url: string, tabTitle: string) => {
// If no arguments were passed, you can prompt the user (optional):
if (!url) {
vscode.window.showErrorMessage('URL not provided!');
return;
}
if (!tabTitle) {
tabTitle = "My Website"; // fallback title if not provided
}

// Create and show a new webview panel
const panel = vscode.window.createWebviewPanel(
'myWebview', // internal identifier
tabTitle, // use the dynamic title
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true
}
);

// Set the HTML content of the webview
panel.webview.html = getWebviewContent(url);
}
);

context.subscriptions.push(disposable);

return externalApi;
}

// this method is called when your extension is deactivated
export function deactivate() {
closeLogger();
}

function getWebviewContent(url: string): string {
// Basic HTML that includes an iframe to your target website.
// NOTE: This will only work if the site allows iframes.
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body, html {
padding: 0;
margin: 0;
height: 100%;
overflow: hidden;
background: #fff;
}
iframe {
border: none;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<iframe src="${url}" sandbox="allow-scripts allow-same-origin"></iframe>
</body>
</html>`;
}

0 comments on commit c310d90

Please sign in to comment.