Skip to content

Commit

Permalink
Refactor worksspace trust setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Apr 6, 2021
1 parent 5818668 commit 5d94a7c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/vs/workbench/contrib/preferences/browser/settingsLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ export const tocData: ITOCEntry<string> = {
settings: ['settingsSync.*']
}
]
},
{
id: 'security',
label: localize('security', "Security"),
children: [
{
id: 'security/workspace',
label: localize('workspace', "Workspace"),
settings: ['security.workspace.*']
}
]
}
]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IConfiguration extends IWindowsConfiguration {
update: { mode: string; };
debug: { console: { wordWrap: boolean } };
editor: { accessibilitySupport: 'on' | 'off' | 'auto' };
security: { workspace: { trust: { enabled: boolean } } }
}

export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution {
Expand All @@ -35,6 +36,7 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
private clickThroughInactive: boolean | undefined;
private updateMode: string | undefined;
private accessibilitySupport: 'on' | 'off' | 'auto' | undefined;
private workspaceTrustEnabled: boolean | undefined;

constructor(
@IHostService private readonly hostService: IHostService,
Expand Down Expand Up @@ -90,6 +92,12 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
changed = true;
}
}

// Workspace trust
if (typeof config.security?.workspace.trust.enabled === 'boolean' && config.security?.workspace.trust.enabled !== this.workspaceTrustEnabled) {
this.workspaceTrustEnabled = config.security.workspace.trust.enabled;
changed = true;
}
}

// Notify only when changed and we are the focused window (avoids notification spam across windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Severity } from 'vs/platform/notification/common/notification';
Expand All @@ -22,7 +23,6 @@ import { ThemeColor } from 'vs/workbench/api/common/extHostTypes';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/common/statusbar';
import { IEditorRegistry, Extensions as EditorExtensions, EditorDescriptor } from 'vs/workbench/browser/editor';
Expand Down Expand Up @@ -50,7 +50,6 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben
@IDialogService private readonly dialogService: IDialogService,
@IActivityService private readonly activityService: IActivityService,
@ICommandService private readonly commandService: ICommandService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IExtensionService private readonly extensionService: IExtensionService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
Expand Down Expand Up @@ -185,21 +184,6 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben
}
}));

this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(WORKSPACE_TRUST_ENABLED)) {
const isEnabled = this.configurationService.inspect<boolean>(WORKSPACE_TRUST_ENABLED).userValue;
if (!isEnabled || typeof isEnabled === 'boolean') {
this.dialogService.confirm({
message: localize('trustConfigurationChangeMessage', "In order for this change to take effect, the window needs to be reloaded. Do you want to reload the window now?")
}).then(result => {
if (result.confirmed) {
this.hostService.reload();
}
});
}
}
}));

// Don't auto-show the UX editor if the request is 5 seconds after startup
setTimeout(() => { this.shouldShowManagementEditor = false; }, 5000);
}
Expand Down Expand Up @@ -425,3 +409,19 @@ MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
order: 40,
when: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${WORKSPACE_TRUST_ENABLED}`, true), WorkspaceTrustContext.PendingRequest)
});

// Configuration
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
id: 'security',
order: 7,
title: localize('securityConfigurationTitle', "Security"),
type: 'object',
properties: {
[WORKSPACE_TRUST_ENABLED]: {
type: 'boolean',
default: false,
description: localize('workspace.trust.description', "Controls whether or not workspace trust is enabled within VS Code."),
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { dirname, resolve } from 'vs/base/common/path';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';

export const WORKSPACE_TRUST_ENABLED = 'workspace.trustEnabled';
export const WORKSPACE_TRUST_ENABLED = 'security.workspace.trust.enabled';
export const WORKSPACE_TRUST_STORAGE_KEY = 'content.trust.model.key';

export const WorkspaceTrustContext = {
Expand Down

0 comments on commit 5d94a7c

Please sign in to comment.