Skip to content

Commit 4f9c935

Browse files
authored
Startup dialog goes through the request service (microsoft#141592)
1 parent b297fc9 commit 4f9c935

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

src/vs/platform/workspace/common/workspaceTrust.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ export interface IWorkspaceTrustRequestService {
8383

8484
readonly onDidInitiateOpenFilesTrustRequest: Event<void>;
8585
readonly onDidInitiateWorkspaceTrustRequest: Event<WorkspaceTrustRequestOptions | undefined>;
86+
readonly onDidInitiateWorkspaceTrustRequestOnStartup: Event<void>;
8687

8788
completeOpenFilesTrustRequest(result: WorkspaceTrustUriResponse, saveResponse?: boolean): Promise<void>;
8889
requestOpenFilesTrust(openFiles: URI[]): Promise<WorkspaceTrustUriResponse>;
8990

9091
cancelWorkspaceTrustRequest(): void;
9192
completeWorkspaceTrustRequest(trusted?: boolean): Promise<void>;
9293
requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise<boolean | undefined>;
94+
requestWorkspaceTrustOnStartup(): void;
9395
}
9496

9597
export interface IWorkspaceTrustTransitionParticipant {

src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,35 @@ export class WorkspaceTrustUXHandler extends Disposable implements IWorkbenchCon
307307
this._register(this.workspaceTrustManagementService.onDidChangeTrust(trusted => {
308308
this.updateWorkbenchIndicators(trusted);
309309
}));
310+
311+
this._register(this.workspaceTrustRequestService.onDidInitiateWorkspaceTrustRequestOnStartup(() => {
312+
const title = this.useWorkspaceLanguage ?
313+
localize('workspaceTrust', "Do you trust the authors of the files in this workspace?") :
314+
localize('folderTrust', "Do you trust the authors of the files in this folder?");
315+
316+
let checkboxText: string | undefined;
317+
const workspaceIdentifier = toWorkspaceIdentifier(this.workspaceContextService.getWorkspace())!;
318+
const isSingleFolderWorkspace = isSingleFolderWorkspaceIdentifier(workspaceIdentifier);
319+
if (this.workspaceTrustManagementService.canSetParentFolderTrust()) {
320+
const { name } = splitName(splitName((workspaceIdentifier as ISingleFolderWorkspaceIdentifier).uri.fsPath).parentPath);
321+
checkboxText = localize('checkboxString', "Trust the authors of all files in the parent folder '{0}'", name);
322+
}
323+
324+
// Show Workspace Trust Start Dialog
325+
this.doShowModal(
326+
title,
327+
{ label: localize('trustOption', "Yes, I trust the authors"), sublabel: isSingleFolderWorkspace ? localize('trustFolderOptionDescription', "Trust folder and enable all features") : localize('trustWorkspaceOptionDescription', "Trust workspace and enable all features") },
328+
{ label: localize('dontTrustOption', "No, I don't trust the authors"), sublabel: isSingleFolderWorkspace ? localize('dontTrustFolderOptionDescription', "Browse folder in restricted mode") : localize('dontTrustWorkspaceOptionDescription', "Browse workspace in restricted mode") },
329+
[
330+
!isSingleFolderWorkspace ?
331+
localize('workspaceStartupTrustDetails', "{0} provides features that may automatically execute files in this workspace.", this.productService.nameShort) :
332+
localize('folderStartupTrustDetails', "{0} provides features that may automatically execute files in this folder.", this.productService.nameShort),
333+
localize('startupTrustRequestLearnMore', "If you don't trust the authors of these files, we recommend to continue in restricted mode as the files may be malicious. See [our docs](https://aka.ms/vscode-workspace-trust) to learn more."),
334+
`\`${this.labelService.getWorkspaceLabel(workspaceIdentifier, { verbose: true })}\``,
335+
],
336+
checkboxText
337+
);
338+
}));
310339
}
311340

312341
private updateWorkbenchIndicators(trusted: boolean): void {
@@ -404,32 +433,8 @@ export class WorkspaceTrustUXHandler extends Disposable implements IWorkbenchCon
404433
return;
405434
}
406435

407-
const title = this.useWorkspaceLanguage ?
408-
localize('workspaceTrust', "Do you trust the authors of the files in this workspace?") :
409-
localize('folderTrust', "Do you trust the authors of the files in this folder?");
410-
411-
let checkboxText: string | undefined;
412-
const workspaceIdentifier = toWorkspaceIdentifier(this.workspaceContextService.getWorkspace())!;
413-
const isSingleFolderWorkspace = isSingleFolderWorkspaceIdentifier(workspaceIdentifier);
414-
if (this.workspaceTrustManagementService.canSetParentFolderTrust()) {
415-
const { name } = splitName(splitName((workspaceIdentifier as ISingleFolderWorkspaceIdentifier).uri.fsPath).parentPath);
416-
checkboxText = localize('checkboxString', "Trust the authors of all files in the parent folder '{0}'", name);
417-
}
418-
419-
// Show Workspace Trust Start Dialog
420-
this.doShowModal(
421-
title,
422-
{ label: localize('trustOption', "Yes, I trust the authors"), sublabel: isSingleFolderWorkspace ? localize('trustFolderOptionDescription', "Trust folder and enable all features") : localize('trustWorkspaceOptionDescription', "Trust workspace and enable all features") },
423-
{ label: localize('dontTrustOption', "No, I don't trust the authors"), sublabel: isSingleFolderWorkspace ? localize('dontTrustFolderOptionDescription', "Browse folder in restricted mode") : localize('dontTrustWorkspaceOptionDescription', "Browse workspace in restricted mode") },
424-
[
425-
!isSingleFolderWorkspace ?
426-
localize('workspaceStartupTrustDetails', "{0} provides features that may automatically execute files in this workspace.", this.productService.nameShort) :
427-
localize('folderStartupTrustDetails', "{0} provides features that may automatically execute files in this folder.", this.productService.nameShort),
428-
localize('startupTrustRequestLearnMore', "If you don't trust the authors of these files, we recommend to continue in restricted mode as the files may be malicious. See [our docs](https://aka.ms/vscode-workspace-trust) to learn more."),
429-
`\`${this.labelService.getWorkspaceLabel(workspaceIdentifier, { verbose: true })}\``,
430-
],
431-
checkboxText
432-
);
436+
// Use the workspace trust request service to show modal dialog
437+
this.workspaceTrustRequestService.requestWorkspaceTrustOnStartup();
433438
}
434439

