drop zone, and remove beta tag from mraid checker

This commit is contained in:
2026-05-29 13:20:33 +08:00
parent a1d3fde774
commit 5625d94106
21 changed files with 632 additions and 48 deletions

View File

@@ -1,15 +1,18 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
const BETA_TOOLS_ENABLED_KEY = 'hplToolbox.betaTools.enabled';
interface ToolDefinition {
id?: string;
command: string;
title: string;
description: string;
beta?: boolean;
}
const TOOLS: ToolDefinition[] = [
const FALLBACK_TOOLS: ToolDefinition[] = [
{
command: 'hplToolbox.openPlecUpload',
title: 'PLEC Upload',
@@ -25,17 +28,16 @@ const TOOLS: ToolDefinition[] = [
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.openMraidChecker',
title: 'MRAID Checker',
description: 'Check MRAID requirements and best practices',
},
{
command: 'hplToolbox.openPlayworksConverter',
title: 'Playworks Converter',
@@ -50,8 +52,9 @@ export class LauncherViewProvider implements vscode.WebviewViewProvider {
resolveWebviewView(view: vscode.WebviewView) {
view.webview.options = { enableScripts: true };
const version = this.context.extension.packageJSON.version as string;
const tools = loadToolDefinitions(this.context.extensionPath);
const betaToolsEnabled = this.context.globalState.get<boolean>(BETA_TOOLS_ENABLED_KEY, false);
view.webview.html = getHtml(version, betaToolsEnabled);
view.webview.html = getHtml(version, betaToolsEnabled, tools);
view.webview.onDidReceiveMessage(async (msg) => {
if (msg?.type === 'open' && typeof msg.command === 'string') {
vscode.commands.executeCommand(msg.command);
@@ -59,14 +62,34 @@ export class LauncherViewProvider implements vscode.WebviewViewProvider {
vscode.commands.executeCommand('hplToolbox.openChangelog');
} 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);
view.webview.html = getHtml(version, msg.enabled, tools);
}
});
}
}
function getHtml(version: string, betaToolsEnabled: boolean): string {
const visibleTools = sortToolsForDisplay(TOOLS.filter(tool => betaToolsEnabled || !tool.beta));
function loadToolDefinitions(extensionPath: string): ToolDefinition[] {
const toolsPath = path.join(extensionPath, 'tools.json');
try {
const raw = JSON.parse(fs.readFileSync(toolsPath, 'utf8'));
if (!Array.isArray(raw)) return FALLBACK_TOOLS;
const tools = raw
.filter((tool: any) => tool && typeof tool.command === 'string' && typeof tool.title === 'string')
.map((tool: any) => ({
id: typeof tool.id === 'string' ? tool.id : undefined,
command: tool.command,
title: tool.title,
description: typeof tool.description === 'string' ? tool.description : '',
beta: Boolean(tool.beta),
}));
return tools.length ? tools : FALLBACK_TOOLS;
} catch {
return FALLBACK_TOOLS;
}
}
function getHtml(version: string, betaToolsEnabled: boolean, tools: ToolDefinition[]): string {
const visibleTools = sortToolsForDisplay(tools.filter(tool => betaToolsEnabled || !tool.beta));
const toolButtons = visibleTools.map(renderToolButton).join('\n');
return `<!DOCTYPE html>
<html>