Skip to content

Commit

Permalink
support loading profile in web (#180331)
Browse files Browse the repository at this point in the history
* support loading profile in web
- embedder api to pass profile and contents
- initialise the profile

* fix typo
  • Loading branch information
sandy081 authored Apr 19, 2023
1 parent 446426b commit 9c4d6d2
Show file tree
Hide file tree
Showing 15 changed files with 797 additions and 410 deletions.
4 changes: 2 additions & 2 deletions src/vs/platform/userDataSync/common/abstractSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getServiceMachineId } from 'vs/platform/externalServices/common/service
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { Change, getLastSyncResourceUri, IRemoteUserData, IResourcePreview as IBaseResourcePreview, ISyncData, IUserDataSyncResourcePreview as IBaseSyncResourcePreview, IUserData, IUserDataInitializer, IUserDataSyncBackupStoreService, IUserDataSyncConfiguration, IUserDataSynchroniser, IUserDataSyncLogService, IUserDataSyncEnablementService, IUserDataSyncStoreService, IUserDataSyncUtilService, MergeState, PREVIEW_DIR_NAME, SyncResource, SyncStatus, UserDataSyncError, UserDataSyncErrorCode, USER_DATA_SYNC_CONFIGURATION_SCOPE, USER_DATA_SYNC_SCHEME, IUserDataResourceManifest, getPathSegments, IUserDataSyncResourceConflicts, IUserDataSyncResource } from 'vs/platform/userDataSync/common/userDataSync';
import { Change, getLastSyncResourceUri, IRemoteUserData, IResourcePreview as IBaseResourcePreview, ISyncData, IUserDataSyncResourcePreview as IBaseSyncResourcePreview, IUserData, IUserDataSyncResourceInitializer, IUserDataSyncBackupStoreService, IUserDataSyncConfiguration, IUserDataSynchroniser, IUserDataSyncLogService, IUserDataSyncEnablementService, IUserDataSyncStoreService, IUserDataSyncUtilService, MergeState, PREVIEW_DIR_NAME, SyncResource, SyncStatus, UserDataSyncError, UserDataSyncErrorCode, USER_DATA_SYNC_CONFIGURATION_SCOPE, USER_DATA_SYNC_SCHEME, IUserDataResourceManifest, getPathSegments, IUserDataSyncResourceConflicts, IUserDataSyncResource } from 'vs/platform/userDataSync/common/userDataSync';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';

type IncompatibleSyncSourceClassification = {
Expand Down Expand Up @@ -915,7 +915,7 @@ export abstract class AbstractJsonFileSynchroniser extends AbstractFileSynchroni

}

