Skip to content

Commit

Permalink
feat(vscode): add timeout logic for insiders fetching (#5048)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Dec 20, 2024
1 parent 14f0b11 commit f35dfa0
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions extensions/vscode/src/insiders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,49 @@ import * as vscode from 'vscode';

export function useInsidersStatusItem(context: vscode.ExtensionContext) {
const item = vscode.languages.createLanguageStatusItem('vue-insider', 'vue');
item.text = 'Checking for Updates...';
item.busy = true;
let succeed = false;
item.command = {
title: 'Fetch Versions',
command: 'vue-insiders.fetch',
};
let status: 'idle' | 'pending' | 'success' = 'idle';

useCommand('vue-insiders.fetch', () => {
if (status === 'idle') {
fetchJson();
}
});

fetchJson();

async function fetchJson() {
item.busy = true;
item.text = 'Checking for Updates...';
item.severity = vscode.LanguageStatusSeverity.Warning;
status = 'pending';

for (const url of [
'https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json',
'https://cdn.jsdelivr.net/gh/vuejs/language-tools/insiders.json',
]) {
try {
const res = await fetch(url);
const controller = new AbortController();
setTimeout(() => controller.abort(), 15000);

const res = await fetch(url, {
signal: controller.signal,
});
onJson(await res.json() as any);
succeed = true;
status = 'success';
break;
}
catch { };
}

item.busy = false;
if (!succeed) {
if (status !== 'success') {
item.text = 'Failed to Fetch Versions';
item.severity = vscode.LanguageStatusSeverity.Error;
status = 'idle';
}
}

Expand Down

0 comments on commit f35dfa0

Please sign in to comment.