Skip to content

Commit

Permalink
feat(vscode): check update for insiders edition
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 24, 2024
1 parent cb1c335 commit 804f472
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 17 deletions.
127 changes: 110 additions & 17 deletions extensions/vscode/src/common.ts
Expand Up @@ -8,6 +8,7 @@ import * as splitEditors from './features/splitEditors';
import * as semver from 'semver';
import * as fs from 'fs';
import * as path from 'path';
import { quickPick } from '@volar/vscode/lib/common';

let client: lsp.BaseLanguageClient;

Expand Down Expand Up @@ -228,26 +229,118 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang

const item = vscode.languages.createLanguageStatusItem('vue-insider', 'vue');
if (!context.extension.packageJSON.version.includes('-insider')) {
item.text = '✨ Get Vue - Official Insiders';
item.text = '✨ Get Insiders Edition';
item.severity = vscode.LanguageStatusSeverity.Warning;
item.command = {
title: 'More Info',
command: 'vscode.open',
arguments: ['https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'],
};
}
else {
item.text = '🚀 Vue - Official Insiders';
item.detail = 'Installed';
item.command = {
title: 'Changelog',
command: 'vue-insiders.checkUpdate',
};
vscode.commands.registerCommand('vue-insiders.checkUpdate', () => {
const updateUrl = 'https://github.com/vuejs/language-tools/blob/master/CHANGELOG.md';
vscode.env.openExternal(vscode.Uri.parse(updateUrl));
});
item.text = '🚀 Insiders Edition';
}
item.detail = 'Checking for Updates...';
item.busy = true;
fetch('https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json')
.then(res => res.json())
.then((json: {
latest: string;
versions: {
version: string;
date: string;
downloads: {
GitHub: string;
AFDIAN: string;
};
}[];
}) => {
item.detail = undefined;
item.command = {
title: 'Select Version',
command: 'vue-insiders.update',
};
if (json.versions.some(version => version.version === context.extension.packageJSON.version)) {
item.detail = 'New Version Available!';
item.severity = vscode.LanguageStatusSeverity.Warning;
}
vscode.commands.registerCommand('vue-insiders.update', async () => {
const quickPickItems: { [version: string]: vscode.QuickPickItem; } = {};
for (const { version, date } of json.versions) {
let description = date;
if (context.extension.packageJSON.version === version) {
description += ' (current)';
}
quickPickItems[version] = {
label: version,
description,
};
}
const version = await quickPick([quickPickItems, {
learnMore: {
label: 'Learn more about Insiders Edition',
},
joinViaGitHub: {
label: 'Join via GitHub Sponsors',
},
joinViaAFDIAN: {
label: 'Join via AFDIAN (爱发电)',
},
}]);
if (version === 'learnMore') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'));
}
else if (version === 'joinViaGitHub') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/johnsoncodehk'));
}
else if (version === 'joinViaAFDIAN') {
vscode.env.openExternal(vscode.Uri.parse('https://afdian.net/a/johnsoncodehk'));
}
else {
const downloads = json.versions.find(v => v.version === version)?.downloads;
if (downloads) {
const quickPickItems: { [key: string]: vscode.QuickPickItem; } = {
GitHub: {
label: `${version} - GitHub Releases`,
description: 'Access via GitHub Sponsors',
detail: downloads.GitHub,
},
AFDIAN: {
label: `${version} - Insiders 电圈`,
description: 'Access via AFDIAN (爱发电)',
detail: downloads.AFDIAN,
},
};
const otherItems: { [key: string]: vscode.QuickPickItem; } = {
learnMore: {
label: 'Learn more about Insiders Edition',
},
joinViaGitHub: {
label: 'Join via GitHub Sponsors',
},
joinViaAFDIAN: {
label: 'Join via AFDIAN (爱发电)',
},
};
const option = await quickPick([quickPickItems, otherItems]);
if (option === 'learnMore') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'));
}
else if (option === 'joinViaGitHub') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/johnsoncodehk'));
}
else if (option === 'joinViaAFDIAN') {
vscode.env.openExternal(vscode.Uri.parse('https://afdian.net/a/johnsoncodehk'));
}
else if (option) {
vscode.env.openExternal(vscode.Uri.parse(downloads[option as keyof typeof downloads]));
}
}
}
});
})
.catch(() => {
item.detail = 'Failed to Fetch Versions';
item.severity = vscode.LanguageStatusSeverity.Warning;
})
.finally(() => {
item.busy = false;
});

async function requestReloadVscode(msg: string) {
const reload = await vscode.window.showInformationMessage(msg, 'Reload Window');
Expand Down Expand Up @@ -335,4 +428,4 @@ async function getInitializationOptions(
],
},
};
}
};
45 changes: 45 additions & 0 deletions insiders.json
@@ -0,0 +1,45 @@
{
"latest": "2.1.0-insiders.5",
"versions": [
{
"version": "2.1.0-insiders.5",
"date": "2024-4-22",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.5",
"AFDIAN": "https://afdian.net/p/25aca47c004e11ef8b445254001e7c00"
}
},
{
"version": "2.1.0-insiders.4",
"date": "2024-4-10",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.4",
"AFDIAN": "https://afdian.net/p/46a5f4a8f72011ee97fe52540025c377"
}
},
{
"version": "2.1.0-insiders.3",
"date": "2024-4-7",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.3",
"AFDIAN": "https://afdian.net/p/5bf99cfaf4ec11ee9e1f5254001e7c00"
}
},
{
"version": "2.1.0-insiders.2",
"date": "2024-4-4",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.3",
"AFDIAN": "https://afdian.net/p/d59d0dd8f29611ee88945254001e7c00"
}
},
{
"version": "2.1.0-insiders.1",
"date": "2024-3-28",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.1",
"AFDIAN": "https://afdian.net/p/ba0901a2edce11ee8f2e52540025c377"
}
}
]
}

0 comments on commit 804f472

Please sign in to comment.