export abstract class AbstractInitializer implements IUserDataInitializer {
export abstract class AbstractInitializer implements IUserDataSyncResourceInitializer {

protected readonly extUri: IExtUri;
private readonly lastSyncResource: URI;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/userDataSync/common/userDataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export interface IUserDataSyncResourceError extends IUserDataSyncResource {
readonly error: UserDataSyncError;
}

export interface IUserDataInitializer {
export interface IUserDataSyncResourceInitializer {
initialize(userData: IUserData): Promise<void>;
}

Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/web.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ export interface IWorkbenchConstructionOptions {

//#region Profile options

/**
* Profile to use for the workbench.
*/
readonly profile?: { readonly name: string; readonly contents?: string | UriComponents };

/**
* URI of the profile to preview.
*/
Expand Down
39 changes: 28 additions & 11 deletions src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { IndexedDBFileSystemProviderErrorDataClassification, IndexedDBFileSystemProvider, IndexedDBFileSystemProviderErrorData } from 'vs/platform/files/browser/indexedDBFileSystemProvider';
import { BrowserRequestService } from 'vs/workbench/services/request/browser/requestService';
import { IRequestService } from 'vs/platform/request/common/request';
import { IUserDataInitializationService, UserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit';
import { IUserDataInitializationService, IUserDataInitializer, UserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit';
import { UserDataSyncStoreManagementService } from 'vs/platform/userDataSync/common/userDataSyncStoreService';
import { IUserDataSyncStoreManagementService } from 'vs/platform/userDataSync/common/userDataSync';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
Expand Down Expand Up @@ -73,7 +73,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { DelayedLogChannel } from 'vs/workbench/services/output/common/delayedLogChannel';
import { dirname, joinPath } from 'vs/base/common/resources';
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { NullPolicyService } from 'vs/platform/policy/common/policy';
import { IRemoteExplorerService, TunnelSource } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { DisposableTunnel, TunnelProtocol } from 'vs/platform/tunnel/common/tunnel';
Expand All @@ -86,6 +86,8 @@ import { windowLogId } from 'vs/workbench/services/log/common/logConstants';
import { LogService } from 'vs/platform/log/common/logService';
import { VSBuffer } from 'vs/base/common/buffer';
import { IStoredWorkspace } from 'vs/platform/workspaces/common/workspaces';
import { UserDataProfileInitializer } from 'vs/workbench/services/userDataProfile/browser/userDataProfileInit';
import { UserDataSyncInitializer } from 'vs/workbench/services/userDataSync/browser/userDataSyncInit';

export class BrowserMain extends Disposable {

Expand Down Expand Up @@ -281,6 +283,10 @@ export class BrowserMain extends Disposable {
const loggerService = new FileLoggerService(logLevel, logsPath, fileService);
serviceCollection.set(ILoggerService, loggerService);

// Register File System Providers depending on IndexedDB support
// Register them early because they are needed for the profiles initialization
await this.registerIndexedDBFileSystemProviders(environmentService, fileService, bufferLogger, logService, loggerService, logsPath);

// URI Identity
const uriIdentityService = new UriIdentityService(fileService);
serviceCollection.set(IUriIdentityService, uriIdentityService);
Expand All @@ -289,15 +295,14 @@ export class BrowserMain extends Disposable {
const userDataProfilesService = new BrowserUserDataProfilesService(environmentService, fileService, uriIdentityService, logService);
serviceCollection.set(IUserDataProfilesService, userDataProfilesService);

const currentProfile = userDataProfilesService.getProfileForWorkspace(workspace) ?? userDataProfilesService.defaultProfile;
const currentProfile = await this.getCurrentProfile(workspace, userDataProfilesService, environmentService);
const userDataProfileService = new UserDataProfileService(currentProfile, userDataProfilesService);
serviceCollection.set(IUserDataProfileService, userDataProfileService);

// Remote Agent
const remoteAgentService = this._register(new RemoteAgentService(this.configuration.webSocketFactory, userDataProfileService, environmentService, productService, remoteAuthorityResolverService, signService, logService));
serviceCollection.set(IRemoteAgentService, remoteAgentService);

await this.registerFileSystemProviders(environmentService, fileService, remoteAgentService, bufferLogger, logService, loggerService, logsPath);
this._register(RemoteFileSystemProviderClient.register(remoteAgentService, fileService, logService));

// Long running services (workspace, config, storage)
const [configurationService, storageService] = await Promise.all([
Expand Down Expand Up @@ -365,7 +370,12 @@ export class BrowserMain extends Disposable {
serviceCollection.set(ICredentialsService, credentialsService);

// Userdata Initialize Service
const userDataInitializationService = new UserDataInitializationService(environmentService, credentialsService, userDataSyncStoreManagementService, fileService, userDataProfilesService, storageService, productService, requestService, logService, uriIdentityService);
const userDataInitializers: IUserDataInitializer[] = [];
userDataInitializers.push(new UserDataSyncInitializer(environmentService, credentialsService, userDataSyncStoreManagementService, fileService, userDataProfilesService, storageService, productService, requestService, logService, uriIdentityService));
if (environmentService.options.profile) {
userDataInitializers.push(new UserDataProfileInitializer(environmentService, fileService, userDataProfileService, storageService, logService, uriIdentityService, requestService));
}
const userDataInitializationService = new UserDataInitializationService(userDataInitializers);
serviceCollection.set(IUserDataInitializationService, userDataInitializationService);

try {
Expand Down Expand Up @@ -396,8 +406,7 @@ export class BrowserMain extends Disposable {
}
}

private async registerFileSystemProviders(environmentService: IWorkbenchEnvironmentService, fileService: IWorkbenchFileService, remoteAgentService: IRemoteAgentService, bufferLogger: BufferLogger, logService: ILogService, loggerService: ILoggerService, logsPath: URI): Promise<void> {

private async registerIndexedDBFileSystemProviders(environmentService: IWorkbenchEnvironmentService, fileService: IWorkbenchFileService, bufferLogger: BufferLogger, logService: ILogService, loggerService: ILoggerService, logsPath: URI): Promise<void> {
// IndexedDB is used for logging and user data
let indexedDB: IndexedDB | undefined;
const userDataStore = 'vscode-userdata-store';
Expand Down Expand Up @@ -435,9 +444,6 @@ export class BrowserMain extends Disposable {
}
fileService.registerProvider(Schemas.vscodeUserData, userDataProvider);

// Remote file system
this._register(RemoteFileSystemProviderClient.register(remoteAgentService, fileService, logService));

// Local file access (if supported by browser)
if (WebFileSystemAccess.supported(window)) {
fileService.registerProvider(Schemas.file, new HTMLFileSystemProvider(indexedDB, handlesStore, logService));
Expand Down Expand Up @@ -538,6 +544,17 @@ export class BrowserMain extends Disposable {
}
}

private async getCurrentProfile(workspace: IAnyWorkspaceIdentifier, userDataProfilesService: BrowserUserDataProfilesService, environmentService: IBrowserWorkbenchEnvironmentService): Promise<IUserDataProfile> {
if (environmentService.options?.profile) {
const profile = userDataProfilesService.profiles.find(p => p.name === environmentService.options?.profile?.name);
if (profile) {
return profile;
}
return userDataProfilesService.createNamedProfile(environmentService.options?.profile?.name, undefined, workspace);
}
return userDataProfilesService.getProfileForWorkspace(workspace) ?? userDataProfilesService.defaultProfile;
}

private resolveWorkspace(): IAnyWorkspaceIdentifier {
let workspace: IWorkspace | undefined = undefined;
if (this.configuration.workspaceProvider) {
Expand Down
Loading

0 comments on commit 9c4d6d2

Please sign in to comment.