Skip to content

Commit 866146a

Browse files
authored
fix: show LocalStack setup on only when setup is required (#58)
We've had a couple of race conditions and missing status check dependencies. This resulted in LocalStack Setup notification being shown when the setup is not required - this was happening on the most of VS Code starts. This PR fixes it with the following: - Add explicit status initialization on every status tracker creation. - Show Setup Wizard pop-up once setup is required. This ensures that pop-up appears if setup is required at the start. Instead of synchronizing statuses at the start and ensuring Setup Wizard is only popping up once, we decided to have pop-up appearing every time the setup is broken. This shouldn't happen normally, but when it happens then setup wizard pop-up in addition to painting setup bar red can actually be helpful. - License status tracker now watches both license and auth token file (not very clean solution, in the next iteration we should add behavioral dependency between license tracker and auth tracker). - Refresh status bar is now happening after the last setup wizard step. Before it was in the middle.
1 parent 8891ebc commit 866146a

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

src/plugins/setup.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ export default createPlugin(
296296
}),
297297
);
298298

299-
void commands.executeCommand("localstack.refreshStatusBar");
300-
301299
progress.report({
302300
message:
303301
'Finished configuring the AWS profile named "localstack".',
@@ -326,6 +324,8 @@ export default createPlugin(
326324
return;
327325
}
328326

327+
void commands.executeCommand("localstack.refreshStatusBar");
328+
329329
/////////////////////////////////////////////////////////////////////
330330
if (localStackStatusTracker.status() === "running") {
331331
window
@@ -368,17 +368,22 @@ export default createPlugin(
368368
),
369369
);
370370

371-
if (setupStatusTracker.status() === "setup_required") {
372-
window
373-
.showInformationMessage("Setup LocalStack to get started.", {
374-
title: "Setup",
375-
command: "localstack.setup",
376-
})
377-
.then((selected) => {
378-
if (selected) {
379-
commands.executeCommand(selected.command, "extension_startup");
380-
}
381-
});
382-
}
371+
setupStatusTracker.onChange((status) => {
372+
if (status === "setup_required") {
373+
void window
374+
.showInformationMessage("Setup LocalStack to get started.", {
375+
title: "Setup",
376+
command: "localstack.setup",
377+
})
378+
.then((selected) => {
379+
if (selected) {
380+
void commands.executeCommand(
381+
selected.command,
382+
"extension_startup",
383+
);
384+
}
385+
});
386+
}
387+
});
383388
},
384389
);

src/utils/setup-status.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,30 @@ export async function createSetupStatusTracker(
4747
);
4848

4949
const checkStatusNow = async () => {
50+
const allStatusesInitialized = Object.values({
51+
awsProfileTracker: awsProfileTracker.status(),
52+
authTracker: localStackAuthenticationTracker.status(),
53+
licenseTracker: licenseTracker.status(),
54+
}).every((check) => check !== undefined);
55+
56+
if (!allStatusesInitialized) {
57+
outputChannel.trace(
58+
`[setup-status] File watchers not initialized yet, skipping status check : ${JSON.stringify(
59+
{
60+
awsProfileTracker: awsProfileTracker.status() ?? "undefined",
61+
authTracker:
62+
localStackAuthenticationTracker.status() ?? "undefined",
63+
licenseTracker: licenseTracker.status() ?? "undefined",
64+
},
65+
)}`,
66+
);
67+
return;
68+
}
69+
5070
statuses = await checkSetupStatus(outputChannel);
5171

5272
const setupRequired = [
53-
Object.values(statuses),
73+
...Object.values(statuses),
5474
awsProfileTracker.status() === "ok",
5575
localStackAuthenticationTracker.status() === "ok",
5676
licenseTracker.status() === "ok",
@@ -60,7 +80,12 @@ export async function createSetupStatusTracker(
6080
if (status !== newStatus) {
6181
status = newStatus;
6282
outputChannel.trace(
63-
`[setup-status] Status changed to ${JSON.stringify(statuses)}`,
83+
`[setup-status] Status changed to ${JSON.stringify({
84+
...statuses,
85+
awsProfileTracker: awsProfileTracker.status() ?? "undefined",
86+
authTracker: localStackAuthenticationTracker.status() ?? "undefined",
87+
licenseTracker: licenseTracker.status() ?? "undefined",
88+
})}`,
6489
);
6590
await emitter.emit(status);
6691
}
@@ -178,6 +203,9 @@ function createFileStatusTracker(
178203
outputChannel.error(error instanceof Error ? error : String(error));
179204
});
180205

206+
// Update the status immediately on file tracker initialization
207+
void updateStatus();
208+
181209
return {
182210
status() {
183211
return status;
@@ -247,7 +275,7 @@ function createLicenseStatusTracker(
247275
return createFileStatusTracker(
248276
outputChannel,
249277
"[setup-status.license]",
250-
[LICENSE_FILENAME],
278+
[LOCALSTACK_AUTH_FILENAME, LICENSE_FILENAME], //TODO rewrite to depend on change in localStackAuthenticationTracker
251279
async () =>
252280
(await checkIsLicenseValid(outputChannel)) ? "ok" : "setup_required",
253281
);

0 commit comments

Comments
 (0)