Skip to content

Commit

Permalink
fix: allow for web-only extensions with an override
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves committed Nov 17, 2023
1 parent 8805cd8 commit b9a4f10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demo/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ await Promise.all([
// Override services
await initializeMonacoService({
...getExtensionServiceOverride(toWorkerConfig(ExtensionHostWorker)),
...getExtensionGalleryServiceOverride(),
...getExtensionGalleryServiceOverride({ webOnly: false }),
...getModelServiceOverride(),
...getNotificationServiceOverride(),
...getDialogsServiceOverride(),
Expand Down
30 changes: 25 additions & 5 deletions src/service-override/extensionGallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { RemoteExtensionsScannerService } from 'vs/workbench/services/remote/com
import { ExtensionRecommendationNotificationService } from 'vs/workbench/contrib/extensions/browser/extensionRecommendationNotificationService'
import { ExtensionTipsService } from 'vs/platform/extensionManagement/common/extensionTipsService'
import { ExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagementService'
import { WebExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/webExtensionManagementService'
import 'vs/workbench/contrib/extensions/browser/extensions.contribution'
import 'vs/workbench/contrib/extensions/browser/extensions.web.contribution'
import 'vs/workbench/contrib/logs/common/logs.contribution'
Expand All @@ -33,11 +32,34 @@ import { ExtensionEnablementService } from 'vs/workbench/services/extensionManag
import 'vs/workbench/services/extensionManagement/browser/extensionBisect'
import { changeUrlDomain } from './tools/url'
import { registerAssets } from '../assets'
import { IInstantiationService, ILabelService, IRemoteAgentService } from '../services'

registerAssets({
'vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html': () => changeUrlDomain(new URL('../assets/webWorkerExtensionHostIframe.html', import.meta.url).href, undefined)
})

class ExtensionManagementServerServiceOverride extends ExtensionManagementServerService {
constructor (
private isWebOnly: boolean,
@IRemoteAgentService readonly remoteAgentService: IRemoteAgentService,
@ILabelService readonly labelService: ILabelService,
@IInstantiationService readonly instantiationService: IInstantiationService
) {
super(remoteAgentService, labelService, instantiationService)

if (this.isWebOnly) {
/**
* If `isWebOnly` is set to true, we explicitly set the remote extension management server to `null`, even if
* we're connected to a remote server.
*/
// Cannot override read-only property, but this is the only way we can override it to be null,
// overriding the field doesn't work and setting a getter is not allowed.
// @ts-ignore
this.remoteExtensionManagementServer = null
}
}
}

export interface ExtensionGalleryOptions {
/**
* Whether we should only allow for web extensions to be installed, this is generally
Expand All @@ -52,16 +74,14 @@ export default function getServiceOverride (options: ExtensionGalleryOptions = {
[IExtensionGalleryService.toString()]: new SyncDescriptor(ExtensionGalleryService, [], true),
[IGlobalExtensionEnablementService.toString()]: new SyncDescriptor(GlobalExtensionEnablementService, [], true),
[IExtensionsWorkbenchService.toString()]: new SyncDescriptor(ExtensionsWorkbenchService, [], true),
[IExtensionManagementServerService.toString()]: new SyncDescriptor(ExtensionManagementServerService, [], true),
[IExtensionManagementServerService.toString()]: new SyncDescriptor(ExtensionManagementServerServiceOverride, [options.webOnly], true),
[IExtensionRecommendationsService.toString()]: new SyncDescriptor(ExtensionRecommendationsService, [], true),
[IExtensionRecommendationNotificationService.toString()]: new SyncDescriptor(ExtensionRecommendationNotificationService, [], true),
[IWebExtensionsScannerService.toString()]: new SyncDescriptor(WebExtensionsScannerService, [], true),
[IExtensionIgnoredRecommendationsService.toString()]: new SyncDescriptor(ExtensionIgnoredRecommendationsService, [], true),
[IIgnoredExtensionsManagementService.toString()]: new SyncDescriptor(IgnoredExtensionsManagementService, [], true),
[IExtensionManifestPropertiesService.toString()]: new SyncDescriptor(ExtensionManifestPropertiesService, [], true),
[IExtensionManagementService.toString()]: options.webOnly
? new SyncDescriptor(WebExtensionManagementService, [], true)
: new SyncDescriptor(ExtensionManagementService, [], true),
[IExtensionManagementService.toString()]: new SyncDescriptor(ExtensionManagementService, [], true),
[IBuiltinExtensionsScannerService.toString()]: new SyncDescriptor(BuiltinExtensionsScannerService, [], true),
[IWorkspaceExtensionsConfigService.toString()]: new SyncDescriptor(WorkspaceExtensionsConfigService, [], true),
[IRemoteExtensionsScannerService.toString()]: new SyncDescriptor(RemoteExtensionsScannerService, [], true),
Expand Down

0 comments on commit b9a4f10

Please sign in to comment.