diff --git a/src/plugins/setup.ts b/src/plugins/setup.ts index 3455661..6f92d12 100644 --- a/src/plugins/setup.ts +++ b/src/plugins/setup.ts @@ -296,8 +296,6 @@ export default createPlugin( }), ); - void commands.executeCommand("localstack.refreshStatusBar"); - progress.report({ message: 'Finished configuring the AWS profile named "localstack".', @@ -326,6 +324,8 @@ export default createPlugin( return; } + void commands.executeCommand("localstack.refreshStatusBar"); + ///////////////////////////////////////////////////////////////////// if (localStackStatusTracker.status() === "running") { window @@ -368,17 +368,22 @@ export default createPlugin( ), ); - if (setupStatusTracker.status() === "setup_required") { - window - .showInformationMessage("Setup LocalStack to get started.", { - title: "Setup", - command: "localstack.setup", - }) - .then((selected) => { - if (selected) { - commands.executeCommand(selected.command, "extension_startup"); - } - }); - } + setupStatusTracker.onChange((status) => { + if (status === "setup_required") { + void window + .showInformationMessage("Setup LocalStack to get started.", { + title: "Setup", + command: "localstack.setup", + }) + .then((selected) => { + if (selected) { + void commands.executeCommand( + selected.command, + "extension_startup", + ); + } + }); + } + }); }, ); diff --git a/src/utils/setup-status.ts b/src/utils/setup-status.ts index 08b31d6..c3b70e0 100644 --- a/src/utils/setup-status.ts +++ b/src/utils/setup-status.ts @@ -47,10 +47,30 @@ export async function createSetupStatusTracker( ); const checkStatusNow = async () => { + const allStatusesInitialized = Object.values({ + awsProfileTracker: awsProfileTracker.status(), + authTracker: localStackAuthenticationTracker.status(), + licenseTracker: licenseTracker.status(), + }).every((check) => check !== undefined); + + if (!allStatusesInitialized) { + outputChannel.trace( + `[setup-status] File watchers not initialized yet, skipping status check : ${JSON.stringify( + { + awsProfileTracker: awsProfileTracker.status() ?? "undefined", + authTracker: + localStackAuthenticationTracker.status() ?? "undefined", + licenseTracker: licenseTracker.status() ?? "undefined", + }, + )}`, + ); + return; + } + statuses = await checkSetupStatus(outputChannel); const setupRequired = [ - Object.values(statuses), + ...Object.values(statuses), awsProfileTracker.status() === "ok", localStackAuthenticationTracker.status() === "ok", licenseTracker.status() === "ok", @@ -60,7 +80,12 @@ export async function createSetupStatusTracker( if (status !== newStatus) { status = newStatus; outputChannel.trace( - `[setup-status] Status changed to ${JSON.stringify(statuses)}`, + `[setup-status] Status changed to ${JSON.stringify({ + ...statuses, + awsProfileTracker: awsProfileTracker.status() ?? "undefined", + authTracker: localStackAuthenticationTracker.status() ?? "undefined", + licenseTracker: licenseTracker.status() ?? "undefined", + })}`, ); await emitter.emit(status); } @@ -178,6 +203,9 @@ function createFileStatusTracker( outputChannel.error(error instanceof Error ? error : String(error)); }); + // Update the status immediately on file tracker initialization + void updateStatus(); + return { status() { return status; @@ -247,7 +275,7 @@ function createLicenseStatusTracker( return createFileStatusTracker( outputChannel, "[setup-status.license]", - [LICENSE_FILENAME], + [LOCALSTACK_AUTH_FILENAME, LICENSE_FILENAME], //TODO rewrite to depend on change in localStackAuthenticationTracker async () => (await checkIsLicenseValid(outputChannel)) ? "ok" : "setup_required", );