@@ -7,11 +7,11 @@ import * as nls from 'vs/nls';
77import { Registry } from 'vs/platform/registry/common/platform' ;
88import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService' ;
99import { Disposable } from 'vs/base/common/lifecycle' ;
10- import { isMacintosh } from 'vs/base/common/platform' ;
10+ import { isMacintosh , isWindows } from 'vs/base/common/platform' ;
1111import { KeyMod , KeyChord , KeyCode } from 'vs/base/common/keyCodes' ;
1212import { KeybindingsRegistry , KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
1313import { IWorkbenchContribution , IWorkbenchContributionsRegistry , Extensions as WorkbenchContributionsExtensions } from 'vs/workbench/common/contributions' ;
14- import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
14+ import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
1515import { ILabelService } from 'vs/platform/label/common/label' ;
1616import { ICommandService } from 'vs/platform/commands/common/commands' ;
1717import { Schemas } from 'vs/base/common/network' ;
@@ -27,6 +27,9 @@ import { OpenLocalFileFolderCommand, OpenLocalFileCommand, OpenLocalFolderComman
2727import { IWorkspaceContextService , WorkbenchState } from 'vs/platform/workspace/common/workspace' ;
2828import { TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry' ;
2929import { getTelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils' ;
30+ import { IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
31+ import { INativeHostService } from 'vs/platform/native/electron-sandbox/native' ;
32+ import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
3033
3134class RemoteAgentDiagnosticListener implements IWorkbenchContribution {
3235 constructor (
@@ -131,11 +134,49 @@ class RemoteEmptyWorkbenchPresentation extends Disposable implements IWorkbenchC
131134 }
132135}
133136
137+ /**
138+ * Sets the 'wslFeatureInstalled' context key if the WSL feature is or was installed on this machine.
139+ */
140+ class WSLContextKeyInitializer extends Disposable implements IWorkbenchContribution {
141+
142+ constructor (
143+ @IContextKeyService contextKeyService : IContextKeyService ,
144+ @INativeHostService nativeHostService : INativeHostService ,
145+ @IStorageService storageService : IStorageService ,
146+ @ILifecycleService lifecycleService : ILifecycleService
147+ ) {
148+ super ( ) ;
149+
150+ const contextKeyId = 'wslFeatureInstalled' ;
151+ const storageKey = 'remote.wslFeatureInstalled' ;
152+
153+ const defaultValue = storageService . getBoolean ( storageKey , StorageScope . APPLICATION , undefined ) ;
154+
155+ const hasWSLFeatureContext = new RawContextKey < boolean > ( contextKeyId , ! ! defaultValue , nls . localize ( 'wslFeatureInstalled' , "Whether the platform has the WSL feature installed" ) ) ;
156+ const contextKey = hasWSLFeatureContext . bindTo ( contextKeyService ) ;
157+
158+ if ( defaultValue === undefined ) {
159+ lifecycleService . when ( LifecyclePhase . Eventually ) . then ( async ( ) => {
160+ nativeHostService . hasWSLFeatureInstalled ( ) . then ( res => {
161+ if ( res ) {
162+ contextKey . set ( true ) ;
163+ // once detected, set to true
164+ storageService . store ( storageKey , true , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
165+ }
166+ } ) ;
167+ } ) ;
168+ }
169+ }
170+ }
171+
134172const workbenchContributionsRegistry = Registry . as < IWorkbenchContributionsRegistry > ( WorkbenchContributionsExtensions . Workbench ) ;
135173workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteAgentDiagnosticListener , 'RemoteAgentDiagnosticListener' , LifecyclePhase . Eventually ) ;
136174workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteExtensionHostEnvironmentUpdater , 'RemoteExtensionHostEnvironmentUpdater' , LifecyclePhase . Eventually ) ;
137175workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteTelemetryEnablementUpdater , 'RemoteTelemetryEnablementUpdater' , LifecyclePhase . Ready ) ;
138176workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteEmptyWorkbenchPresentation , 'RemoteEmptyWorkbenchPresentation' , LifecyclePhase . Ready ) ;
177+ if ( isWindows ) {
178+ workbenchContributionsRegistry . registerWorkbenchContribution ( WSLContextKeyInitializer , 'WSLContextKeyInitializer' , LifecyclePhase . Ready ) ;
179+ }
139180
140181Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration )
141182 . registerConfiguration ( {
0 commit comments