Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve empty workspace detection in web #155643

Merged
merged 2 commits into from Jul 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/vs/workbench/services/workspaces/common/workspaceTrust.ts
Expand Up @@ -15,7 +15,7 @@ import { IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/rem
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
import { isVirtualResource } from 'vs/platform/workspace/common/virtualWorkspace';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { ISingleFolderWorkspaceIdentifier, isSavedWorkspace, isSingleFolderWorkspaceIdentifier, IWorkspace, IWorkspaceContextService, IWorkspaceFolder, toWorkspaceIdentifier, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ISingleFolderWorkspaceIdentifier, isSavedWorkspace, isSingleFolderWorkspaceIdentifier, isTemporaryWorkspace, IWorkspace, IWorkspaceContextService, IWorkspaceFolder, toWorkspaceIdentifier, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustInfo, IWorkspaceTrustUriInfo, IWorkspaceTrustRequestService, IWorkspaceTrustTransitionParticipant, WorkspaceTrustUriResponse, IWorkspaceTrustEnablementService } from 'vs/platform/workspace/common/workspaceTrust';
import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
Expand Down Expand Up @@ -132,7 +132,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
this._workspaceTrustInitializedPromiseResolve = resolve;
});

this._storedTrustState = new WorkspaceTrustMemento(isWeb && this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY ? undefined : this.storageService);
this._storedTrustState = new WorkspaceTrustMemento(isWeb && this.isEmptyWorkspace() ? undefined : this.storageService);
this._trustTransitionManager = this._register(new WorkspaceTrustTransitionManager());

this._trustStateInfo = this.loadTrustInfo();
Expand Down Expand Up @@ -172,7 +172,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
}

// Empty workspace - save initial state to memento
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
if (this.isEmptyWorkspace()) {
this._workspaceTrustInitializedPromise.then(() => {
if (this._storedTrustState.isEmptyWorkspaceTrusted === undefined) {
this._storedTrustState.isEmptyWorkspaceTrusted = this.isWorkspaceTrusted();
Expand Down Expand Up @@ -307,7 +307,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
}

// Empty workspace - use memento, open ediors, or user setting
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
if (this.isEmptyWorkspace()) {
// Use memento if present
if (this._storedTrustState.isEmptyWorkspaceTrusted !== undefined) {
return this._storedTrustState.isEmptyWorkspaceTrusted;
Expand Down Expand Up @@ -426,6 +426,19 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
}
}

private isEmptyWorkspace(): boolean {
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
return true;
}

const workspace = this.workspaceService.getWorkspace();
if (workspace) {
return isTemporaryWorkspace(this.workspaceService.getWorkspace()) && workspace.folders.length === 0;
}

return false;
}

private isTrustedVirtualResource(uri: URI): boolean {
return isVirtualResource(uri) && uri.scheme !== 'vscode-vfs';
}
Expand All @@ -451,7 +464,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
}

// Empty workspace - save memento
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
if (this.isEmptyWorkspace()) {
this._storedTrustState.isEmptyWorkspaceTrusted = value;
}
}
Expand Down Expand Up @@ -530,7 +543,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
}

// Empty workspace
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
if (this.isEmptyWorkspace()) {
return true;
}

Expand Down Expand Up @@ -577,7 +590,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork

async setWorkspaceTrust(trusted: boolean): Promise<void> {
// Empty workspace
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) {
if (this.isEmptyWorkspace()) {
await this.updateWorkspaceTrust(trusted);
return;
}
Expand Down