设置中添加插件商店地址配置选项,含有serviceUrl和itemUrl配置.

This commit is contained in:
chriswang521 2023-08-17 17:22:43 +08:00
parent 9093b28a37
commit 5a979b5480
13 changed files with 220 additions and 6 deletions

View File

@ -1544,6 +1544,14 @@
"versionSpecificity2": "\"engines.vscode\" ({0}) 中指定的版本不够具体。对于 1.0.0 之后的 vscode 版本,请至少定义主要想要的版本。例如: ^1.10.0、1.10.x、1.x.x、2.x.x 等。",
"versionSyntax": "无法解析 \"engines.vscode\" 的值 {0}。请改为如 ^1.22.0, ^1.22.x 等。"
},
"vs/platform/extensionsGallery/common/extensionsGallery.config.contribution":{
"extensionsGalleryConfigurationTitle":"插件商店地址",
"extensionsGalleryServiceUrl":"配置插件商店的服务器地址serviceUrl。例如:https://open-vsx.org/vscode/gallery",
"extensionsGalleryItemUrl":"配置插件商店的单个插件地址itemUrl。例如:https://open-vsx.org/vscode/item"
},
"vs/platform/extensionsGallery/common/extensionsGalleryConfig":{
"galleryConfigChanged":"插件商店配置地址已更改。"
},
"vs/platform/externalTerminal/node/externalTerminalService": {
"console.title": "VS Code 控制台",
"ext.term.app.not.found": "找不到终端应用程序 \"{0}\"",
@ -7364,6 +7372,7 @@
"diffEditor": "差异编辑器",
"editorManagement": "编辑管理",
"extensions": "插件",
"extensionsGallery":"插件商店地址",
"features": "功能",
"fileExplorer": "资源管理器",
"files": "文件",

View File

@ -102,6 +102,10 @@ import { IExtensionsScannerService } from 'vs/platform/extensionManagement/commo
import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService';
import { PolicyChannelClient } from 'vs/platform/policy/common/policyIpc';
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
import { ExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfig';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
import { INotificationService } from 'vs/platform/notification/common/notification';
class SharedProcessMain extends Disposable {
@ -304,6 +308,9 @@ class SharedProcessMain extends Disposable {
services.set(IExtensionsScannerService, new SyncDescriptor(ExtensionsScannerService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(INotificationService, new SyncDescriptor(NotificationService));
services.set(IExtensionsGalleryConfigService, new SyncDescriptor(ExtensionsGalleryConfigService));
// Extension Gallery
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));

View File

@ -29,6 +29,8 @@ import { ExtensionManagementCLIService } from 'vs/platform/extensionManagement/c
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';
import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService';
import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService';
import { ExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfig';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
import { IFileService } from 'vs/platform/files/common/files';
import { FileService } from 'vs/platform/files/common/fileService';
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
@ -155,6 +157,7 @@ class CliMain extends Disposable {
services.set(IDownloadService, new SyncDescriptor(DownloadService));
// Extensions
services.set(IExtensionsGalleryConfigService, new SyncDescriptor(ExtensionsGalleryConfigService));
services.set(IExtensionsScannerService, new SyncDescriptor(ExtensionsScannerService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryServiceWithNoStorageService));

View File

@ -27,6 +27,7 @@ import { asJson, asTextOrError, IRequestService, isSuccess } from 'vs/platform/r
import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/marketplace';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
const CURRENT_TARGET_PLATFORM = isWeb ? TargetPlatform.WEB : getTargetPlatform(platform, arch);
@ -581,13 +582,30 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
@IFileService private readonly fileService: IFileService,
@IProductService private readonly productService: IProductService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IExtensionsGalleryConfigService readonly extensionsGalleryConfigService: IExtensionsGalleryConfigService,
) {
const config = productService.extensionsGallery;
if (extensionsGalleryConfigService && extensionsGalleryConfigService.serviceUrl) {
this.extensionsGalleryUrl = extensionsGalleryConfigService.serviceUrl;
} else {
this.extensionsGalleryUrl = config && config.serviceUrl;
}
this.extensionsGalleryConfigService!.onConfigChange!(this.onUpdateConfigChange, this);
this.extensionsControlUrl = config && config.controlUrl;
this.commonHeadersPromise = resolveMarketplaceHeaders(productService.version, productService, this.environmentService, this.configurationService, this.fileService, storageService);
}
private onUpdateConfigChange(serverURL: string) {
this.logService.info('wpl onUpdateConfigChange serverURL:' + serverURL);
if (serverURL) {
this.extensionsGalleryUrl = serverURL;
} else {
const config = this.productService.extensionsGallery;
this.extensionsGalleryUrl = config && config.serviceUrl;
}
}
private api(path = ''): string {
return `${this.extensionsGalleryUrl}${path}`;
}
@ -1223,8 +1241,9 @@ export class ExtensionGalleryService extends AbstractExtensionGalleryService {
@IFileService fileService: IFileService,
@IProductService productService: IProductService,
@IConfigurationService configurationService: IConfigurationService,
@IExtensionsGalleryConfigService extensionsGalleryConfigService: IExtensionsGalleryConfigService,
) {
super(storageService, requestService, logService, environmentService, telemetryService, fileService, productService, configurationService);
super(storageService, requestService, logService, environmentService, telemetryService, fileService, productService, configurationService, extensionsGalleryConfigService);
}
}
@ -1238,7 +1257,8 @@ export class ExtensionGalleryServiceWithNoStorageService extends AbstractExtensi
@IFileService fileService: IFileService,
@IProductService productService: IProductService,
@IConfigurationService configurationService: IConfigurationService,
@IExtensionsGalleryConfigService extensionsGalleryConfigService: IExtensionsGalleryConfigService,
) {
super(undefined, requestService, logService, environmentService, telemetryService, fileService, productService, configurationService);
super(undefined, requestService, logService, environmentService, telemetryService, fileService, productService, configurationService, extensionsGalleryConfigService);
}
}

View File

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) kylinIDETeam. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
id: 'extensionsGallery',
order: 199,
title: localize('extensionsGalleryConfigurationTitle', "extensionsGallery"),
type: 'object',
properties: {
'extensionsGallery.serviceUrl': {
type: 'string',
pattern: '^(http|https)?://([^:]*(:[^@]*)?@)?([^:]+|\\[[:0-9a-fA-F]+\\])(:\\d+)?/?$|^$',
default: '',
scope: ConfigurationScope.APPLICATION,
description: localize('extensionsGalleryServiceUrl', "Configure Extensions Gallery ServiceUrl.Sample:https://open-vsx.org/vscode/gallery"),
restricted: true
},
'extensionsGallery.itemUrl': {
type: 'string',
pattern: '^(http|https)?://([^:]*(:[^@]*)?@)?([^:]+|\\[[:0-9a-fA-F]+\\])(:\\d+)?/?$|^$',
default: '',
scope: ConfigurationScope.APPLICATION,
description: localize('extensionsGalleryItemUrl', "Configure Extensions Gallery ItemUrl.Sample:https://open-vsx.org/vscode/item"),
restricted: true,
}
},
});
export interface IExtensionsGalleryConfiguration {
// extensionsGallery?: {
serviceUrl: string;
itemUrl: string;
// }
}

