From a6ae7172ec8ffa8b63a7553802091137df6cf07e Mon Sep 17 00:00:00 2001 From: Maxime Dufour Date: Thu, 25 Jan 2024 13:44:33 +0000 Subject: [PATCH] Block multiple refresh Signed-off-by: Maxime Dufour --- l10n/bundle.l10n.fr.json | 3 ++- src/explorer.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/l10n/bundle.l10n.fr.json b/l10n/bundle.l10n.fr.json index d1ff864..5b8a7dc 100644 --- a/l10n/bundle.l10n.fr.json +++ b/l10n/bundle.l10n.fr.json @@ -64,5 +64,6 @@ "Downloading {0} for {1}, {2} in {3}": "Téléchargement de {0} pour {1}, {2} dans {3}", "{0} is not found. Do you want to install it ?": "{0} est introuvable. Voulez-vous l'installer ?", "Adding the path to the user config": "Ajout du chemin dans la configuration utilisateur", - "Latest stable version found is {0}": "La dernière version stable trouvée est {0}" + "Latest stable version found is {0}": "La dernière version stable trouvée est {0}", + "Refreshed not finished, waiting": "Actualisation non terminée" } \ No newline at end of file diff --git a/src/explorer.ts b/src/explorer.ts index f38f0a8..d50f348 100644 --- a/src/explorer.ts +++ b/src/explorer.ts @@ -3,15 +3,19 @@ import { ExplorerNode, Profile } from './flat/node'; import { ProfileNode } from './flat/node.profile'; import { createConfigFile, getConfigFile, getDefaultConfigFilePath, jsonToProfile, readConfigFile } from './config_file/utils'; import { AccountCost, fetchAccountCost, isOscCostEnabled, isOscCostWorking } from './components/osc_cost'; -import { OutputChannel } from './logs/output_channel'; export class OscExplorer implements vscode.TreeDataProvider { private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private waitFor = 0; // Counter to not spam the API/tools when they are already executed (here osc-cost) refresh(): void { + if (this.waitFor !== 0) { + vscode.window.showInformationMessage(vscode.l10n.t("Refreshed not finished, waiting")); + return; + } this._onDidChangeTreeData.fire(); } @@ -28,6 +32,7 @@ export class OscExplorer implements vscode.TreeDataProvider { const profileObj = new ProfileNode(profile); if (performOscCost) { + this.waitFor += 1; this.retrieveAccountCost(profile).then( (res: AccountCost) => { profileObj.profile.oscCost = res; @@ -35,6 +40,8 @@ export class OscExplorer implements vscode.TreeDataProvider { }, (reason: any) => { vscode.window.showErrorMessage(vscode.l10n.t(`Retrieval the cost for ${profile.name} fails: ${reason}`)); + }).finally(() => { + this.waitFor -= 1; }); } return profileObj;