diff --git a/src/extension.ts b/src/extension.ts index b3f6934a..e4d9158c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { const crcInstaller = new CrcInstall(extensionContext.storagePath); @@ -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(); } @@ -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 @@ -242,11 +245,11 @@ async function createCrcVm( logger: extensionApi.Logger, ): Promise { // 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.`);