import { ExtensionContext , window , Uri , env } from 'vscode' ; import semver from 'semver' ; import { version } from '../package.json' ; interface Notification { id : string ; condition : string ; message : string ; buttons : { text : string ; url : string ; } [ ] ; } export function checkNotification ( ctx ) { const notifications = [ ] ; const previousVersion = ctx . globalState . get < string > ( 'version' ) || '0.0.0' ; const notificationIds = ( ctx . globalState . get < string > ( 'notifications-ids' ) || '' ) . split ( ',' ) ; for ( const notification of notifications ) { if ( notificationIds . includes ( notification . id ) ) continue ; if ( semver . satisfies ( previousVersion , notification . condition ) ) { notificationIds . push ( notification . id ) ; const buttonNames = notification . buttons . map ( b => b . text ) ; window . showInformationMessage ( notification . message , ... buttonNames ) . then ( ( result ) => { const button = notification . buttons . find ( i => i . text === result ) ; if ( button ) env . openExternal ( Uri . parse ( button . url ) ) ; } ) ; } } ctx . globalState . update ( 'notifications-ids' , notificationIds . join ( ',' ) ) ; ctx . globalState . update ( 'version' , version ) ; } export function clearNotificationState ( ctx ) { ctx . globalState . update ( 'notifications-ids' , undefined ) ; ctx . globalState . update ( 'version' , undefined ) ; }