@@ -207,39 +207,60 @@ export class Options {
207
207
return this . cache . api_key ;
208
208
}
209
209
210
+ let from = '' ;
211
+
210
212
const keyFromSettings = this . getApiKeyFromEditor ( ) ;
211
213
if ( ! Utils . apiKeyInvalid ( keyFromSettings ) ) {
212
214
this . cache . api_key = keyFromSettings ;
213
- return this . cache . api_key ;
215
+ from = 'settings.json editor' ;
214
216
}
215
217
216
218
const keyFromEnv = this . getApiKeyFromEnv ( ) ;
217
219
if ( ! Utils . apiKeyInvalid ( keyFromEnv ) ) {
220
+ if ( this . cache . api_key && this . cache . api_key !== keyFromEnv ) {
221
+ vscode . window . showErrorMessage (
222
+ `WakaTime API Key conflict. Your env key doesn't match your ${ from } key.` ,
223
+ ) ;
224
+ return this . cache . api_key ;
225
+ }
218
226
this . cache . api_key = keyFromEnv ;
219
- return this . cache . api_key ;
227
+ from = 'env var' ;
220
228
}
221
229
222
230
try {
223
231
const apiKeyFromVault = await this . getApiKeyFromVaultCmd ( ) ;
224
232
if ( ! Utils . apiKeyInvalid ( apiKeyFromVault ) ) {
233
+ if ( this . cache . api_key && this . cache . api_key !== apiKeyFromVault ) {
234
+ vscode . window . showErrorMessage (
235
+ `WakaTime API Key conflict. Your vault command key doesn't match your ${ from } key.` ,
236
+ ) ;
237
+ return this . cache . api_key ;
238
+ }
225
239
this . cache . api_key = apiKeyFromVault ;
226
- return this . cache . api_key ;
240
+ from = 'vault command' ;
227
241
}
228
242
} catch ( err ) { }
229
243
230
244
try {
231
245
const apiKey = await this . getSettingAsync < string > ( 'settings' , 'api_key' ) ;
232
- if ( ! Utils . apiKeyInvalid ( apiKey ) ) this . cache . api_key = apiKey ;
233
- return apiKey ;
246
+ if ( ! Utils . apiKeyInvalid ( apiKey ) ) {
247
+ if ( this . cache . api_key && this . cache . api_key !== apiKey ) {
248
+ vscode . window . showErrorMessage (
249
+ `WakaTime API Key conflict. Your ~/.wakatime.cfg key doesn't match your ${ from } key.` ,
250
+ ) ;
251
+ }
252
+ this . cache . api_key = apiKey ;
253
+ }
234
254
} catch ( err ) {
235
255
this . logger . debug ( `Exception while reading API Key from config file: ${ err } ` ) ;
236
- if ( `${ err } ` . includes ( 'spawn EPERM' ) ) {
256
+ if ( ! this . cache . api_key && `${ err } ` . includes ( 'spawn EPERM' ) ) {
237
257
vscode . window . showErrorMessage (
238
258
'Microsoft Defender is blocking WakaTime. Please allow WakaTime to run so it can upload code stats to your dashboard.' ,
239
259
) ;
240
260
}
241
- return '' ;
242
261
}
262
+
263
+ return this . cache . api_key ?? '' ;
243
264
}
244
265
245
266
public async getApiKeyFromVaultCmd ( ) : Promise < string > {
0 commit comments