diff --git a/packages/ai-core/src/browser/ai-activation-service.ts b/packages/ai-core/src/browser/ai-activation-service.ts index a914604306995..d1ff622f1a98d 100644 --- a/packages/ai-core/src/browser/ai-activation-service.ts +++ b/packages/ai-core/src/browser/ai-activation-service.ts @@ -44,12 +44,23 @@ export class AIActivationService implements FrontendApplicationContribution { return this.isAiEnabledKey.get() ?? false; } + protected updateEnableValue(value: boolean): void { + if (value !== this.isAiEnabledKey.get()) { + this.isAiEnabledKey.set(value); + this.onDidChangeAIEnabled.fire(value); + } + } + initialize(): MaybePromise { this.isAiEnabledKey = this.contextKeyService.createKey(ENABLE_AI_CONTEXT_KEY, false); + // make sure we don't miss once preferences are ready + this.preferenceService.ready.then(() => { + const enableValue = this.preferenceService.get(PREFERENCE_NAME_ENABLE_AI) ?? false; + this.updateEnableValue(enableValue); + }); this.preferenceService.onPreferenceChanged(e => { if (e.preferenceName === PREFERENCE_NAME_ENABLE_AI) { - this.isAiEnabledKey.set(e.newValue); - this.onDidChangeAIEnabled.fire(e.newValue); + this.updateEnableValue(e.newValue); } }); }