View File

@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) kylinIDETeam. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// import { Action } from 'vs/base/common/actions';
// import { isWeb } from 'vs/base/common/platform';
import { localize } from 'vs/nls';
import { Emitter, Event } from 'vs/base/common/event';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IExtensionsGalleryConfiguration } from 'vs/platform/extensionsGallery/common/extensionsGallery.config.contribution';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
import { INotificationService } from 'vs/platform/notification/common/notification';
// import { IHostService } from 'vs/workbench/services/host/browser/host';
export class ExtensionsGalleryConfigService implements IExtensionsGalleryConfigService {
declare readonly _serviceBrand: undefined;
private _serviceUrl: string = '';
private _itemUrl: string = '';
public extensionsGalleryConfiguration!: IExtensionsGalleryConfiguration;
private preExtensionsGalleryConfig: IExtensionsGalleryConfiguration;
private readonly _onConfigChange = new Emitter<string>();
readonly onConfigChange: Event<string> = this._onConfigChange.event;
constructor(
@IConfigurationService private readonly configurationService: IConfigurationService,
@INotificationService private readonly notificationService: INotificationService,
// @IHostService private readonly hostService: IHostService,
) {
this.preExtensionsGalleryConfig = this.configurationService.getValue<IExtensionsGalleryConfiguration>('extensionsGallery');
this.updateURL(this.preExtensionsGalleryConfig);
this.configurationService.onDidChangeConfiguration(() => this.configure(this.configurationService.getValue<IExtensionsGalleryConfiguration>('extensionsGallery')), this);
}
get serviceUrl(): string {
return this._serviceUrl;
}
get itemUrl(): string {
return this._itemUrl;
}
private updateURL(extensionsGalleryConfig: IExtensionsGalleryConfiguration) {
if (extensionsGalleryConfig) {
this._serviceUrl = extensionsGalleryConfig.serviceUrl;
this._itemUrl = extensionsGalleryConfig.itemUrl;
}
}
private configure(extensionsGalleryConfig: IExtensionsGalleryConfiguration) {
//不能直接使用==判断可以将内容转为json的比较必须序列一致
if (JSON.stringify(this.preExtensionsGalleryConfig) === JSON.stringify(extensionsGalleryConfig)) {
//前一次和本次修改一致,不做任何操作
} else {
this.preExtensionsGalleryConfig = extensionsGalleryConfig;
this.updateURL(extensionsGalleryConfig);
// if (extensionsGalleryConfig.serviceUrl) {
// this._serviceUrl = extensionsGalleryConfig!.serviceUrl!;
// this._itemUrl = extensionsGalleryConfig.itemUrl;
this._onConfigChange.fire(this._serviceUrl ? this._serviceUrl : '');
this.notificationService.info(localize('galleryConfigChanged', "Extensions Gallery Config Changed"));
// this.notificationService.prompt(
// Severity.Info,
// "changed testing",
// [
// {
// label: isWeb ? localize('reload', "Reload") : localize('restart', "Restart"),
// run: () => this.hostService.restart()
// }
// ]
// );
// this.notificationService.notify({
// severity: Severity.Info,
// message: "satest",
// actions: {
// primary: [
// new Action('Restart', isWeb ? localize('reload', "Reload") : localize('restart', "Restart"), undefined, true, () => this.hostService.restart())
// ]
// }
// });
// }
}
}
}

