diff --git a/deadlock-plugins/deadlock-extension/src/core/extensionStore.ts b/deadlock-plugins/deadlock-extension/src/core/extensionStore.ts index 9759b5e1559f2e1252a1c3a5740dc9beb47e99a9..17cd1edfea96672ffeaaece45a078bcc8bea8186 100644 --- a/deadlock-plugins/deadlock-extension/src/core/extensionStore.ts +++ b/deadlock-plugins/deadlock-extension/src/core/extensionStore.ts @@ -1,7 +1,7 @@ import { ExtensionContext, Memento, SecretStorage, window } from 'vscode'; import { extensionLog as log } from '../recorder/utils/log'; -export type GlobalStorageType = Memento & { setKeysForSync(keys: readonly string[]): void }; +type GlobalStorageType = Memento & { setKeysForSync(keys: readonly string[]): void }; export default class ExtensionStore { private static instance: ExtensionStore; @@ -20,8 +20,10 @@ export default class ExtensionStore { this.globalStorage.update(key, undefined); } } - if (await this.secretStorage.get(StoreKey.AccessTokenKey)) this.secretStorage.delete(StoreKey.AccessTokenKey); - if (await this.secretStorage.get(StoreKey.RefreshTokenKey)) this.secretStorage.delete(StoreKey.RefreshTokenKey); + if (await this.secretStorage.get(SecretStoreKey.AccessTokenKey)) + this.secretStorage.delete(SecretStoreKey.AccessTokenKey); + if (await this.secretStorage.get(SecretStoreKey.RefreshTokenKey)) + this.secretStorage.delete(SecretStoreKey.RefreshTokenKey); } public static getInstance(context?: ExtensionContext): ExtensionStore { @@ -33,21 +35,29 @@ export default class ExtensionStore { return ExtensionStore.instance; } - getMissionWorkdir(): string | undefined { - return this.globalStorage.get<string>(StoreKey.MissionWorkdirKey); + public getMissionWorkdir(): string | undefined { + return this.readStringKey(GlobalStoreKey.MissionWorkdirKey); } - setMissionWorkdir(path: string) { - this.globalStorage.update(StoreKey.MissionWorkdirKey, path); + public setMissionWorkdir(path: string) { + this.storeStringKey(GlobalStoreKey.MissionWorkdirKey, path); window.showInformationMessage(`Nouveau dossier de stockage des missions: ${path}`); } + private readStringKey(key: GlobalStoreKey): string | undefined { + return this.globalStorage.get<string>(key); + } + + private storeStringKey(key: GlobalStoreKey, value: string) { + this.globalStorage.update(key, value); + } + public getAccessToken(): Thenable<string | undefined> { - return this.readSecret(StoreKey.AccessTokenKey); + return this.readSecret(SecretStoreKey.AccessTokenKey); } public getRefreshToken(): Thenable<string | undefined> { - return this.readSecret(StoreKey.RefreshTokenKey); + return this.readSecret(SecretStoreKey.RefreshTokenKey); } public setAccessToken(accessToken: string): Thenable<void> { @@ -55,7 +65,7 @@ export default class ExtensionStore { log('Attempt to store undefined access token'); return Promise.resolve(); } - return this.storeSecret(StoreKey.AccessTokenKey, accessToken); + return this.storeSecret(SecretStoreKey.AccessTokenKey, accessToken); } public setRefreshToken(refreshToken: string): Thenable<void> { @@ -63,20 +73,23 @@ export default class ExtensionStore { log('Attempt to store undefined refresh token'); return Promise.resolve(); } - return this.storeSecret(StoreKey.RefreshTokenKey, refreshToken); + return this.storeSecret(SecretStoreKey.RefreshTokenKey, refreshToken); } - private storeSecret(key: StoreKey, value: string): Thenable<void> { - return this.secretStorage.store(key, value); + private readSecret(key: SecretStoreKey): Thenable<string | undefined> { + return this.secretStorage.get(key); } - private readSecret(key: StoreKey): Thenable<string | undefined> { - return this.secretStorage.get(key); + private storeSecret(key: SecretStoreKey, value: string): Thenable<void> { + return this.secretStorage.store(key, value); } } -enum StoreKey { - MissionWorkdirKey = 'mission-workdir-key', +enum SecretStoreKey { AccessTokenKey = 'access-token-key', RefreshTokenKey = 'refresh-token-key', } + +enum GlobalStoreKey { + MissionWorkdirKey = 'mission-workdir-key', +}