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 280df1a commit 044bed5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 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
35 changes: 33 additions & 2 deletions src/service-override/extensionGallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,49 @@ 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)
})

export default function getServiceOverride (): IEditorOverrideServices {
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
* true if there is no server part.
*/
webOnly: boolean
}

export default function getServiceOverride (options: ExtensionGalleryOptions = { webOnly: false }): IEditorOverrideServices {
return {
[ILocaleService.toString()]: new SyncDescriptor(WebLocaleService, [], false),
[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),
Expand Down

0 comments on commit 044bed5

Please sign in to comment.