diff --git a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts index ae421026..e4792735 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts @@ -14,7 +14,7 @@ import { Context as SuggestContext } from 'vs/editor/contrib/suggest/browser/sug import * as nls from 'vs/nls'; import { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions'; import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands'; -import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContext, IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; @@ -60,9 +60,6 @@ const SETTINGS_EDITOR_COMMAND_FILTER_UNTRUSTED = 'settings.filterUntrusted'; const SETTINGS_COMMAND_OPEN_SETTINGS = 'workbench.action.openSettings'; -const HasInstalledExtDependencyExtensionContext = new RawContextKey('hasExtDependency', false); //by wpl -const HasInstalledOfflineExtManagerExtensionContext = new RawContextKey('hasOfflineExtManager', false); //by wpl - Registry.as(EditorExtensions.EditorPane).registerEditorPane( EditorPaneDescriptor.create( @@ -141,16 +138,12 @@ function sanitizeOpenSettingsArgs(args: any): IOpenSettingsActionOptions { class PreferencesActionsContribution extends Disposable implements IWorkbenchContribution { - private HasInstalledExtDependencyExtensionContextKey: IContextKey; - private HasInstalledOfflineExtManagerExtensionContextKey: IContextKey; - constructor( @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, @IPreferencesService private readonly preferencesService: IPreferencesService, @IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService, @ILabelService private readonly labelService: ILabelService, @IExtensionService private readonly extensionService: IExtensionService, - @IContextKeyService contextKeyService: IContextKeyService, ) { super(); @@ -161,21 +154,6 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon this._register(workspaceContextService.onDidChangeWorkbenchState(() => this.updatePreferencesEditorMenuItem())); this._register(workspaceContextService.onDidChangeWorkspaceFolders(() => this.updatePreferencesEditorMenuItemForWorkspaceFolders())); - this.HasInstalledExtDependencyExtensionContextKey = HasInstalledExtDependencyExtensionContext.bindTo(contextKeyService); - this.HasInstalledOfflineExtManagerExtensionContextKey = HasInstalledOfflineExtManagerExtensionContext.bindTo(contextKeyService); - this.checkallextension(); - } - - //check extension - private async checkallextension() { - const runningExtensions = await this.extensionService.getExtensions(); - for (let extension of runningExtensions) { - if (extension.identifier.value === 'KylinIDETeam.extension-dependency') { - this.HasInstalledExtDependencyExtensionContextKey.set(true); - } else if (extension.identifier.value === 'KylinIDETeam.offline-extensions-manager') { - this.HasInstalledOfflineExtManagerExtensionContextKey.set(true); - } - } } private registerSettingsActions() { diff --git a/src/vs/workbench/services/extensions/electron-sandbox/cachedExtensionScanner.ts b/src/vs/workbench/services/extensions/electron-sandbox/cachedExtensionScanner.ts index 852ea770..37e5ae23 100644 --- a/src/vs/workbench/services/extensions/electron-sandbox/cachedExtensionScanner.ts +++ b/src/vs/workbench/services/extensions/electron-sandbox/cachedExtensionScanner.ts @@ -15,23 +15,34 @@ import { localize } from 'vs/nls'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { timeout } from 'vs/base/common/async'; +import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +const HasInstalledExtDependencyExtensionContext = new RawContextKey('hasExtDependency', false); +const HasInstalledOfflineExtManagerExtensionContext = new RawContextKey('hasOfflineExtManager', false); export class CachedExtensionScanner { public readonly scannedExtensions: Promise; private _scannedExtensionsResolve!: (result: IExtensionDescription[]) => void; private _scannedExtensionsReject!: (err: any) => void; + private HasInstalledExtDependencyExtensionContextKey: IContextKey; + private HasInstalledOfflineExtManagerExtensionContextKey: IContextKey; + constructor( @INotificationService private readonly _notificationService: INotificationService, @IHostService private readonly _hostService: IHostService, @IExtensionsScannerService private readonly _extensionsScannerService: IExtensionsScannerService, @ILogService private readonly _logService: ILogService, + @IContextKeyService contextKeyService: IContextKeyService, ) { this.scannedExtensions = new Promise((resolve, reject) => { this._scannedExtensionsResolve = resolve; this._scannedExtensionsReject = reject; }); + + this.HasInstalledExtDependencyExtensionContextKey = HasInstalledExtDependencyExtensionContext.bindTo(contextKeyService); + this.HasInstalledOfflineExtManagerExtensionContextKey = HasInstalledOfflineExtManagerExtensionContext.bindTo(contextKeyService); + } public async scanSingleExtension(extensionPath: string, isBuiltin: boolean): Promise { @@ -43,6 +54,13 @@ export class CachedExtensionScanner { try { const { system, user, development } = await this._scanInstalledExtensions(); const r = dedupExtensions(system, user, development, this._logService); + for (let extension of r) { + if (extension.identifier.value === 'KylinIDETeam.extension-dependency') { + this.HasInstalledExtDependencyExtensionContextKey.set(true); + } else if (extension.identifier.value === 'KylinIDETeam.offline-extensions-manager') { + this.HasInstalledOfflineExtManagerExtensionContextKey.set(true); + } + } this._scannedExtensionsResolve(r); } catch (err) { this._scannedExtensionsReject(err);