improve empty workspace detection in web (#155643)

* improve empty workspace detection in web
fixes #155214

* fix order of eval, unit test failures
This commit is contained in:
SteVen Batten 2022-07-19 12:22:14 -07:00 committed by GitHub
parent 9440d5c6b5
commit 646345fba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,7 @@ import { IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/rem
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts'; import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
import { isVirtualResource } from 'vs/platform/workspace/common/virtualWorkspace'; import { isVirtualResource } from 'vs/platform/workspace/common/virtualWorkspace';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; 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 { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustInfo, IWorkspaceTrustUriInfo, IWorkspaceTrustRequestService, IWorkspaceTrustTransitionParticipant, WorkspaceTrustUriResponse, IWorkspaceTrustEnablementService } from 'vs/platform/workspace/common/workspaceTrust';
import { Memento, MementoObject } from 'vs/workbench/common/memento'; import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@ -132,7 +132,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
this._workspaceTrustInitializedPromiseResolve = resolve; 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._trustTransitionManager = this._register(new WorkspaceTrustTransitionManager());
this._trustStateInfo = this.loadTrustInfo(); this._trustStateInfo = this.loadTrustInfo();
@ -172,7 +172,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
} }
// Empty workspace - save initial state to memento // Empty workspace - save initial state to memento
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.isEmptyWorkspace()) {
this._workspaceTrustInitializedPromise.then(() => { this._workspaceTrustInitializedPromise.then(() => {
if (this._storedTrustState.isEmptyWorkspaceTrusted === undefined) { if (this._storedTrustState.isEmptyWorkspaceTrusted === undefined) {
this._storedTrustState.isEmptyWorkspaceTrusted = this.isWorkspaceTrusted(); this._storedTrustState.isEmptyWorkspaceTrusted = this.isWorkspaceTrusted();
@ -307,7 +307,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
} }
// Empty workspace - use memento, open ediors, or user setting // Empty workspace - use memento, open ediors, or user setting
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.isEmptyWorkspace()) {
// Use memento if present // Use memento if present
if (this._storedTrustState.isEmptyWorkspaceTrusted !== undefined) { if (this._storedTrustState.isEmptyWorkspaceTrusted !== undefined) {
return this._storedTrustState.isEmptyWorkspaceTrusted; return this._storedTrustState.isEmptyWorkspaceTrusted;
@ -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 { private isTrustedVirtualResource(uri: URI): boolean {
return isVirtualResource(uri) && uri.scheme !== 'vscode-vfs'; return isVirtualResource(uri) && uri.scheme !== 'vscode-vfs';
} }
@ -451,7 +464,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
} }
// Empty workspace - save memento // Empty workspace - save memento
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.isEmptyWorkspace()) {
this._storedTrustState.isEmptyWorkspaceTrusted = value; this._storedTrustState.isEmptyWorkspaceTrusted = value;
} }
} }
@ -530,7 +543,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
} }
// Empty workspace // Empty workspace
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.isEmptyWorkspace()) {
return true; return true;
} }
@ -577,7 +590,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork
async setWorkspaceTrust(trusted: boolean): Promise<void> { async setWorkspaceTrust(trusted: boolean): Promise<void> {
// Empty workspace // Empty workspace
if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.isEmptyWorkspace()) {
await this.updateWorkspaceTrust(trusted); await this.updateWorkspaceTrust(trusted);
return; return;
} }