import * as vscode from 'vscode'; const BETA_TOOLS_ENABLED_KEY = 'hplToolbox.betaTools.enabled'; interface ToolDefinition { command: string; title: string; description: string; beta?: boolean; } const TOOLS: ToolDefinition[] = [ { command: 'hplToolbox.openPlecUpload', title: 'PLEC Upload', description: 'Upload HTML to internal PLEC server', }, { command: 'hplToolbox.openApplovinUpload', title: 'AppLovin Playable Preview', description: 'Upload to p.applov.in (QR preview)', }, { command: 'hplToolbox.openBase64Scanner', title: 'Base64 Scanner', description: 'Find non-base64 assets in HTML', }, { command: 'hplToolbox.openMraidChecker', title: 'MRAID Checker', description: 'Check MRAID requirements and best practices', beta: true, }, { command: 'hplToolbox.openSendToMobile', title: 'Send To Mobile', description: 'Share HTML to a phone via LAN + QR', }, { command: 'hplToolbox.openPlayworksConverter', title: 'Playworks Converter', description: 'Convert Playworks HTML to per-network variants', beta: true, }, ]; export class LauncherViewProvider implements vscode.WebviewViewProvider { constructor(private readonly context: vscode.ExtensionContext) { } resolveWebviewView(view: vscode.WebviewView) { view.webview.options = { enableScripts: true }; const version = this.context.extension.packageJSON.version as string; const betaToolsEnabled = this.context.globalState.get(BETA_TOOLS_ENABLED_KEY, false); view.webview.html = getHtml(version, betaToolsEnabled); view.webview.onDidReceiveMessage(async (msg) => { if (msg?.type === 'open' && typeof msg.command === 'string') { vscode.commands.executeCommand(msg.command); } else if (msg?.type === 'setBetaToolsEnabled' && typeof msg.enabled === 'boolean') { await this.context.globalState.update(BETA_TOOLS_ENABLED_KEY, msg.enabled); view.webview.html = getHtml(version, msg.enabled); } }); } } function getHtml(version: string, betaToolsEnabled: boolean): string { const visibleTools = sortToolsForDisplay(TOOLS.filter(tool => betaToolsEnabled || !tool.beta)); const hiddenBetaCount = TOOLS.filter(tool => tool.beta).length - visibleTools.filter(tool => tool.beta).length; const toolButtons = visibleTools.map(renderToolButton).join('\n'); return `
${toolButtons}
`; } function sortToolsForDisplay(tools: ToolDefinition[]): ToolDefinition[] { return [...tools].sort((a, b) => Number(Boolean(a.beta)) - Number(Boolean(b.beta))); } function renderToolButton(tool: ToolDefinition): string { return ` `; } function escapeHtml(value: string): string { return value.replace(/[&<>"']/g, ch => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', }[ch] ?? ch)); }