Skip to content

Commit

Permalink
fix: updates state during extension startup (#240)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <[email protected]>
  • Loading branch information
dgolovin authored Jul 3, 2024
1 parent e568606 commit 6a58793
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ let connectionFactoryDisposable: extensionApi.Disposable;

let crcVersion: CrcVersion | undefined;

function isNeedSetup() {
return crcStatus.status.CrcStatus === 'Need Setup';
}

async function _activate(extensionContext: extensionApi.ExtensionContext): Promise<void> {
const crcInstaller = new CrcInstall(extensionContext.storagePath);

Expand All @@ -57,15 +61,14 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi

const detectionChecks: extensionApi.ProviderDetectionCheck[] = [];
let hasDaemonRunning = false;
let isNeedSetup = false;

if (crcVersion) {
isNeedSetup = await needSetup();
await crcStatus.initialize();

if (!isNeedSetup) {
if (!isNeedSetup()) {
await connectToCrc();
} else {
crcStatus.initialize();
}

hasDaemonRunning = await isDaemonRunning();
}

Expand Down Expand Up @@ -126,12 +129,12 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi
}

// if no need to setup we could add commands
if (!isNeedSetup) {
if (!isNeedSetup()) {
addCommands(telemetryLogger);
}

// no need to setup and crc has cluster
if (!isNeedSetup && crcStatus.status.CrcStatus !== 'No Cluster') {
if (!isNeedSetup() && crcStatus.status.CrcStatus !== 'No Cluster') {
presetChanged(provider, extensionContext, telemetryLogger);
} else {
// else get preset from cli as setup is not finished and daemon may not running
Expand Down Expand Up @@ -242,11 +245,11 @@ async function createCrcVm(
logger: extensionApi.Logger,
): Promise<void> {
// we already have an instance
if (crcStatus.status.CrcStatus !== 'No Cluster' && crcStatus.status.CrcStatus !== 'Need Setup') {
if (crcStatus.status.CrcStatus !== 'No Cluster' && !isNeedSetup()) {
return;
}

if (crcStatus.status.CrcStatus === 'Need Setup') {
if (!isNeedSetup()) {
const initResult = await initializeCrc(provider, extensionContext, telemetryLogger, logger);
if (!initResult) {
throw new Error(`${productName} not initialized.`);
Expand Down

0 comments on commit 6a58793

Please sign in to comment.