@@ -16,12 +16,14 @@ import { ConnectionHandler } from './handler';
16
16
import { DockerConnectionHandler } from './handlers/docker' ;
17
17
import { StdioConnectionHandler } from './handlers/stdio' ;
18
18
import { TcpConnectionHandler } from './handlers/tcp' ;
19
- import { ConnectionType , ProtocolType , PuppetInstallType } from './settings' ;
19
+ import { ConnectionType , ProtocolType , PuppetInstallType , ISettings } from './settings' ;
20
20
import { ILogger } from './logging' ;
21
21
import { OutputChannelLogger } from './logging/outputchannel' ;
22
22
import { legacySettings , SettingsFromWorkspace } from './settings' ;
23
23
import { Reporter , reporter } from './telemetry/telemetry' ;
24
24
25
+ const axios = require ( 'axios' ) ;
26
+
25
27
export const puppetLangID = 'puppet' ; // don't change this
26
28
export const puppetFileLangID = 'puppetfile' ; // don't change this
27
29
const debugType = 'Puppet' ; // don't change this
@@ -36,6 +38,7 @@ export function activate(context: vscode.ExtensionContext) {
36
38
extContext = context ;
37
39
38
40
notifyOnNewExtensionVersion ( extContext ) ;
41
+
39
42
checkForLegacySettings ( ) ;
40
43
41
44
context . subscriptions . push ( new Reporter ( extContext ) ) ;
@@ -76,6 +79,12 @@ export function activate(context: vscode.ExtensionContext) {
76
79
// This can be revisited to enable disabling language server portion
77
80
return ;
78
81
}
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
+ }
79
88
80
89
switch ( configSettings . workspace . editorService . protocol ) {
81
90
case ProtocolType . STDIO :
@@ -232,3 +241,57 @@ async function notifyEditorServiceDisabled(context: vscode.ExtensionContext) {
232
241
context . globalState . update ( suppressEditorServicesDisabled , true ) ;
233
242
}
234
243
}
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