@@ -7,11 +7,11 @@ import * as nls from 'vs/nls';
7
7
import { Registry } from 'vs/platform/registry/common/platform' ;
8
8
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService' ;
9
9
import { Disposable } from 'vs/base/common/lifecycle' ;
10
- import { isMacintosh } from 'vs/base/common/platform' ;
10
+ import { isMacintosh , isWindows } from 'vs/base/common/platform' ;
11
11
import { KeyMod , KeyChord , KeyCode } from 'vs/base/common/keyCodes' ;
12
12
import { KeybindingsRegistry , KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
13
13
import { 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' ;
15
15
import { ILabelService } from 'vs/platform/label/common/label' ;
16
16
import { ICommandService } from 'vs/platform/commands/common/commands' ;
17
17
import { Schemas } from 'vs/base/common/network' ;
@@ -27,6 +27,9 @@ import { OpenLocalFileFolderCommand, OpenLocalFileCommand, OpenLocalFolderComman
27
27
import { IWorkspaceContextService , WorkbenchState } from 'vs/platform/workspace/common/workspace' ;
28
28
import { TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry' ;
29
29
import { 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' ;
30
33
31
34
class RemoteAgentDiagnosticListener implements IWorkbenchContribution {
32
35
constructor (
@@ -131,11 +134,49 @@ class RemoteEmptyWorkbenchPresentation extends Disposable implements IWorkbenchC
131
134
}
132
135
}
133
136
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
+
134
172
const workbenchContributionsRegistry = Registry . as < IWorkbenchContributionsRegistry > ( WorkbenchContributionsExtensions . Workbench ) ;
135
173
workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteAgentDiagnosticListener , 'RemoteAgentDiagnosticListener' , LifecyclePhase . Eventually ) ;
136
174
workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteExtensionHostEnvironmentUpdater , 'RemoteExtensionHostEnvironmentUpdater' , LifecyclePhase . Eventually ) ;
137
175
workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteTelemetryEnablementUpdater , 'RemoteTelemetryEnablementUpdater' , LifecyclePhase . Ready ) ;
138
176
workbenchContributionsRegistry . registerWorkbenchContribution ( RemoteEmptyWorkbenchPresentation , 'RemoteEmptyWorkbenchPresentation' , LifecyclePhase . Ready ) ;
177
+ if ( isWindows ) {
178
+ workbenchContributionsRegistry . registerWorkbenchContribution ( WSLContextKeyInitializer , 'WSLContextKeyInitializer' , LifecyclePhase . Ready ) ;
179
+ }
139
180
140
181
Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration )
141
182
. registerConfiguration ( {
0 commit comments