Skip to content

Commit

Permalink
Register connection factory only on installed state
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed May 17, 2023
1 parent 36dc5de commit 9faf871
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 9faf871

Please sign in to comment.