View File

@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) kylinIDETeam. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IExtensionsGalleryConfigService = createDecorator<IExtensionsGalleryConfigService>('extensionsGalleryConfigService');
export interface IExtensionsGalleryConfigService {
readonly serviceUrl: string;
readonly itemUrl: string;
readonly _serviceBrand: undefined;
readonly onConfigChange: Event<string>;
}

View File

@ -71,6 +71,8 @@ import { ExtensionHostStatusService, IExtensionHostStatusService } from 'vs/serv
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';
import { ExtensionsScannerService } from 'vs/server/node/extensionsScannerService';
import { NullPolicyService } from 'vs/platform/policy/common/policy';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
import { ExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfig';
const eventPrefix = 'monacoworkbench';
@ -150,6 +152,7 @@ export async function setupServerServices(connectionToken: ServerConnectionToken
services.set(IServerTelemetryService, ServerNullTelemetryService);
}
services.set(IExtensionsGalleryConfigService, new SyncDescriptor(ExtensionsGalleryConfigService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryServiceWithNoStorageService));
const downloadChannel = socketServer.getChannel('download', router);

View File

@ -70,6 +70,7 @@ import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels';
import { Codicon } from 'vs/base/common/codicons';
import { assertType } from 'vs/base/common/types';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
export class PromptExtensionInstallFailureAction extends Action {
@ -87,6 +88,7 @@ export class PromptExtensionInstallFailureAction extends Action {
@ILogService private readonly logService: ILogService,
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IExtensionsGalleryConfigService readonly extensionsGalleryConfigService: IExtensionsGalleryConfigService,
) {
super('extension.promptExtensionInstallFailure');
}
@ -131,11 +133,17 @@ export class PromptExtensionInstallFailureAction extends Action {
});
}
else if (this.extension.gallery && this.productService.extensionsGallery && (this.extensionManagementServerService.localExtensionManagementServer || this.extensionManagementServerService.remoteExtensionManagementServer) && !isIOS) {
else if (this.extension.gallery && (this.productService.extensionsGallery || (this.extensionsGalleryConfigService && this.extensionsGalleryConfigService.serviceUrl)) && (this.extensionManagementServerService.localExtensionManagementServer || this.extensionManagementServerService.remoteExtensionManagementServer) && !isIOS) {
let extServiceURL: string = '';
if (this.extensionsGalleryConfigService && this.extensionsGalleryConfigService.serviceUrl) {
extServiceURL = this.extensionsGalleryConfigService.serviceUrl;
} else if (this.productService.extensionsGallery) {
extServiceURL = this.productService.extensionsGallery!.serviceUrl;
}
additionalMessage = localize('check logs', "Please check the [log]({0}) for more details.", `command:${Constants.showWindowLogActionId}`);
promptChoices.push({
label: localize('download', "Try Downloading Manually..."),
run: () => this.openerService.open(URI.parse(`${this.productService.extensionsGallery!.serviceUrl}/publishers/${this.extension.publisher}/vsextensions/${this.extension.name}/${this.version}/vspackage`)).then(() => {
run: () => this.openerService.open(URI.parse(`${extServiceURL}/publishers/${this.extension.publisher}/vsextensions/${this.extension.name}/${this.version}/vspackage`)).then(() => {
this.notificationService.prompt(
Severity.Info,
localize('install vsix', 'Once downloaded, please manually install the downloaded VSIX of \'{0}\'.', this.extension.identifier.id),

View File

@ -47,6 +47,7 @@ import { IExtensionService, IExtensionsStatus } from 'vs/workbench/services/exte
import { ExtensionEditor } from 'vs/workbench/contrib/extensions/browser/extensionEditor';
import { isWeb } from 'vs/base/common/platform';
import { GDPRClassification } from 'vs/platform/telemetry/common/gdprTypings';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
interface IExtensionStateProvider<T> {
(extension: Extension): T;
@ -75,7 +76,8 @@ export class Extension implements IExtension {
@ITelemetryService private readonly telemetryService: ITelemetryService,
@ILogService private readonly logService: ILogService,
@IFileService private readonly fileService: IFileService,
@IProductService private readonly productService: IProductService
@IProductService private readonly productService: IProductService,
@IExtensionsGalleryConfigService readonly extensionsGalleryConfigService: IExtensionsGalleryConfigService,
) { }
get type(): ExtensionType {
@ -154,6 +156,14 @@ export class Extension implements IExtension {
}
get url(): string | undefined {
if (this.extensionsGalleryConfigService.serviceUrl) {
if (this.extensionsGalleryConfigService.itemUrl && this.gallery) {
return `${this.extensionsGalleryConfigService.itemUrl}?itemName=${this.publisher}.${this.name}`;
} else {
this.logService.info('itemUrl undefine');
return undefined;
}
}
if (!this.productService.extensionsGallery || !this.gallery) {
return undefined;
}

View File

@ -228,6 +228,11 @@ export const tocData: ITOCEntry<string> = {
id: 'application/settingsSync',
label: localize('settingsSync', "Settings Sync"),
settings: ['settingsSync.*']
},
{
id: 'application/extensionsGallery',
label: localize('extensionsGallery', "Extensions Gallery"),
settings: ['extensionsGallery.*']
}
]
},

View File

@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/platform/update/common/update.config.contribution';
import 'vs/platform/extensionsGallery/common/extensionsGallery.config.contribution';
import { localize } from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';

View File

@ -102,6 +102,8 @@ import 'vs/workbench/services/languageDetection/browser/languageDetectionWorkerS
import 'vs/editor/common/services/languageFeaturesService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfig';
import { IExtensionsGalleryConfigService } from 'vs/platform/extensionsGallery/common/extensionsGalleryConfigService';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService';
import { GlobalExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionEnablementService';
import { IExtensionGalleryService, IGlobalExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
@ -133,6 +135,7 @@ registerSingleton(IUserDataSyncLogService, UserDataSyncLogService);
registerSingleton(IIgnoredExtensionsManagementService, IgnoredExtensionsManagementService);
registerSingleton(IGlobalExtensionEnablementService, GlobalExtensionEnablementService);
registerSingleton(IExtensionStorageService, ExtensionStorageService);
registerSingleton(IExtensionsGalleryConfigService, ExtensionsGalleryConfigService);
registerSingleton(IExtensionGalleryService, ExtensionGalleryService, true);
registerSingleton(IContextViewService, ContextViewService, true);
registerSingleton(IListService, ListService, true);