@@ -5,7 +5,7 @@ const LAST_PROFILE_KEY = `currentProfile`;
5
5
const SOURCE_LIST_KEY = `sourceList` ;
6
6
const DEPLOYMENT_KEY = `deployment` ;
7
7
const DEBUG_KEY = `debug` ;
8
- const SERVER_SETTINGS_CACHE_KEY = ( name : string ) => `serverSettingsCache_${ name } ` ;
8
+ const SERVER_SETTINGS_CACHE_KEY = ( name : string ) => `serverSettingsCache_${ name } ` ;
9
9
const PREVIOUS_SEARCH_TERMS_KEY = `prevSearchTerms` ;
10
10
const RECENTLY_OPENED_FILES_KEY = `recentlyOpenedFiles` ;
11
11
const AUTHORISED_EXTENSIONS_KEY = `authorisedExtensions`
@@ -14,6 +14,13 @@ export type PathContent = Record<string, string[]>;
14
14
export type DeploymentPath = Record < string , string > ;
15
15
export type DebugCommands = Record < string , string > ;
16
16
17
+ type AuthorisedExtension = {
18
+ id : string
19
+ displayName : string
20
+ since : number
21
+ lastAccess : number
22
+ }
23
+
17
24
abstract class Storage {
18
25
protected readonly globalState ;
19
26
@@ -181,7 +188,7 @@ export class ConnectionStorage extends Storage {
181
188
return this . set ( DEBUG_KEY , existingCommands ) ;
182
189
}
183
190
184
- getWorkspaceDeployPath ( workspaceFolder : vscode . WorkspaceFolder ) {
191
+ getWorkspaceDeployPath ( workspaceFolder : vscode . WorkspaceFolder ) {
185
192
const deployDirs = this . get < DeploymentPath > ( DEPLOYMENT_KEY ) || { } ;
186
193
return deployDirs [ workspaceFolder . uri . fsPath ] . toLowerCase ( ) ;
187
194
}
@@ -198,26 +205,37 @@ export class ConnectionStorage extends Storage {
198
205
await this . set ( RECENTLY_OPENED_FILES_KEY , undefined ) ;
199
206
}
200
207
201
- async addAuthorizedExtension ( extension : string ) {
202
- const extensions = this . get < string [ ] > ( AUTHORISED_EXTENSIONS_KEY ) || [ ] ;
203
- if ( ! extensions . includes ( extension ) ) {
204
- extensions . push ( extension ) ;
208
+ async addAuthorisedExtension ( extension : vscode . Extension < any > ) {
209
+ const extensions = this . getAuthorisedExtensions ( ) ;
210
+ if ( ! this . isExtensionAuthorised ( extension ) ) {
211
+ extensions . push ( {
212
+ id : extension . id ,
213
+ displayName : extension . packageJSON . displayName ,
214
+ since : new Date ( ) . getTime ( ) ,
215
+ lastAccess : new Date ( ) . getTime ( )
216
+ } ) ;
205
217
await this . set ( AUTHORISED_EXTENSIONS_KEY , extensions ) ;
206
218
}
207
219
}
208
220
209
- isExtensionAuthorised ( extension : string ) {
210
- const extensions = this . get < string [ ] > ( AUTHORISED_EXTENSIONS_KEY ) || [ ] ;
211
- return extensions . includes ( extension ) ;
221
+ isExtensionAuthorised ( extension : vscode . Extension < any > ) {
222
+ const authorisedExtension = this . getAuthorisedExtensions ( ) . find ( authorisedExtension => authorisedExtension . id === extension . id ) ;
223
+ if ( authorisedExtension ) {
224
+ authorisedExtension . lastAccess = new Date ( ) . getTime ( ) ;
225
+ }
226
+ return authorisedExtension !== undefined ;
227
+ }
228
+
229
+ getAuthorisedExtensions ( ) : AuthorisedExtension [ ] {
230
+ return this . get < AuthorisedExtension [ ] > ( AUTHORISED_EXTENSIONS_KEY ) || [ ] ;
212
231
}
213
232
214
- getAuthorizedExtensions ( ) : string [ ] {
215
- return this . get < string [ ] > ( AUTHORISED_EXTENSIONS_KEY ) || [ ] ;
233
+ removeAllAuthorisedExtension ( ) {
234
+ this . removeAuthorisedExtension ( this . getAuthorisedExtensions ( ) ) ;
216
235
}
217
236
218
- removeAuthorizedExtension ( extensions : string [ ] ) {
219
- const authorizedExtensions = this . get < string [ ] > ( AUTHORISED_EXTENSIONS_KEY ) || [ ] ;
220
- const newExtensions = authorizedExtensions . filter ( ext => ! extensions . includes ( ext ) ) ;
237
+ removeAuthorisedExtension ( extensions : AuthorisedExtension [ ] ) {
238
+ const newExtensions = this . getAuthorisedExtensions ( ) . filter ( ext => ! extensions . includes ( ext ) ) ;
221
239
return this . set ( AUTHORISED_EXTENSIONS_KEY , newExtensions ) ;
222
240
}
223
241
}
0 commit comments