v0.2.2
This commit is contained in:
@@ -9,6 +9,7 @@ import { openPlayworksConverter } from './tools/playworksConverter';
|
||||
import { openMintegralChecker } from './tools/mintegralChecker';
|
||||
import { openChangelog } from './changelogView';
|
||||
import { openDeviceSimulator } from './tools/deviceSimulator';
|
||||
import { checkForUpdates } from './updateChecker';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
@@ -21,8 +22,11 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.commands.registerCommand('hplToolbox.openMintegralChecker', () => openMintegralChecker(context)),
|
||||
vscode.commands.registerCommand('hplToolbox.openDeviceSimulator', () => openDeviceSimulator(context)),
|
||||
vscode.commands.registerCommand('hplToolbox.openChangelog', () => openChangelog(context)),
|
||||
vscode.commands.registerCommand('hplToolbox.checkForUpdates', () => checkForUpdates(context)),
|
||||
vscode.window.registerWebviewViewProvider('hplToolbox.launcher', new LauncherViewProvider(context))
|
||||
);
|
||||
|
||||
void checkForUpdates(context);
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
|
||||
@@ -62,6 +62,8 @@ export class LauncherViewProvider implements vscode.WebviewViewProvider {
|
||||
vscode.commands.executeCommand(msg.command);
|
||||
} else if (msg?.type === 'openChangelog') {
|
||||
vscode.commands.executeCommand('hplToolbox.openChangelog');
|
||||
} else if (msg?.type === 'checkForUpdates') {
|
||||
vscode.commands.executeCommand('hplToolbox.checkForUpdates');
|
||||
} 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, tools, this.context.globalState.get<string[]>(TOOL_ORDER_KEY, []));
|
||||
@@ -204,6 +206,7 @@ function getHtml(version: string, betaToolsEnabled: boolean, tools: ToolDefiniti
|
||||
opacity: 0.75;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
justify-self: center;
|
||||
}
|
||||
.changelog-link {
|
||||
justify-self: end;
|
||||
@@ -217,7 +220,7 @@ ${toolButtons}
|
||||
</div>
|
||||
<div class="footer">
|
||||
<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="updateCheck" class="footer-action footer-version" title="Check for updates">${version} - JJGC 00784</button>
|
||||
<button id="changelogLink" class="footer-action changelog-link">Changelog</button>
|
||||
</div>
|
||||
<script>
|
||||
@@ -269,6 +272,9 @@ ${toolButtons}
|
||||
document.getElementById('changelogLink').addEventListener('click', () => {
|
||||
vscode.postMessage({ type: 'openChangelog' });
|
||||
});
|
||||
document.getElementById('updateCheck').addEventListener('click', () => {
|
||||
vscode.postMessage({ type: 'checkForUpdates' });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
80
src/updateChecker.ts
Normal file
80
src/updateChecker.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const REMOTE_PACKAGE_JSON_URL = 'https://gitea.hesukastro.com/hesukastro/vsix-hpl-toolbox/raw/branch/main/package.json';
|
||||
|
||||
interface RemotePackageJson {
|
||||
version?: unknown;
|
||||
}
|
||||
|
||||
export async function checkForUpdates(context: vscode.ExtensionContext): Promise<void> {
|
||||
const currentVersion = String(context.extension.packageJSON.version ?? '').trim();
|
||||
|
||||
if (!currentVersion) {
|
||||
vscode.window.showWarningMessage('HPL Toolbox could not read the installed version.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const remoteVersion = await fetchRemoteVersion();
|
||||
const comparison = compareVersions(remoteVersion, currentVersion);
|
||||
|
||||
if (comparison > 0) {
|
||||
const action = await vscode.window.showInformationMessage(
|
||||
`HPL Toolbox update available: ${remoteVersion} (installed: ${currentVersion}).`,
|
||||
'Open Repository'
|
||||
);
|
||||
|
||||
if (action === 'Open Repository') {
|
||||
await vscode.env.openExternal(vscode.Uri.parse('https://gitea.hesukastro.com/hesukastro/vsix-hpl-toolbox'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
vscode.window.showInformationMessage(`HPL Toolbox is up to date (${currentVersion}).`);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
vscode.window.showWarningMessage(`HPL Toolbox update check failed: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchRemoteVersion(): Promise<string> {
|
||||
const response = await fetch(REMOTE_PACKAGE_JSON_URL, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`remote package.json returned HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const packageJson = await response.json() as RemotePackageJson;
|
||||
if (typeof packageJson.version !== 'string' || !packageJson.version.trim()) {
|
||||
throw new Error('remote package.json is missing a version');
|
||||
}
|
||||
|
||||
return packageJson.version.trim();
|
||||
}
|
||||
|
||||
function compareVersions(left: string, right: string): number {
|
||||
const leftParts = parseVersion(left);
|
||||
const rightParts = parseVersion(right);
|
||||
const length = Math.max(leftParts.length, rightParts.length);
|
||||
|
||||
for (let index = 0; index < length; index += 1) {
|
||||
const leftPart = leftParts[index] ?? 0;
|
||||
const rightPart = rightParts[index] ?? 0;
|
||||
|
||||
if (leftPart > rightPart) return 1;
|
||||
if (leftPart < rightPart) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function parseVersion(version: string): number[] {
|
||||
return version
|
||||
.split(/[.-]/)
|
||||
.map(part => Number.parseInt(part, 10))
|
||||
.filter(part => Number.isFinite(part));
|
||||
}
|
||||
Reference in New Issue
Block a user