Skip to content
Snippets Groups Projects
Commit 6a7dc8ed authored by Christian ZHENG's avatar Christian ZHENG
Browse files

feat(login): add persistence

parent cb1c0c6a
No related branches found
No related tags found
2 merge requests!14feat: added mounted, .bashrc, .zshrc, added tests, added keycloak tests,!8feat(extension): login, open in devcontainer, automaticly save code, open briefing, publish extension
import { Memento, ExtensionContext } from 'vscode';
import { ExtensionContext, Memento, SecretStorage, window } from 'vscode';
import { log } from '../recorder/utils';
export type GlobalStorageType = Memento & { setKeysForSync(keys: readonly string[]): void };
......@@ -6,9 +7,11 @@ export default class ExtensionStore {
private static instance: ExtensionStore;
private globalStorage: GlobalStorageType;
private secretStorage: SecretStorage;
private constructor(globalStorage: GlobalStorageType) {
this.globalStorage = globalStorage;
private constructor(context: ExtensionContext) {
this.globalStorage = context.globalState;
this.secretStorage = context.secrets;
}
public static getInstance(): ExtensionStore {
......@@ -24,18 +27,53 @@ export default class ExtensionStore {
return ExtensionStore.instance;
}
ExtensionStore.instance = new ExtensionStore(context.globalState);
ExtensionStore.instance = new ExtensionStore(context);
}
public getMissionWorkdir(): string | undefined {
getMissionWorkdir(): string | undefined {
return this.globalStorage.get<string>(StoreKey.MissionWorkDirKey);
}
public setMissionWorkdir(path: string): Thenable<void> {
return this.globalStorage.update(StoreKey.MissionWorkDirKey, path);
setMissionWorkdir(path: string) {
this.globalStorage.update(StoreKey.MissionWorkDirKey, path);
window.showInformationMessage(`Nouveau dossier de stockage des missions: ${path}`);
}
public async getAccessToken() {
return this._readSecret(StoreKey.AccessTokenKey);
}
public async getRefreshToken() {
return this._readSecret(StoreKey.RefreshTokenKey);
}
public async setAccessToken(accessToken: string) {
if (!accessToken) {
log('Attempt to store undefined access token');
return;
}
return this._storeSecret(StoreKey.AccessTokenKey, accessToken);
}
public async setRefreshToken(refreshToken: string) {
if (!refreshToken) {
log('Attempt to store undefined refresh token');
return;
}
return this._storeSecret(StoreKey.RefreshTokenKey, refreshToken);
}
private async _storeSecret(key: StoreKey, value: string) {
this.secretStorage.store(key, value);
}
private async _readSecret(key: StoreKey) {
return this.secretStorage.get(key);
}
}
enum StoreKey {
MissionWorkDirKey = 'mission-workdir-key',
MissionWorkDirKey = 'mission-wordir-key',
AccessTokenKey = 'access-token-key',
RefreshTokenKey = 'refresh-token-key',
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment