@@ -261,115 +261,135 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
261261 else {
262262 item . text = '🚀 Insiders Edition' ;
263263 }
264- item . detail = 'Checking for Updates...' ;
265- item . busy = true ;
266- fetch ( 'https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json' )
267- . then ( res => res . json ( ) )
268- . then ( ( json : {
269- latest : string ;
270- versions : {
271- version : string ;
272- date : string ;
273- downloads : {
274- GitHub : string ;
275- AFDIAN : string ;
276- } ;
277- } [ ] ;
278- } ) => {
279- item . detail = undefined ;
280- item . command = {
281- title : 'Select Version' ,
282- command : 'vue-insiders.update' ,
264+ checkUpdate ( ) ;
265+
266+ async function checkUpdate ( ) {
267+ item . detail = 'Checking for Updates...' ;
268+ item . busy = true ;
269+ let succeed = false ;
270+ for ( const url of [
271+ 'https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json' ,
272+ 'https://cdn.jsdelivr.net/gh/vuejs/language-tools/insiders.json' ,
273+ ] ) {
274+ try {
275+ const res = await fetch ( url ) ;
276+ onJson ( await res . json ( ) ) ;
277+ succeed = true ;
278+ break ;
279+ } catch { }
280+ }
281+ item . busy = false ;
282+ if ( ! succeed ) {
283+ item . detail = 'Failed to Fetch Versions' ;
284+ item . severity = vscode . LanguageStatusSeverity . Error ;
285+ }
286+ }
287+
288+ function onJson ( json : {
289+ latest : string ;
290+ versions : {
291+ version : string ;
292+ date : string ;
293+ downloads : {
294+ GitHub : string ;
295+ AFDIAN : string ;
283296 } ;
284- if (
285- json . versions . some ( version => version . version === context . extension . packageJSON . version )
286- && context . extension . packageJSON . version !== json . latest
287- ) {
288- item . detail = 'New Version Available!' ;
289- item . severity = vscode . LanguageStatusSeverity . Warning ;
290- }
291- vscode . commands . registerCommand ( 'vue-insiders.update' , async ( ) => {
292- const quickPickItems : { [ version : string ] : vscode . QuickPickItem ; } = { } ;
293- for ( const { version, date } of json . versions ) {
294- let description = date ;
295- if ( context . extension . packageJSON . version === version ) {
296- description += ' (current)' ;
297+ } [ ] ;
298+ } ) {
299+ item . detail = undefined ;
300+ item . command = {
301+ title : 'Select Version' ,
302+ command : 'vue-insiders.update' ,
303+ } ;
304+ if (
305+ json . versions . some ( version => version . version === context . extension . packageJSON . version )
306+ && context . extension . packageJSON . version !== json . latest
307+ ) {
308+ item . detail = 'New Version Available!' ;
309+ item . severity = vscode . LanguageStatusSeverity . Warning ;
310+ vscode . window
311+ . showInformationMessage ( 'New Insiders Version Available!' , 'Download' )
312+ . then ( download => {
313+ if ( download ) {
314+ vscode . commands . executeCommand ( 'vue-insiders.update' ) ;
297315 }
298- quickPickItems [ version ] = {
299- label : version ,
300- description,
301- } ;
302- }
303- const version = await quickPick ( [ quickPickItems , {
304- learnMore : {
305- label : 'Learn more about Insiders Edition' ,
306- } ,
307- joinViaGitHub : {
308- label : 'Join via GitHub Sponsors' ,
309- } ,
310- joinViaAFDIAN : {
311- label : 'Join via AFDIAN (爱发电)' ,
312- } ,
313- } ] ) ;
314- if ( version === 'learnMore' ) {
315- vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition' ) ) ;
316- }
317- else if ( version === 'joinViaGitHub' ) {
318- vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/sponsors/johnsoncodehk' ) ) ;
319- }
320- else if ( version === 'joinViaAFDIAN' ) {
321- vscode . env . openExternal ( vscode . Uri . parse ( 'https://afdian.net/a/johnsoncodehk' ) ) ;
316+ } ) ;
317+ }
318+ vscode . commands . registerCommand ( 'vue-insiders.update' , async ( ) => {
319+ const quickPickItems : { [ version : string ] : vscode . QuickPickItem ; } = { } ;
320+ for ( const { version, date } of json . versions ) {
321+ let description = date ;
322+ if ( context . extension . packageJSON . version === version ) {
323+ description += ' (current)' ;
322324 }
323- else {
324- const downloads = json . versions . find ( v => v . version === version ) ?. downloads ;
325- if ( downloads ) {
326- const quickPickItems : { [ key : string ] : vscode . QuickPickItem ; } = {
327- GitHub : {
328- label : `${ version } - GitHub Releases` ,
329- description : 'Access via GitHub Sponsors' ,
330- detail : downloads . GitHub ,
331- } ,
332- AFDIAN : {
333- label : `${ version } - Insiders 电圈` ,
334- description : 'Access via AFDIAN (爱发电)' ,
335- detail : downloads . AFDIAN ,
336- } ,
337- } ;
338- const otherItems : { [ key : string ] : vscode . QuickPickItem ; } = {
339- learnMore : {
340- label : 'Learn more about Insiders Edition' ,
341- } ,
342- joinViaGitHub : {
343- label : 'Join via GitHub Sponsors' ,
344- } ,
345- joinViaAFDIAN : {
346- label : 'Join via AFDIAN (爱发电)' ,
347- } ,
348- } ;
349- const option = await quickPick ( [ quickPickItems , otherItems ] ) ;
350- if ( option === 'learnMore' ) {
351- vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition' ) ) ;
352- }
353- else if ( option === 'joinViaGitHub' ) {
354- vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/sponsors/johnsoncodehk' ) ) ;
355- }
356- else if ( option === 'joinViaAFDIAN' ) {
357- vscode . env . openExternal ( vscode . Uri . parse ( 'https://afdian.net/a/johnsoncodehk' ) ) ;
358- }
359- else if ( option ) {
360- vscode . env . openExternal ( vscode . Uri . parse ( downloads [ option as keyof typeof downloads ] ) ) ;
361- }
325+ quickPickItems [ version ] = {
326+ label : version ,
327+ description,
328+ } ;
329+ }
330+ const version = await quickPick ( [ quickPickItems , {
331+ learnMore : {
332+ label : 'Learn more about Insiders Edition' ,
333+ } ,
334+ joinViaGitHub : {
335+ label : 'Join via GitHub Sponsors' ,
336+ } ,
337+ joinViaAFDIAN : {
338+ label : 'Join via AFDIAN (爱发电)' ,
339+ } ,
340+ } ] ) ;
341+ if ( version === 'learnMore' ) {
342+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition' ) ) ;
343+ }
344+ else if ( version === 'joinViaGitHub' ) {
345+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/sponsors/johnsoncodehk' ) ) ;
346+ }
347+ else if ( version === 'joinViaAFDIAN' ) {
348+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://afdian.net/a/johnsoncodehk' ) ) ;
349+ }
350+ else {
351+ const downloads = json . versions . find ( v => v . version === version ) ?. downloads ;
352+ if ( downloads ) {
353+ const quickPickItems : { [ key : string ] : vscode . QuickPickItem ; } = {
354+ GitHub : {
355+ label : `${ version } - GitHub Releases` ,
356+ description : 'Access via GitHub Sponsors' ,
357+ detail : downloads . GitHub ,
358+ } ,
359+ AFDIAN : {
360+ label : `${ version } - Insiders 电圈` ,
361+ description : 'Access via AFDIAN (爱发电)' ,
362+ detail : downloads . AFDIAN ,
363+ } ,
364+ } ;
365+ const otherItems : { [ key : string ] : vscode . QuickPickItem ; } = {
366+ learnMore : {
367+ label : 'Learn more about Insiders Edition' ,
368+ } ,
369+ joinViaGitHub : {
370+ label : 'Join via GitHub Sponsors' ,
371+ } ,
372+ joinViaAFDIAN : {
373+ label : 'Join via AFDIAN (爱发电)' ,
374+ } ,
375+ } ;
376+ const option = await quickPick ( [ quickPickItems , otherItems ] ) ;
377+ if ( option === 'learnMore' ) {
378+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition' ) ) ;
379+ }
380+ else if ( option === 'joinViaGitHub' ) {
381+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/sponsors/johnsoncodehk' ) ) ;
382+ }
383+ else if ( option === 'joinViaAFDIAN' ) {
384+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://afdian.net/a/johnsoncodehk' ) ) ;
385+ }
386+ else if ( option ) {
387+ vscode . env . openExternal ( vscode . Uri . parse ( downloads [ option as keyof typeof downloads ] ) ) ;
362388 }
363389 }
364- } ) ;
365- } )
366- . catch ( ( ) => {
367- item . detail = 'Failed to Fetch Versions' ;
368- item . severity = vscode . LanguageStatusSeverity . Warning ;
369- } )
370- . finally ( ( ) => {
371- item . busy = false ;
390+ }
372391 } ) ;
392+ }
373393
374394 async function requestReloadVscode ( msg : string ) {
375395 const reload = await vscode . window . showInformationMessage ( msg , 'Reload Window' ) ;
0 commit comments