435440
private get startupPromptSetting(): 'always' | 'once' | 'never' {

src/vs/workbench/services/workspaces/common/workspaceTrust.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ export class WorkspaceTrustRequestService extends Disposable implements IWorkspa
651651
private readonly _onDidInitiateWorkspaceTrustRequest = this._register(new Emitter<WorkspaceTrustRequestOptions | undefined>());
652652
readonly onDidInitiateWorkspaceTrustRequest = this._onDidInitiateWorkspaceTrustRequest.event;
653653

654+
private readonly _onDidInitiateWorkspaceTrustRequestOnStartup = this._register(new Emitter<void>());
655+
readonly onDidInitiateWorkspaceTrustRequestOnStartup = this._onDidInitiateWorkspaceTrustRequestOnStartup.event;
656+
654657
constructor(
655658
@IConfigurationService private readonly configurationService: IConfigurationService,
656659
@IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService
@@ -794,6 +797,17 @@ export class WorkspaceTrustRequestService extends Disposable implements IWorkspa
794797
return this._workspaceTrustRequestPromise;
795798
}
796799

800+
requestWorkspaceTrustOnStartup(): void {
801+
if (!this._workspaceTrustRequestPromise) {
802+
// Create promise
803+
this._workspaceTrustRequestPromise = new Promise(resolve => {
804+
this._workspaceTrustRequestResolver = resolve;
805+
});
806+
}
807+
808+
this._onDidInitiateWorkspaceTrustRequestOnStartup.fire();
809+
}
810+
797811
//#endregion
798812
}
799813

src/vs/workbench/services/workspaces/test/common/testWorkspaceTrustService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export class TestWorkspaceTrustRequestService implements IWorkspaceTrustRequestS
109109
private readonly _onDidInitiateWorkspaceTrustRequest = new Emitter<WorkspaceTrustRequestOptions>();
110110
readonly onDidInitiateWorkspaceTrustRequest = this._onDidInitiateWorkspaceTrustRequest.event;
111111

112+
private readonly _onDidInitiateWorkspaceTrustRequestOnStartup = new Emitter<void>();
113+
readonly onDidInitiateWorkspaceTrustRequestOnStartup = this._onDidInitiateWorkspaceTrustRequestOnStartup.event;
114+
112115
constructor(private readonly _trusted: boolean) { }
113116

114117
requestOpenUrisHandler = async (uris: URI[]) => {
@@ -134,4 +137,8 @@ export class TestWorkspaceTrustRequestService implements IWorkspaceTrustRequestS
134137
async requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise<boolean> {
135138
return this._trusted;
136139
}
140+
141+
requestWorkspaceTrustOnStartup(): void {
142+
throw new Error('Method not implemented.');
143+
}
137144
}

0 commit comments

Comments
 (0)