Skip to content

Commit

Permalink
Block multiple refresh
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Dufour <[email protected]>
  • Loading branch information
outscale-mdr committed Jan 25, 2024
1 parent 650f622 commit b270c9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion l10n/bundle.l10n.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
27 changes: 26 additions & 1 deletion src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExplorerNode> {

private _onDidChangeTreeData: vscode.EventEmitter<ExplorerNode | undefined | void> = new vscode.EventEmitter<ExplorerNode | undefined | void>();
readonly onDidChangeTreeData: vscode.Event<ExplorerNode | undefined | void> = 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();
}

Expand All @@ -28,13 +32,16 @@ export class OscExplorer implements vscode.TreeDataProvider<ExplorerNode> {
const profileObj = new ProfileNode(profile);

if (performOscCost) {
this.waitFor += 1;
this.retrieveAccountCost(profile).then(
(res: AccountCost) => {
profileObj.profile.oscCost = res;
this._onDidChangeTreeData.fire(profileObj);
},
(reason: any) => {
vscode.window.showErrorMessage(vscode.l10n.t(`Retrieval the cost for ${profile.name} fails: ${reason}`));
}).finally(() => {
this.waitFor -= 1;
});
}
return profileObj;
Expand All @@ -46,6 +53,24 @@ export class OscExplorer implements vscode.TreeDataProvider<ExplorerNode> {
return Promise.resolve([]);
}
const performOscCost = isOscCostEnabled() && await isOscCostWorking();
if (performOscCost) {
vscode.window.withProgress(
{
title: vscode.l10n.t("Fetching account price"),
location: vscode.ProgressLocation.Notification,
cancellable: false
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async (p, _) => {
p.report({ message: vscode.l10n.t("Installing the latest stable version of {0}", tool) });

Check failure on line 65 in src/explorer.ts

View workflow job for this annotation

GitHub Actions / ui-test

Cannot find name 'tool'.
await installOscCost(p).catch((reason: string) => {

Check failure on line 66 in src/explorer.ts

View workflow job for this annotation

GitHub Actions / ui-test

Cannot find name 'installOscCost'.
vscode.window.showErrorMessage(vscode.l10n.t("Error while installing {0}: {1}", tool, reason));

Check failure on line 67 in src/explorer.ts

View workflow job for this annotation

GitHub Actions / ui-test

Cannot find name 'tool'.
throw vscode.l10n.t("Error while installing {0}: {1}", tool, reason);

Check failure on line 68 in src/explorer.ts

View workflow job for this annotation

GitHub Actions / ui-test

Cannot find name 'tool'.
});
p.report({ message: vscode.l10n.t("Adding the path to the user config") });
await addInstalledPathToExtension();

Check failure on line 71 in src/explorer.ts

View workflow job for this annotation

GitHub Actions / ui-test

Cannot find name 'addInstalledPathToExtension'.
});
}
const explorerNodes = Object.keys(oscConfigObject).map(dep => toExplorerNode(dep, oscConfigObject[dep], performOscCost));
return Promise.resolve(explorerNodes);
}
Expand Down

0 comments on commit b270c9d

Please sign in to comment.