use last active profile in web (#156966)

* use last active profile in web

* 💄

Co-authored-by: Benjamin Pasero <benjamin.pasero@gmail.com>
This commit is contained in:
Sandeep Somavarapu
2022-08-03 08:57:19 +02:00
committed by GitHub
parent bc137bb745
commit 88c5ba1a8a
4 changed files with 26 additions and 10 deletions

View File

@@ -225,6 +225,10 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
}
getProfile(workspaceIdentifier: WorkspaceIdentifier, profileToUseIfNotSet: IUserDataProfile): IUserDataProfile {
if (!this.enabled) {
return this.defaultProfile;
}
const workspace = this.getWorkspace(workspaceIdentifier);
let profile = URI.isUri(workspace) ? this.profilesObject.workspaces.get(workspace) : this.profilesObject.emptyWindow;
if (!profile) {

View File

@@ -269,7 +269,9 @@ export class BrowserMain extends Disposable {
// User Data Profiles
const userDataProfilesService = new BrowserUserDataProfilesService(environmentService, fileService, uriIdentityService, logService);
serviceCollection.set(IUserDataProfilesService, userDataProfilesService);
const userDataProfileService = new UserDataProfileService(userDataProfilesService.getProfile(isWorkspaceIdentifier(payload) || isSingleFolderWorkspaceIdentifier(payload) ? payload : 'empty-window', userDataProfilesService.defaultProfile), userDataProfilesService);
const lastActiveProfile = environmentService.lastActiveProfile ? userDataProfilesService.profiles.find(p => p.id === environmentService.lastActiveProfile) : undefined;
const currentProfile = userDataProfilesService.getProfile(isWorkspaceIdentifier(payload) || isSingleFolderWorkspaceIdentifier(payload) ? payload : 'empty-window', lastActiveProfile ?? userDataProfilesService.defaultProfile);
const userDataProfileService = new UserDataProfileService(currentProfile, userDataProfilesService);
serviceCollection.set(IUserDataProfileService, userDataProfileService);
// Long running services (workspace, config, storage)

View File

@@ -208,6 +208,9 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi
@memoize
get disableWorkspaceTrust(): boolean { return !this.options.enableWorkspaceTrust; }
@memoize
get lastActiveProfile(): string | undefined { return this.payload?.get('lastActiveProfile'); }
editSessionId: string | undefined = this.options.editSessionId;
private payload: Map<string, string> | undefined;

View File

@@ -35,6 +35,7 @@ import { isTemporaryWorkspace, IWorkspaceContextService } from 'vs/platform/work
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { Schemas } from 'vs/base/common/network';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
/**
* A workspace to open in the workbench can either be:
@@ -112,7 +113,8 @@ export class BrowserHostService extends Disposable implements IHostService {
@ILifecycleService private readonly lifecycleService: BrowserLifecycleService,
@ILogService private readonly logService: ILogService,
@IDialogService private readonly dialogService: IDialogService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
) {
super();
@@ -214,7 +216,7 @@ export class BrowserHostService extends Disposable implements IHostService {
}
private async doOpenWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void> {
const payload = this.preservePayload();
const payload = this.preservePayload(false /* not an empty window */);
const fileOpenables: IFileToOpen[] = [];
const foldersToAdd: IWorkspaceFolderCreationData[] = [];
@@ -371,13 +373,11 @@ export class BrowserHostService extends Disposable implements IHostService {
this.instantiationService.invokeFunction(accessor => fn(accessor));
}
private preservePayload(): Array<unknown> | undefined {
private preservePayload(isEmptyWindow: boolean): Array<unknown> | undefined {
// Selectively copy payload: for now only extension debugging properties are considered
let newPayload: Array<unknown> | undefined = undefined;
if (this.environmentService.extensionDevelopmentLocationURI) {
newPayload = new Array();
const newPayload: Array<unknown> = new Array();
if (!isEmptyWindow && this.environmentService.extensionDevelopmentLocationURI) {
newPayload.push(['extensionDevelopmentPath', this.environmentService.extensionDevelopmentLocationURI.toString()]);
if (this.environmentService.debugExtensionHost.debugId) {
@@ -389,7 +389,11 @@ export class BrowserHostService extends Disposable implements IHostService {
}
}
return newPayload;
if (!this.userDataProfileService.currentProfile.isDefault) {
newPayload.push(['lastActiveProfile', this.userDataProfileService.currentProfile.id]);
}
return newPayload.length ? newPayload : undefined;
}
private getRecentLabel(openable: IWindowOpenable): string {
@@ -421,7 +425,10 @@ export class BrowserHostService extends Disposable implements IHostService {
}
private async doOpenEmptyWindow(options?: IOpenEmptyWindowOptions): Promise<void> {
return this.doOpen(undefined, { reuse: options?.forceReuseWindow });
return this.doOpen(undefined, {
reuse: options?.forceReuseWindow,
payload: this.preservePayload(true /* empty window */)
});
}
private async doOpen(workspace: IWorkspace, options?: { reuse?: boolean; payload?: object }): Promise<void> {