From 9faf871b071ad3837e9d4548679712c96d8caa76 Mon Sep 17 00:00:00 2001 From: Yevhen Vydolob Date: Wed, 17 May 2023 14:32:03 +0300 Subject: [PATCH] Register connection factory only on installed state Signed-off-by: Yevhen Vydolob --- src/extension.ts | 65 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9cc52eab..f3441314 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -108,33 +108,9 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): }); extensionContext.subscriptions.push(provider); - const providerLifecycle: extensionApi.ProviderLifecycle = { - status: () => { - return crcStatus.getProviderStatus(); - }, - start: async context => { - provider.updateStatus('starting'); - await startCrc(provider, context.log, telemetryLogger); - }, - stop: () => { - provider.updateStatus('stopping'); - return stopCrc(telemetryLogger); - }, - }; - - extensionContext.subscriptions.push( - provider.setKubernetesProviderConnectionFactory({ - initialize: async () => { - await createCrcVm(provider, extensionContext, telemetryLogger, defaultLogger); - }, - create: async (_, logger) => { - await createCrcVm(provider, extensionContext, telemetryLogger, logger); - await presetChanged(provider, extensionContext, telemetryLogger); - }, - }), - ); - - extensionContext.subscriptions.push(provider.registerLifecycle(providerLifecycle)); + if (status != 'not-installed') { + registerProviderLifecycleAndFactory(provider, extensionContext, telemetryLogger); + } commandManager.setExtContext(extensionContext); commandManager.setTelemetryLogger(telemetryLogger); @@ -164,6 +140,7 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): if (!setupResult) { return; } + registerProviderLifecycleAndFactory(provider, extensionContext, telemetryLogger); await connectToCrc(); initCommandsAndPreferences(provider, extensionContext, telemetryLogger); presetChanged(provider, extensionContext, telemetryLogger); @@ -186,6 +163,40 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): ); } +function registerProviderLifecycleAndFactory( + provider: extensionApi.Provider, + extensionContext: extensionApi.ExtensionContext, + telemetryLogger: extensionApi.TelemetryLogger, +): void { + const providerLifecycle: extensionApi.ProviderLifecycle = { + status: () => { + return crcStatus.getProviderStatus(); + }, + start: async context => { + provider.updateStatus('starting'); + await startCrc(provider, context.log, telemetryLogger); + }, + stop: () => { + provider.updateStatus('stopping'); + return stopCrc(telemetryLogger); + }, + }; + + extensionContext.subscriptions.push( + provider.setKubernetesProviderConnectionFactory({ + initialize: async () => { + await createCrcVm(provider, extensionContext, telemetryLogger, defaultLogger); + }, + create: async (_, logger) => { + await createCrcVm(provider, extensionContext, telemetryLogger, logger); + await presetChanged(provider, extensionContext, telemetryLogger); + }, + }), + ); + + extensionContext.subscriptions.push(provider.registerLifecycle(providerLifecycle)); +} + async function createCrcVm( provider: extensionApi.Provider, extensionContext: extensionApi.ExtensionContext,