@@ -93,31 +93,36 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
9393 interface DistributionUpdateConfig {
9494 isUserInitiated : boolean ;
9595 shouldDisplayMessageWhenNoUpdates : boolean ;
96+ allowAutoUpdating : boolean ;
9697 }
9798
9899 async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , config : DistributionUpdateConfig ) : Promise < void > {
99100 const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
100101 const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates ?
101102 helpers . showAndLogInformationMessage : async ( message : string ) => logger . log ( message ) ;
102103 const result = await distributionManager . checkForUpdatesToExtensionManagedDistribution ( minSecondsSinceLastUpdateCheck ) ;
104+
105+ // We do want to auto update if there is no distribution at all
106+ const allowAutoUpdating = config . allowAutoUpdating || ! await distributionManager . hasDistribution ( ) ;
107+
103108 switch ( result . kind ) {
104109 case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
105110 logger . log ( "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
106111 `${ minSecondsSinceLastUpdateCheck } seconds.` ) ;
107112 break ;
108113 case DistributionUpdateCheckResultKind . AlreadyUpToDate :
109- await noUpdatesLoggingFunc ( " CodeQL CLI already up to date." ) ;
114+ await noUpdatesLoggingFunc ( ' CodeQL CLI already up to date.' ) ;
110115 break ;
111116 case DistributionUpdateCheckResultKind . InvalidLocation :
112- await noUpdatesLoggingFunc ( " CodeQL CLI is installed externally so could not be updated." ) ;
117+ await noUpdatesLoggingFunc ( ' CodeQL CLI is installed externally so could not be updated.' ) ;
113118 break ;
114119 case DistributionUpdateCheckResultKind . UpdateAvailable :
115- if ( beganMainExtensionActivation ) {
120+ if ( beganMainExtensionActivation || ! allowAutoUpdating ) {
116121 const updateAvailableMessage = `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
117- "The update will be installed after Visual Studio Code restarts. Restart now to upgrade?" ;
122+ 'Do you wish to upgrade?' ;
118123 await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
119- if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , " Restart and Upgrade" ) ) {
120- await commands . executeCommand ( " workbench.action.reloadWindow" ) ;
124+ if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , ' Restart and Upgrade' ) ) {
125+ await commands . executeCommand ( ' workbench.action.reloadWindow' ) ;
121126 }
122127 } else {
123128 const progressOptions : ProgressOptions = {
@@ -144,8 +149,12 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
144149 isInstallingOrUpdatingDistribution = true ;
145150 const codeQlInstalled = await distributionManager . getCodeQlPathWithoutVersionCheck ( ) !== undefined ;
146151 const willUpdateCodeQl = ctx . globalState . get ( shouldUpdateOnNextActivationKey ) ;
147- const messageText = willUpdateCodeQl ? "Updating CodeQL CLI" :
148- codeQlInstalled ? "Checking for updates to CodeQL CLI" : "Installing CodeQL CLI" ;
152+ const messageText = willUpdateCodeQl
153+ ? "Updating CodeQL CLI"
154+ : codeQlInstalled
155+ ? "Checking for updates to CodeQL CLI"
156+ : "Installing CodeQL CLI" ;
157+
149158 try {
150159 await installOrUpdateDistributionWithProgressTitle ( messageText , config ) ;
151160 } catch ( e ) {
@@ -207,7 +216,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
207216 if ( chosenAction === installActionName ) {
208217 installOrUpdateThenTryActivate ( {
209218 isUserInitiated : true ,
210- shouldDisplayMessageWhenNoUpdates : false
219+ shouldDisplayMessageWhenNoUpdates : false ,
220+ allowAutoUpdating : true
211221 } ) ;
212222 }
213223 } ) ;
@@ -216,16 +226,22 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
216226
217227 ctx . subscriptions . push ( distributionConfigListener . onDidChangeDistributionConfiguration ( ( ) => installOrUpdateThenTryActivate ( {
218228 isUserInitiated : true ,
219- shouldDisplayMessageWhenNoUpdates : false
229+ shouldDisplayMessageWhenNoUpdates : false ,
230+ allowAutoUpdating : true
220231 } ) ) ) ;
221232 ctx . subscriptions . push ( commands . registerCommand ( checkForUpdatesCommand , ( ) => installOrUpdateThenTryActivate ( {
222233 isUserInitiated : true ,
223- shouldDisplayMessageWhenNoUpdates : true
234+ shouldDisplayMessageWhenNoUpdates : true ,
235+ allowAutoUpdating : true
224236 } ) ) ) ;
225237
226238 await installOrUpdateThenTryActivate ( {
227239 isUserInitiated : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey ) ,
228- shouldDisplayMessageWhenNoUpdates : false
240+ shouldDisplayMessageWhenNoUpdates : false ,
241+
242+ // only auto update on startup if the user has previously requested an update
243+ // otherwise, ask user to accept the update
244+ allowAutoUpdating : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey )
229245 } ) ;
230246}
231247
0 commit comments