Workspace trust api feedback
This commit is contained in:
parent
65a9aa1776
commit
14fd07d57a
11 changed files with 46 additions and 46 deletions
|
@ -39,7 +39,7 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
}
|
||||
} else {
|
||||
setImmediate(() => {
|
||||
vscode.workspace.requireWorkspaceTrust(false)
|
||||
vscode.workspace.requireWorkspaceTrust({ modal: false })
|
||||
.then(trustState => {
|
||||
if (trustState === vscode.WorkspaceTrustState.Trusted && this.versionProvider.localVersion) {
|
||||
this.updateActiveVersion(this.versionProvider.localVersion);
|
||||
|
|
|
@ -44,18 +44,17 @@ export interface IWorkspaceTrustModel {
|
|||
getTrustStateInfo(): IWorkspaceTrustStateInfo;
|
||||
}
|
||||
|
||||
export interface IWorkspaceTrustRequest {
|
||||
export interface WorkspaceTrustRequest {
|
||||
modal: boolean;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface IWorkspaceTrustRequestModel {
|
||||
readonly trustRequest: IWorkspaceTrustRequest | undefined;
|
||||
readonly trustRequest: WorkspaceTrustRequest | undefined;
|
||||
|
||||
readonly onDidInitiateRequest: Event<void>;
|
||||
readonly onDidCompleteRequest: Event<WorkspaceTrustState | undefined>;
|
||||
|
||||
initiateRequest(request?: IWorkspaceTrustRequest): void;
|
||||
initiateRequest(request?: WorkspaceTrustRequest): void;
|
||||
completeRequest(trustState?: WorkspaceTrustState): void;
|
||||
}
|
||||
|
||||
|
@ -76,7 +75,7 @@ export interface IWorkspaceTrustService {
|
|||
onDidChangeTrustState: WorkspaceTrustChangeEvent;
|
||||
getWorkspaceTrustState(): WorkspaceTrustState;
|
||||
isWorkspaceTrustEnabled(): boolean;
|
||||
requireWorkspaceTrust(request: IWorkspaceTrustRequest): Promise<WorkspaceTrustState>;
|
||||
requireWorkspaceTrust(request?: WorkspaceTrustRequest): Promise<WorkspaceTrustState>;
|
||||
}
|
||||
|
||||
export interface IWorkspaceTrustStateInfo {
|
||||
|
|
18
src/vs/vscode.proposed.d.ts
vendored
18
src/vs/vscode.proposed.d.ts
vendored
|
@ -2774,6 +2774,17 @@ declare module 'vscode' {
|
|||
currentTrustState: WorkspaceTrustState;
|
||||
}
|
||||
|
||||
/**
|
||||
* The object describing the properties of the workspace trust request
|
||||
*/
|
||||
export interface WorkspaceTrustRequest {
|
||||
/**
|
||||
* When true, a modal dialog will be used to request workspace trust.
|
||||
* When false, a badge will be displayed on the Setting activity bar item
|
||||
*/
|
||||
modal: boolean;
|
||||
}
|
||||
|
||||
export namespace workspace {
|
||||
/**
|
||||
* The trust state of the current workspace
|
||||
|
@ -2782,11 +2793,10 @@ declare module 'vscode' {
|
|||
|
||||
/**
|
||||
* Prompt the user to chose whether to trust the current workspace
|
||||
* @param modal When true, a modal dialog is used to prompt the user for workspace
|
||||
* trust, otherwise a badge will be shown on the Settings activity bar item.
|
||||
* Default value is true.
|
||||
* @param request Optional object describing the properties of the
|
||||
* workspace trust request
|
||||
*/
|
||||
export function requireWorkspaceTrust(modal?: boolean): Thenable<WorkspaceTrustState>;
|
||||
export function requireWorkspaceTrust(request?: WorkspaceTrustRequest): Thenable<WorkspaceTrustState>;
|
||||
|
||||
/**
|
||||
* Event that fires when the trust state of the current workspace changes
|
||||
|
|
|
@ -16,7 +16,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
|||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
import { WorkspaceTrustStateChangeEvent, IWorkspaceTrustService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { WorkspaceTrustStateChangeEvent, IWorkspaceTrustService, WorkspaceTrustRequest, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { IWorkspace, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
|
@ -208,8 +208,8 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
|||
|
||||
// --- trust ---
|
||||
|
||||
$requireWorkspaceTrust(modal?: boolean): Promise<WorkspaceTrustState> {
|
||||
return this._workspaceTrustService.requireWorkspaceTrust({ modal: modal ?? true });
|
||||
$requireWorkspaceTrust(request?: WorkspaceTrustRequest): Promise<WorkspaceTrustState> {
|
||||
return this._workspaceTrustService.requireWorkspaceTrust(request);
|
||||
}
|
||||
|
||||
private getWorkspaceTrustState(): WorkspaceTrustState {
|
||||
|
|
|
@ -910,10 +910,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
checkRequiresWorkspaceTrust(extension);
|
||||
return extHostWorkspace.trustState;
|
||||
},
|
||||
requireWorkspaceTrust: (modal?: boolean) => {
|
||||
requireWorkspaceTrust: (request?: vscode.WorkspaceTrustRequest) => {
|
||||
checkProposedApiEnabled(extension);
|
||||
checkRequiresWorkspaceTrust(extension);
|
||||
return extHostWorkspace.requireWorkspaceTrust(modal);
|
||||
return extHostWorkspace.requireWorkspaceTrust(request);
|
||||
},
|
||||
onDidChangeWorkspaceTrustState: (listener, thisArgs?, disposables?) => {
|
||||
return extHostWorkspace.onDidChangeWorkspaceTrustState(listener, thisArgs, disposables);
|
||||
|
|
|
@ -58,7 +58,7 @@ import { IAccessibilityInformation } from 'vs/platform/accessibility/common/acce
|
|||
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/extensionsStorageSync';
|
||||
import { InternalTestItem, ITestState, RunTestForProviderRequest, RunTestsRequest, TestIdWithProvider, TestsDiff, ISerializedTestResults } from 'vs/workbench/contrib/testing/common/testCollection';
|
||||
import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService';
|
||||
import { WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { WorkspaceTrustRequest, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
|
||||
import { IShellLaunchConfig, ITerminalDimensions, ITerminalLaunchError } from 'vs/platform/terminal/common/terminal';
|
||||
|
||||
|
@ -834,7 +834,7 @@ export interface MainThreadWorkspaceShape extends IDisposable {
|
|||
$saveAll(includeUntitled?: boolean): Promise<boolean>;
|
||||
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, workspaceFoldersToAdd: { uri: UriComponents, name?: string; }[]): Promise<void>;
|
||||
$resolveProxy(url: string): Promise<string | undefined>;
|
||||
$requireWorkspaceTrust(modal?: boolean): Promise<WorkspaceTrustState>
|
||||
$requireWorkspaceTrust(request?: WorkspaceTrustRequest): Promise<WorkspaceTrustState>;
|
||||
}
|
||||
|
||||
export interface IFileChangeDto {
|
||||
|
|
|
@ -563,8 +563,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
|
|||
return this._workspaceTrustState;
|
||||
}
|
||||
|
||||
requireWorkspaceTrust(modal?: boolean): Promise<WorkspaceTrustState> {
|
||||
return this._proxy.$requireWorkspaceTrust(modal);
|
||||
requireWorkspaceTrust(request?: vscode.WorkspaceTrustRequest): Promise<WorkspaceTrustState> {
|
||||
return this._proxy.$requireWorkspaceTrust(request);
|
||||
}
|
||||
|
||||
$onDidChangeWorkspaceTrustState(state: WorkspaceTrustStateChangeEvent): void {
|
||||
|
|
|
@ -165,16 +165,14 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
|
|||
|
||||
const result = await Promises.settled(extensions.map(e => {
|
||||
if (this._isDisabledByTrustRequirement(e)) {
|
||||
return this.workspaceTrustService.requireWorkspaceTrust({
|
||||
modal: true,
|
||||
message: 'Enabling this extension requires you to trust the contents of this workspace.'
|
||||
}).then(trustState => {
|
||||
if (trustState === WorkspaceTrustState.Trusted) {
|
||||
return this._setEnablement(e, newState);
|
||||
} else {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
});
|
||||
return this.workspaceTrustService.requireWorkspaceTrust()
|
||||
.then(trustState => {
|
||||
if (trustState === WorkspaceTrustState.Trusted) {
|
||||
return this._setEnablement(e, newState);
|
||||
} else {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return this._setEnablement(e, newState);
|
||||
}
|
||||
|
@ -455,10 +453,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
|
|||
|
||||
private _onDidInstallExtension({ local, error }: DidInstallExtensionEvent): void {
|
||||
if (local && !error && this._isDisabledByTrustRequirement(local)) {
|
||||
this.workspaceTrustService.requireWorkspaceTrust({
|
||||
modal: true,
|
||||
message: 'Enabling this extension requires you to trust the contents of this workspace.'
|
||||
});
|
||||
this.workspaceTrustService.requireWorkspaceTrust();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -358,11 +358,7 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
|
|||
|
||||
protected async checkForWorkspaceTrust(manifest: IExtensionManifest): Promise<void> {
|
||||
if (manifest.requiresWorkspaceTrust === 'onStart') {
|
||||
const trustState = await this.workspaceTrustService.requireWorkspaceTrust(
|
||||
{
|
||||
modal: true,
|
||||
message: 'Installing this extension requires you to trust the contents of this workspace.'
|
||||
});
|
||||
const trustState = await this.workspaceTrustService.requireWorkspaceTrust();
|
||||
return trustState === WorkspaceTrustState.Trusted ? Promise.resolve() : Promise.reject(canceled());
|
||||
}
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -11,7 +11,7 @@ import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/cont
|
|||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
|
||||
import { IWorkspace, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkspaceTrustModel, IWorkspaceTrustRequest, IWorkspaceTrustRequestModel, IWorkspaceTrustService, IWorkspaceTrustStateInfo, WorkspaceTrustState, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { IWorkspaceTrustModel, WorkspaceTrustRequest, IWorkspaceTrustRequestModel, IWorkspaceTrustService, IWorkspaceTrustStateInfo, WorkspaceTrustState, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { isEqual, isEqualOrParent } from 'vs/base/common/extpath';
|
||||
import { EditorModel } from 'vs/workbench/common/editor';
|
||||
|
||||
|
@ -178,7 +178,7 @@ export class WorkspaceTrustModel extends Disposable implements IWorkspaceTrustMo
|
|||
}
|
||||
|
||||
export class WorkspaceTrustRequestModel extends Disposable implements IWorkspaceTrustRequestModel {
|
||||
trustRequest: IWorkspaceTrustRequest | undefined;
|
||||
trustRequest: WorkspaceTrustRequest | undefined;
|
||||
|
||||
private readonly _onDidInitiateRequest = this._register(new Emitter<void>());
|
||||
readonly onDidInitiateRequest: Event<void> = this._onDidInitiateRequest.event;
|
||||
|
@ -186,7 +186,7 @@ export class WorkspaceTrustRequestModel extends Disposable implements IWorkspace
|
|||
private readonly _onDidCompleteRequest = this._register(new Emitter<WorkspaceTrustState | undefined>());
|
||||
readonly onDidCompleteRequest = this._onDidCompleteRequest.event;
|
||||
|
||||
initiateRequest(request: IWorkspaceTrustRequest): void {
|
||||
initiateRequest(request: WorkspaceTrustRequest): void {
|
||||
if (this.trustRequest && (!request.modal || this.trustRequest.modal)) {
|
||||
return;
|
||||
}
|
||||
|
@ -319,16 +319,16 @@ export class WorkspaceTrustService extends Disposable implements IWorkspaceTrust
|
|||
return this.configurationService.getValue<boolean>(WORKSPACE_TRUST_ENABLED) ?? false;
|
||||
}
|
||||
|
||||
async requireWorkspaceTrust(request?: IWorkspaceTrustRequest): Promise<WorkspaceTrustState> {
|
||||
async requireWorkspaceTrust(request: WorkspaceTrustRequest = { modal: true }): Promise<WorkspaceTrustState> {
|
||||
if (this.currentTrustState === WorkspaceTrustState.Trusted) {
|
||||
return this.currentTrustState;
|
||||
}
|
||||
if (this.currentTrustState === WorkspaceTrustState.Untrusted && !request?.modal) {
|
||||
if (this.currentTrustState === WorkspaceTrustState.Untrusted && !request.modal) {
|
||||
return this.currentTrustState;
|
||||
}
|
||||
|
||||
if (this._trustRequestPromise) {
|
||||
if (request?.modal &&
|
||||
if (request.modal &&
|
||||
this.requestModel.trustRequest &&
|
||||
!this.requestModel.trustRequest.modal) {
|
||||
this.requestModel.initiateRequest(request);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IWorkspaceTrustRequest, IWorkspaceTrustRequestModel, IWorkspaceTrustService, WorkspaceTrustChangeEvent, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { WorkspaceTrustRequest, IWorkspaceTrustRequestModel, IWorkspaceTrustService, WorkspaceTrustChangeEvent, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { WorkspaceTrustRequestModel } from 'vs/workbench/services/workspaces/common/workspaceTrust';
|
||||
|
||||
export class TestWorkspaceTrustService implements IWorkspaceTrustService {
|
||||
|
@ -22,7 +22,7 @@ export class TestWorkspaceTrustService implements IWorkspaceTrustService {
|
|||
return true;
|
||||
}
|
||||
|
||||
requireWorkspaceTrust(request: IWorkspaceTrustRequest): Promise<WorkspaceTrustState> {
|
||||
requireWorkspaceTrust(request: WorkspaceTrustRequest): Promise<WorkspaceTrustState> {
|
||||
return Promise.resolve(WorkspaceTrustState.Trusted);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue