@@ -4,8 +4,10 @@ import * as archiveFilesystemProvider from './archive-filesystem-provider';
44import { DistributionConfigListener , QueryServerConfigListener , QueryHistoryConfigListener } from './config' ;
55import { DatabaseManager } from './databases' ;
66import { DatabaseUI } from './databases-ui' ;
7- import { DistributionUpdateCheckResultKind , DistributionManager , FindDistributionResult , FindDistributionResultKind , GithubApiError ,
8- DEFAULT_DISTRIBUTION_VERSION_CONSTRAINT , GithubRateLimitedError } from './distribution' ;
7+ import {
8+ DistributionUpdateCheckResultKind , DistributionManager , FindDistributionResult , FindDistributionResultKind , GithubApiError ,
9+ DEFAULT_DISTRIBUTION_VERSION_CONSTRAINT , GithubRateLimitedError
10+ } from './distribution' ;
911import * as helpers from './helpers' ;
1012import { spawnIdeServer } from './ide-server' ;
1113import { InterfaceManager , WebviewReveal } from './interface' ;
@@ -86,29 +88,32 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
8688 helpers . showAndLogErrorMessage ( `Can't execute ${ command } : waiting to finish loading CodeQL CLI.` ) ;
8789 } ) ;
8890
89- interface ReportingConfig {
91+ interface DistributionUpdateConfig {
92+ isUserInitiated : boolean ;
9093 shouldDisplayMessageWhenNoUpdates : boolean ;
91- shouldErrorIfUpdateFails : boolean ;
9294 }
9395
94- async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , reportingConfig : ReportingConfig ) : Promise < void > {
95- const result = await distributionManager . checkForUpdatesToExtensionManagedDistribution ( ) ;
96+ async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , config : DistributionUpdateConfig ) : Promise < void > {
97+ const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
98+ const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates ?
99+ helpers . showAndLogInformationMessage : async ( message : string ) => logger . log ( message ) ;
100+ const result = await distributionManager . checkForUpdatesToExtensionManagedDistribution ( minSecondsSinceLastUpdateCheck ) ;
96101 switch ( result . kind ) {
102+ case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
103+ logger . log ( "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
104+ `${ minSecondsSinceLastUpdateCheck } seconds.` ) ;
105+ break ;
97106 case DistributionUpdateCheckResultKind . AlreadyUpToDate :
98- if ( reportingConfig . shouldDisplayMessageWhenNoUpdates ) {
99- helpers . showAndLogInformationMessage ( "CodeQL CLI already up to date." ) ;
100- }
107+ await noUpdatesLoggingFunc ( "CodeQL CLI already up to date." ) ;
101108 break ;
102- case DistributionUpdateCheckResultKind . InvalidDistributionLocation :
103- if ( reportingConfig . shouldDisplayMessageWhenNoUpdates ) {
104- helpers . showAndLogErrorMessage ( "CodeQL CLI is installed externally so could not be updated." ) ;
105- }
109+ case DistributionUpdateCheckResultKind . InvalidLocation :
110+ await noUpdatesLoggingFunc ( "CodeQL CLI is installed externally so could not be updated." ) ;
106111 break ;
107112 case DistributionUpdateCheckResultKind . UpdateAvailable :
108113 if ( beganMainExtensionActivation ) {
109114 const updateAvailableMessage = `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
110115 "The update will be installed after Visual Studio Code restarts. Restart now to upgrade?" ;
111- ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
116+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
112117 if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , "Restart and Upgrade" ) ) {
113118 await commands . executeCommand ( "workbench.action.reloadWindow" ) ;
114119 }
@@ -121,7 +126,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
121126 await helpers . withProgress ( progressOptions , progress =>
122127 distributionManager . installExtensionManagedDistributionRelease ( result . updatedRelease , progress ) ) ;
123128
124- ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
129+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
125130 helpers . showAndLogInformationMessage ( `CodeQL CLI updated to version "${ result . updatedRelease . name } ".` ) ;
126131 }
127132 break ;
@@ -130,7 +135,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
130135 }
131136 }
132137
133- async function installOrUpdateDistribution ( reportingConfig : ReportingConfig ) : Promise < void > {
138+ async function installOrUpdateDistribution ( config : DistributionUpdateConfig ) : Promise < void > {
134139 if ( isInstallingOrUpdatingDistribution ) {
135140 throw new Error ( "Already installing or updating CodeQL CLI" ) ;
136141 }
@@ -140,11 +145,11 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
140145 const messageText = willUpdateCodeQl ? "Updating CodeQL CLI" :
141146 codeQlInstalled ? "Checking for updates to CodeQL CLI" : "Installing CodeQL CLI" ;
142147 try {
143- await installOrUpdateDistributionWithProgressTitle ( messageText , reportingConfig ) ;
148+ await installOrUpdateDistributionWithProgressTitle ( messageText , config ) ;
144149 } catch ( e ) {
145150 // Don't rethrow the exception, because if the config is changed, we want to be able to retry installing
146151 // or updating the distribution.
147- const alertFunction = ( codeQlInstalled && ! reportingConfig . shouldErrorIfUpdateFails ) ?
152+ const alertFunction = ( codeQlInstalled && ! config . isUserInitiated ) ?
148153 helpers . showAndLogWarningMessage : helpers . showAndLogErrorMessage ;
149154 const taskDescription = ( willUpdateCodeQl ? "update" :
150155 codeQlInstalled ? "check for updates to" : "install" ) + " CodeQL CLI" ;
@@ -183,8 +188,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
183188 return result ;
184189 }
185190
186- async function installOrUpdateThenTryActivate ( reportingConfig : ReportingConfig ) : Promise < void > {
187- await installOrUpdateDistribution ( reportingConfig ) ;
191+ async function installOrUpdateThenTryActivate ( config : DistributionUpdateConfig ) : Promise < void > {
192+ await installOrUpdateDistribution ( config ) ;
188193
189194 // Display the warnings even if the extension has already activated.
190195 const distributionResult = await getDistributionDisplayingDistributionWarnings ( ) ;
@@ -197,26 +202,26 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
197202 const chosenAction = await helpers . showAndLogErrorMessage ( `Can't execute ${ command } : missing CodeQL CLI.` , installActionName ) ;
198203 if ( chosenAction === installActionName ) {
199204 installOrUpdateThenTryActivate ( {
200- shouldDisplayMessageWhenNoUpdates : false ,
201- shouldErrorIfUpdateFails : true
205+ isUserInitiated : true ,
206+ shouldDisplayMessageWhenNoUpdates : false
202207 } ) ;
203208 }
204209 } ) ;
205210 }
206211 }
207212
208213 ctx . subscriptions . push ( distributionConfigListener . onDidChangeDistributionConfiguration ( ( ) => installOrUpdateThenTryActivate ( {
209- shouldDisplayMessageWhenNoUpdates : false ,
210- shouldErrorIfUpdateFails : true
214+ isUserInitiated : true ,
215+ shouldDisplayMessageWhenNoUpdates : false
211216 } ) ) ) ;
212217 ctx . subscriptions . push ( commands . registerCommand ( checkForUpdatesCommand , ( ) => installOrUpdateThenTryActivate ( {
213- shouldDisplayMessageWhenNoUpdates : true ,
214- shouldErrorIfUpdateFails : true
218+ isUserInitiated : true ,
219+ shouldDisplayMessageWhenNoUpdates : true
215220 } ) ) ) ;
216221
217222 await installOrUpdateThenTryActivate ( {
218- shouldDisplayMessageWhenNoUpdates : false ,
219- shouldErrorIfUpdateFails : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey )
223+ isUserInitiated : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey ) ,
224+ shouldDisplayMessageWhenNoUpdates : false
220225 } ) ;
221226}
222227
0 commit comments