@@ -16,12 +16,14 @@ import { ConnectionHandler } from './handler';
1616import { DockerConnectionHandler } from './handlers/docker' ;
1717import { StdioConnectionHandler } from './handlers/stdio' ;
1818import { TcpConnectionHandler } from './handlers/tcp' ;
19- import { ConnectionType , ProtocolType , PuppetInstallType } from './settings' ;
19+ import { ConnectionType , ProtocolType , PuppetInstallType , ISettings } from './settings' ;
2020import { ILogger } from './logging' ;
2121import { OutputChannelLogger } from './logging/outputchannel' ;
2222import { legacySettings , SettingsFromWorkspace } from './settings' ;
2323import { Reporter , reporter } from './telemetry/telemetry' ;
2424
25+ const axios = require ( 'axios' ) ;
26+
2527export const puppetLangID = 'puppet' ; // don't change this
2628export const puppetFileLangID = 'puppetfile' ; // don't change this
2729const debugType = 'Puppet' ; // don't change this
@@ -36,6 +38,7 @@ export function activate(context: vscode.ExtensionContext) {
3638 extContext = context ;
3739
3840 notifyOnNewExtensionVersion ( extContext ) ;
41+
3942 checkForLegacySettings ( ) ;
4043
4144 context . subscriptions . push ( new Reporter ( extContext ) ) ;
@@ -76,6 +79,12 @@ export function activate(context: vscode.ExtensionContext) {
7679 // This can be revisited to enable disabling language server portion
7780 return ;
7881 }
82+
83+ // this happens after checkInstallDirectory so that we don't check pdk version
84+ // if it's not installed
85+ if ( settings . pdk . checkVersion ) {
86+ notifyIfNewPDKVersion ( extContext , configSettings ) ;
87+ }
7988
8089 switch ( configSettings . workspace . editorService . protocol ) {
8190 case ProtocolType . STDIO :
@@ -232,3 +241,57 @@ async function notifyEditorServiceDisabled(context: vscode.ExtensionContext) {
232241 context . globalState . update ( suppressEditorServicesDisabled , true ) ;
233242 }
234243}
244+
245+ async function notifyIfNewPDKVersion ( context : vscode . ExtensionContext , settings :IAggregateConfiguration ) {
246+ const suppressPDKUpdateCheck = 'suppressPDKUpdateCheck' ;
247+ const dontCheckAgainNotice = "Don't check again" ;
248+ const viewPDKDownloadPage = "More info" ;
249+
250+ if ( context . globalState . get ( suppressPDKUpdateCheck , false ) ) {
251+ return ;
252+ }
253+
254+ let version = '' ;
255+ if ( settings . ruby . pdkVersion ) {
256+ version = settings . ruby . pdkVersion ;
257+ } else {
258+ // should we throw a warning here? technically this is only reached *if* a
259+ // PDK install is found, so the only way this is null is if the PDK_VERSION
260+ // file was removed.
261+ return ;
262+ }
263+
264+ axios . get ( 'https://s3.amazonaws.com/puppet-pdk/pdk/LATEST' )
265+ . then ( response => {
266+ return response . data ;
267+ } )
268+ . then ( latest_version => {
269+ if ( version !== latest_version ) {
270+ return vscode . window . showWarningMessage (
271+ `The installed PDK version is ${ version } , the newest version is ${ latest_version } . To find out how to update to the latest version click the more info button` ,
272+ { modal : false } ,
273+ { title : dontCheckAgainNotice } ,
274+ { title : viewPDKDownloadPage }
275+ ) ;
276+ }
277+ } )
278+ . then ( result => {
279+ if ( result === undefined ) {
280+ return ;
281+ }
282+
283+ if ( result . title === dontCheckAgainNotice ) {
284+ context . globalState . update ( suppressPDKUpdateCheck , true ) ;
285+ }
286+
287+ if ( result . title === viewPDKDownloadPage ) {
288+ vscode . commands . executeCommand (
289+ 'vscode.open' ,
290+ vscode . Uri . parse ( 'https://puppet.com/download-puppet-development-kit' )
291+ ) ;
292+ }
293+ } )
294+ . catch ( error => {
295+ logger . error ( error ) ;
296+ } ) ;
297+ }
0 commit comments