@@ -4,8 +4,10 @@ import * as archiveFilesystemProvider from './archive-filesystem-provider';
4
4
import { DistributionConfigListener , QueryServerConfigListener , QueryHistoryConfigListener } from './config' ;
5
5
import { DatabaseManager } from './databases' ;
6
6
import { 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' ;
9
11
import * as helpers from './helpers' ;
10
12
import { spawnIdeServer } from './ide-server' ;
11
13
import { InterfaceManager , WebviewReveal } from './interface' ;
@@ -83,29 +85,32 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
83
85
helpers . showAndLogErrorMessage ( `Can't execute ${ command } : waiting to finish loading CodeQL CLI.` ) ;
84
86
} ) ;
85
87
86
- interface ReportingConfig {
88
+ interface DistributionUpdateConfig {
89
+ isUserInitiated : boolean ;
87
90
shouldDisplayMessageWhenNoUpdates : boolean ;
88
- shouldErrorIfUpdateFails : boolean ;
89
91
}
90
92
91
- async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , reportingConfig : ReportingConfig ) : Promise < void > {
92
- const result = await distributionManager . checkForUpdatesToExtensionManagedDistribution ( ) ;
93
+ async function installOrUpdateDistributionWithProgressTitle ( progressTitle : string , config : DistributionUpdateConfig ) : Promise < void > {
94
+ const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
95
+ const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates ?
96
+ helpers . showAndLogInformationMessage : async ( message : string ) => logger . log ( message ) ;
97
+ const result = await distributionManager . checkForUpdatesToExtensionManagedDistribution ( minSecondsSinceLastUpdateCheck ) ;
93
98
switch ( result . kind ) {
99
+ case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
100
+ logger . log ( "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
101
+ `${ minSecondsSinceLastUpdateCheck } seconds.` ) ;
102
+ break ;
94
103
case DistributionUpdateCheckResultKind . AlreadyUpToDate :
95
- if ( reportingConfig . shouldDisplayMessageWhenNoUpdates ) {
96
- helpers . showAndLogInformationMessage ( "CodeQL CLI already up to date." ) ;
97
- }
104
+ await noUpdatesLoggingFunc ( "CodeQL CLI already up to date." ) ;
98
105
break ;
99
- case DistributionUpdateCheckResultKind . InvalidDistributionLocation :
100
- if ( reportingConfig . shouldDisplayMessageWhenNoUpdates ) {
101
- helpers . showAndLogErrorMessage ( "CodeQL CLI is installed externally so could not be updated." ) ;
102
- }
106
+ case DistributionUpdateCheckResultKind . InvalidLocation :
107
+ await noUpdatesLoggingFunc ( "CodeQL CLI is installed externally so could not be updated." ) ;
103
108
break ;
104
109
case DistributionUpdateCheckResultKind . UpdateAvailable :
105
110
if ( beganMainExtensionActivation ) {
106
111
const updateAvailableMessage = `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
107
112
"The update will be installed after Visual Studio Code restarts. Restart now to upgrade?" ;
108
- ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
113
+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
109
114
if ( await helpers . showInformationMessageWithAction ( updateAvailableMessage , "Restart and Upgrade" ) ) {
110
115
await commands . executeCommand ( "workbench.action.reloadWindow" ) ;
111
116
}
@@ -118,7 +123,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
118
123
await helpers . withProgress ( progressOptions , progress =>
119
124
distributionManager . installExtensionManagedDistributionRelease ( result . updatedRelease , progress ) ) ;
120
125
121
- ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
126
+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
122
127
helpers . showAndLogInformationMessage ( `CodeQL CLI updated to version "${ result . updatedRelease . name } ".` ) ;
123
128
}
124
129
break ;
@@ -127,7 +132,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
127
132
}
128
133
}
129
134
130
- async function installOrUpdateDistribution ( reportingConfig : ReportingConfig ) : Promise < void > {
135
+ async function installOrUpdateDistribution ( config : DistributionUpdateConfig ) : Promise < void > {
131
136
if ( isInstallingOrUpdatingDistribution ) {
132
137
throw new Error ( "Already installing or updating CodeQL CLI" ) ;
133
138
}
@@ -137,11 +142,11 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
137
142
const messageText = willUpdateCodeQl ? "Updating CodeQL CLI" :
138
143
codeQlInstalled ? "Checking for updates to CodeQL CLI" : "Installing CodeQL CLI" ;
139
144
try {
140
- await installOrUpdateDistributionWithProgressTitle ( messageText , reportingConfig ) ;
145
+ await installOrUpdateDistributionWithProgressTitle ( messageText , config ) ;
141
146
} catch ( e ) {
142
147
// Don't rethrow the exception, because if the config is changed, we want to be able to retry installing
143
148
// or updating the distribution.
144
- const alertFunction = ( codeQlInstalled && ! reportingConfig . shouldErrorIfUpdateFails ) ?
149
+ const alertFunction = ( codeQlInstalled && ! config . isUserInitiated ) ?
145
150
helpers . showAndLogWarningMessage : helpers . showAndLogErrorMessage ;
146
151
const taskDescription = ( willUpdateCodeQl ? "update" :
147
152
codeQlInstalled ? "check for updates to" : "install" ) + " CodeQL CLI" ;
@@ -180,8 +185,8 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
180
185
return result ;
181
186
}
182
187
183
- async function installOrUpdateThenTryActivate ( reportingConfig : ReportingConfig ) : Promise < void > {
184
- await installOrUpdateDistribution ( reportingConfig ) ;
188
+ async function installOrUpdateThenTryActivate ( config : DistributionUpdateConfig ) : Promise < void > {
189
+ await installOrUpdateDistribution ( config ) ;
185
190
186
191
// Display the warnings even if the extension has already activated.
187
192
const distributionResult = await getDistributionDisplayingDistributionWarnings ( ) ;
@@ -194,26 +199,26 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
194
199
const chosenAction = await helpers . showAndLogErrorMessage ( `Can't execute ${ command } : missing CodeQL CLI.` , installActionName ) ;
195
200
if ( chosenAction === installActionName ) {
196
201
installOrUpdateThenTryActivate ( {
197
- shouldDisplayMessageWhenNoUpdates : false ,
198
- shouldErrorIfUpdateFails : true
202
+ isUserInitiated : true ,
203
+ shouldDisplayMessageWhenNoUpdates : false
199
204
} ) ;
200
205
}
201
206
} ) ;
202
207
}
203
208
}
204
209
205
210
ctx . subscriptions . push ( distributionConfigListener . onDidChangeDistributionConfiguration ( ( ) => installOrUpdateThenTryActivate ( {
206
- shouldDisplayMessageWhenNoUpdates : false ,
207
- shouldErrorIfUpdateFails : true
211
+ isUserInitiated : true ,
212
+ shouldDisplayMessageWhenNoUpdates : false
208
213
} ) ) ) ;
209
214
ctx . subscriptions . push ( commands . registerCommand ( checkForUpdatesCommand , ( ) => installOrUpdateThenTryActivate ( {
210
- shouldDisplayMessageWhenNoUpdates : true ,
211
- shouldErrorIfUpdateFails : true
215
+ isUserInitiated : true ,
216
+ shouldDisplayMessageWhenNoUpdates : true
212
217
} ) ) ) ;
213
218
214
219
await installOrUpdateThenTryActivate ( {
215
- shouldDisplayMessageWhenNoUpdates : false ,
216
- shouldErrorIfUpdateFails : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey )
220
+ isUserInitiated : ! ! ctx . globalState . get ( shouldUpdateOnNextActivationKey ) ,
221
+ shouldDisplayMessageWhenNoUpdates : false
217
222
} ) ;
218
223
}
219
224
0 commit comments