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

feat(login): add cleaner command + some bug fixes

parent 0ffe58ab
No related branches found
No related tags found
3 merge requests!16feat: publish extension on marketplace with ci,!15feat(Sprint1): add authentication + directory picking + redirection link,!14sprint 1
...@@ -37,6 +37,11 @@ ...@@ -37,6 +37,11 @@
"command": "deadlock.chooseMissionWorkdir", "command": "deadlock.chooseMissionWorkdir",
"title": "Choose mission workdir", "title": "Choose mission workdir",
"category": "Deadlock Coding" "category": "Deadlock Coding"
},
{
"command": "deadlock.clear",
"title": "Clear cache",
"category": "Deadlock Coding"
} }
], ],
"viewsContainers": { "viewsContainers": {
......
...@@ -13,6 +13,7 @@ export class CommandHandler { ...@@ -13,6 +13,7 @@ export class CommandHandler {
initCommandHandler() { initCommandHandler() {
commands.registerCommand(CHOOSE_MISSION_WORKDIR_COMMAND.cmd, this.chooseMissionWorkdir.bind(this)); commands.registerCommand(CHOOSE_MISSION_WORKDIR_COMMAND.cmd, this.chooseMissionWorkdir.bind(this));
commands.registerCommand(AUTHENTICATE_COMMAND.cmd, this.parent.authenticate.bind(this.parent)); commands.registerCommand(AUTHENTICATE_COMMAND.cmd, this.parent.authenticate.bind(this.parent));
commands.registerCommand(CLEAR_COMMAND.cmd, this.parent.clear.bind(this.parent));
} }
async chooseMissionWorkdir() { async chooseMissionWorkdir() {
...@@ -38,3 +39,4 @@ export class CommandHandler { ...@@ -38,3 +39,4 @@ export class CommandHandler {
export const CHOOSE_MISSION_WORKDIR_COMMAND = new Command('Choose mission workdir', 'deadlock.chooseMissionWorkdir'); export const CHOOSE_MISSION_WORKDIR_COMMAND = new Command('Choose mission workdir', 'deadlock.chooseMissionWorkdir');
export const AUTHENTICATE_COMMAND = new Command('Authenticate', 'deadlock.authenticate'); export const AUTHENTICATE_COMMAND = new Command('Authenticate', 'deadlock.authenticate');
export const CLEAR_COMMAND = new Command('Clear', 'deadlock.clear');
...@@ -44,12 +44,18 @@ export default class Controller { ...@@ -44,12 +44,18 @@ export default class Controller {
this.gettingStartedView.isAlreadyConnected = !!(await exensionStorage.getAccessToken()); this.gettingStartedView.isAlreadyConnected = !!(await exensionStorage.getAccessToken());
} }
async clear() {
const exensionStorage = ExtensionStore.getInstance();
await exensionStorage.clear();
this.gettingStartedView.isAlreadyConnected = false;
}
async authenticate() { async authenticate() {
const tokens = await this.connection.getToken({ openLink: Controller.openBrowserWithUrl }); const tokens = await this.connection.getToken({ openLink: Controller.openBrowserWithUrl });
const exensionStorage = ExtensionStore.getInstance(); const exensionStorage = ExtensionStore.getInstance();
await exensionStorage.setAccessToken(tokens.accessToken); await exensionStorage.setAccessToken(tokens.accessToken);
await exensionStorage.setRefreshToken(tokens.refreshToken); await exensionStorage.setRefreshToken(tokens.refreshToken);
this.gettingStartedView.isAlreadyConnected = !!(await exensionStorage.getAccessToken()); this.gettingStartedView.isAlreadyConnected = true;
} }
public static openBrowserWithUrl(url: string) { public static openBrowserWithUrl(url: string) {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
...@@ -71,6 +77,8 @@ export default class Controller { ...@@ -71,6 +77,8 @@ export default class Controller {
const { accessToken, refreshToken } = await this.connection.getToken({ const { accessToken, refreshToken } = await this.connection.getToken({
openLink: Controller.openBrowserWithUrl, openLink: Controller.openBrowserWithUrl,
}); });
extensionStore.setAccessToken(accessToken);
extensionStore.setRefreshToken(refreshToken);
vscode.window.showInformationMessage('Nouvelle connexion validée'); vscode.window.showInformationMessage('Nouvelle connexion validée');
} else { } else {
vscode.window.showInformationMessage('Déjà connecté: session récupérée'); vscode.window.showInformationMessage('Déjà connecté: session récupérée');
......
...@@ -14,6 +14,16 @@ export default class ExtensionStore { ...@@ -14,6 +14,16 @@ export default class ExtensionStore {
this.secretStorage = context.secrets; this.secretStorage = context.secrets;
} }
public async clear() {
if (this.globalStorage.keys()) {
for (let key of this.globalStorage.keys()) {
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);
}
public static getInstance(): ExtensionStore { public static getInstance(): ExtensionStore {
if (!ExtensionStore.instance) { if (!ExtensionStore.instance) {
throw new Error('ExtensionStore should be initiate with a storage first time'); throw new Error('ExtensionStore should be initiate with a storage first time');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment