From f5ee416cc7b2350520a940c8e0a9d2fd95e3b5a9 Mon Sep 17 00:00:00 2001 From: chriswang521 Date: Tue, 30 May 2023 16:46:43 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=90=8E,=E5=B8=AE=E5=8A=A9=E8=8F=9C=E5=8D=95=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=E6=8F=92=E4=BB=B6=E4=BE=9D=E8=B5=96=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=99=A8=E5=92=8C=E7=A6=BB=E7=BA=BF=E6=8F=92=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E8=8F=9C=E5=8D=95=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../browser/preferences.contribution.ts | 24 +------------------ .../cachedExtensionScanner.ts | 18 ++++++++++++++ 2 files changed, 19 insertions(+), 23 deletions(-) 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);