0.1.6 updates and add changelog

This commit is contained in:
2026-05-28 01:49:33 +08:00
parent 16847a78ca
commit afbf504957
14 changed files with 385 additions and 21 deletions

122
src/changelogView.ts Normal file
View File

@@ -0,0 +1,122 @@
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
export function openChangelog(context: vscode.ExtensionContext) {
const panel = vscode.window.createWebviewPanel(
'hplToolbox.changelog',
'HPL Toolbox Changelog',
vscode.ViewColumn.One,
{ enableScripts: false }
);
const changelogPath = path.join(context.extensionPath, 'CHANGELOG.md');
let markdown = '# Changelog\n\nCHANGELOG.md was not found.';
try {
markdown = fs.readFileSync(changelogPath, 'utf8');
} catch {
// Keep the fallback text readable in packaged or development installs.
}
panel.webview.html = getHtml(renderMarkdown(markdown));
}
function getHtml(content: string): string {
return `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 18px;
font-family: var(--vscode-font-family);
font-size: var(--vscode-font-size);
background: var(--vscode-editor-background);
color: var(--vscode-foreground);
}
main {
max-width: 840px;
margin: 0 auto;
}
h1 {
margin: 0 0 14px;
font-size: 20px;
line-height: 1.25;
}
h2 {
margin: 18px 0 8px;
padding-top: 12px;
border-top: 1px solid var(--vscode-panel-border);
font-size: 15px;
line-height: 1.3;
}
ul {
margin: 6px 0 12px;
padding-left: 20px;
}
li {
margin: 4px 0;
line-height: 1.45;
}
p {
margin: 8px 0;
line-height: 1.5;
}
</style>
</head>
<body>
<main>${content}</main>
</body>
</html>`;
}
function renderMarkdown(markdown: string): string {
const lines = markdown.replace(/\r\n/g, '\n').split('\n');
const html: string[] = [];
let inList = false;
const closeList = () => {
if (inList) {
html.push('</ul>');
inList = false;
}
};
for (const rawLine of lines) {
const line = rawLine.trim();
if (!line) {
closeList();
continue;
}
const heading = line.match(/^(#{1,3})\s+(.+)$/);
if (heading) {
closeList();
const level = Math.min(heading[1].length, 2);
html.push(`<h${level}>${escapeHtml(heading[2])}</h${level}>`);
continue;
}
const listItem = line.match(/^-\s+(.+)$/);
if (listItem) {
if (!inList) {
html.push('<ul>');
inList = true;
}
html.push(`<li>${escapeHtml(listItem[1])}</li>`);
continue;
}
closeList();
html.push(`<p>${escapeHtml(line)}</p>`);
}
closeList();
return html.join('\n');
}
function escapeHtml(value: string): string {
return value.replace(/[&<>"']/g, ch => ({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
}[ch] ?? ch));
}

View File

@@ -6,6 +6,7 @@ import { openBase64Scanner } from './tools/base64Scanner';
import { openMraidChecker } from './tools/mraidChecker';
import { openSendToMobile } from './tools/sendToMobile';
import { openPlayworksConverter } from './tools/playworksConverter';
import { openChangelog } from './changelogView';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
@@ -15,6 +16,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('hplToolbox.openMraidChecker', () => openMraidChecker(context)),
vscode.commands.registerCommand('hplToolbox.openSendToMobile', () => openSendToMobile(context)),
vscode.commands.registerCommand('hplToolbox.openPlayworksConverter', () => openPlayworksConverter(context)),
vscode.commands.registerCommand('hplToolbox.openChangelog', () => openChangelog(context)),
vscode.window.registerWebviewViewProvider('hplToolbox.launcher', new LauncherViewProvider(context))
);
}

View File

@@ -55,6 +55,8 @@ export class LauncherViewProvider implements vscode.WebviewViewProvider {
view.webview.onDidReceiveMessage(async (msg) => {
if (msg?.type === 'open' && typeof msg.command === 'string') {
vscode.commands.executeCommand(msg.command);
} else if (msg?.type === 'openChangelog') {
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);
@@ -142,15 +144,15 @@ function getHtml(version: string, betaToolsEnabled: boolean): string {
.footer {
margin-top: auto;
padding-top: 8px;
display: flex;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
justify-content: space-between;
gap: 8px;
color: var(--vscode-descriptionForeground);
font-size: 8px;
border-top: 1px solid var(--vscode-panel-border);
}
.beta-toggle {
.footer-action {
padding: 0;
background: transparent;
color: var(--vscode-descriptionForeground);
@@ -161,12 +163,20 @@ function getHtml(version: string, betaToolsEnabled: boolean): string {
font-size: 10px;
opacity: 0.72;
}
.beta-toggle:hover {
#betaToggle {
justify-self: start;
}
.footer-action:hover {
opacity: 1;
text-decoration: underline;
}
.footer-version {
opacity: 0.75;
text-align: center;
white-space: nowrap;
}
.changelog-link {
justify-self: end;
text-align: right;
}
</style>
@@ -176,8 +186,9 @@ function getHtml(version: string, betaToolsEnabled: boolean): string {
${toolButtons}
</div>
<div class="footer">
<button id="betaToggle" class="beta-toggle" data-enabled="${betaToolsEnabled ? 'true' : 'false'}">${betaToolsEnabled ? 'Hide beta' : 'Show beta'}</button>
<button id="betaToggle" class="footer-action" data-enabled="${betaToolsEnabled ? 'true' : 'false'}">${betaToolsEnabled ? 'Hide beta' : 'Show beta'}</button>
<span class="footer-version">${version} - JJGC 00784</span>
<button id="changelogLink" class="footer-action changelog-link">Changelog</button>
</div>
<script>
const vscode = acquireVsCodeApi();
@@ -190,6 +201,9 @@ ${toolButtons}
const enabled = event.currentTarget.dataset.enabled === 'true';
vscode.postMessage({ type: 'setBetaToolsEnabled', enabled: !enabled });
});
document.getElementById('changelogLink').addEventListener('click', () => {
vscode.postMessage({ type: 'openChangelog' });
});
</script>
</body>
</html>`;