@@ -93,32 +93,36 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
9393 interface DistributionUpdateConfig {
9494 isUserInitiated : boolean ;
9595 shouldDisplayMessageWhenNoUpdates : boolean ;
96- avoidAutoUpdating : boolean ;
96+ allowAutoUpdating : boolean ;
9797 }
9898
9999 async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , config : DistributionUpdateConfig ) : Promise < void > {
100100 const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
101101 const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates ?
102102 helpers . showAndLogInformationMessage : async ( message : string ) => logger . log ( message ) ;
103103 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+
104108 switch ( result . kind ) {
105109 case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
106110 logger . log ( "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
107111 `${ minSecondsSinceLastUpdateCheck } seconds.` ) ;
108112 break ;
109113 case DistributionUpdateCheckResultKind . AlreadyUpToDate :
110- await noUpdatesLoggingFunc ( " CodeQL CLI already up to date." ) ;
114+ await noUpdatesLoggingFunc ( ' CodeQL CLI already up to date.' ) ;
111115 break ;
112116 case DistributionUpdateCheckResultKind . InvalidLocation :
113- 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.' ) ;
114118 break ;
115119 case DistributionUpdateCheckResultKind . UpdateAvailable :
116- if ( beganMainExtensionActivation || config . avoidAutoUpdating ) {
120+ if ( beganMainExtensionActivation || ! allowAutoUpdating ) {
117121 const updateAvailableMessage = `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
118- "The update will be installed after Visual Studio Code restarts. Restart now to upgrade?" ;
122+ 'Do you wish to upgrade?' ;
119123 await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
120- if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , " Restart and Upgrade" ) ) {
121- await commands . executeCommand ( " workbench.action.reloadWindow" ) ;
124+ if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , ' Restart and Upgrade' ) ) {
125+ await commands . executeCommand ( ' workbench.action.reloadWindow' ) ;
122126 }
123127 } else {
124128 const progressOptions : ProgressOptions = {
@@ -148,8 +152,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
148152 const messageText = willUpdateCodeQl
149153 ? "Updating CodeQL CLI"
150154 : codeQlInstalled
151- ? "Checking for updates to CodeQL CLI"
152- : "Installing CodeQL CLI" ;
155+ ? "Checking for updates to CodeQL CLI"
156+ : "Installing CodeQL CLI" ;
153157
154158 try {
155159 await installOrUpdateDistributionWithProgressTitle ( messageText , config ) ;
@@ -213,7 +217,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
213217 installOrUpdateThenTryActivate ( {
214218 isUserInitiated : true ,
215219 shouldDisplayMessageWhenNoUpdates : false ,
216- avoidAutoUpdating : false
220+ allowAutoUpdating : true
217221 } ) ;
218222 }
219223 } ) ;
@@ -223,21 +227,21 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
223227 ctx . subscriptions . push ( distributionConfigListener . onDidChangeDistributionConfiguration ( ( ) => installOrUpdateThenTryActivate ( {
224228 isUserInitiated : true ,
225229 shouldDisplayMessageWhenNoUpdates : false ,
226-
227- // only auto update on startup if the user has previously requested an update
228- // otherwise, ask user to accept the update
229- avoidAutoUpdating : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey )
230+ allowAutoUpdating : true
230231 } ) ) ) ;
231232 ctx . subscriptions . push ( commands . registerCommand ( checkForUpdatesCommand , ( ) => installOrUpdateThenTryActivate ( {
232233 isUserInitiated : true ,
233234 shouldDisplayMessageWhenNoUpdates : true ,
234- avoidAutoUpdating : false
235+ allowAutoUpdating : true
235236 } ) ) ) ;
236237
237238 await installOrUpdateThenTryActivate ( {
238239 isUserInitiated : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey ) ,
239240 shouldDisplayMessageWhenNoUpdates : false ,
240- avoidAutoUpdating : true
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 )
241245 } ) ;
242246}
243247
0 commit comments