Skip to content

Commit

Permalink
profile enhancements (#152043)
Browse files Browse the repository at this point in the history
- add id to profile
- add profile property to ICodeWindow
  • Loading branch information
sandy081 authored Jun 14, 2022
1 parent 009d9ec commit e15ae16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vs/platform/userDataProfile/common/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { coalesce } from 'vs/base/common/arrays';
import { Emitter, Event } from 'vs/base/common/event';
import { hash } from 'vs/base/common/hash';
import { Disposable } from 'vs/base/common/lifecycle';
import { joinPath } from 'vs/base/common/resources';
import { UriDto } from 'vs/base/common/types';
Expand All @@ -15,6 +16,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { ILogService } from 'vs/platform/log/common/log';

export interface IUserDataProfile {
readonly id: string;
readonly name: string;
readonly location: URI;
readonly globalStorageHome: URI;
Expand Down Expand Up @@ -50,6 +52,7 @@ export interface IUserDataProfilesService {

function reviveProfile(profile: IUserDataProfile, scheme: string): IUserDataProfile {
return {
id: profile.id,
name: profile.name,
location: URI.revive(profile.location).with({ scheme }),
globalStorageHome: URI.revive(profile.globalStorageHome).with({ scheme }),
Expand Down Expand Up @@ -92,8 +95,9 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
createProfile(name: string | undefined): IUserDataProfile {
const location = name && name !== UserDataProfilesService.DEFAULT_PROFILE_NAME ? joinPath(this.profilesHome, name) : this.environmentService.userRoamingDataHome;
return {
id: hash(location.toString()).toString(16),
name: name ?? UserDataProfilesService.DEFAULT_PROFILE_NAME,
location: location,
location,
globalStorageHome: joinPath(location, 'globalStorage'),
settingsResource: joinPath(location, 'settings.json'),
keybindingsResource: joinPath(location, 'keybindings.json'),
Expand Down
3 changes: 3 additions & 0 deletions src/vs/platform/window/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ISerializableCommandAction } from 'vs/platform/action/common/action';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { INativeWindowConfiguration } from 'vs/platform/window/common/window';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

Expand All @@ -27,6 +28,8 @@ export interface ICodeWindow extends IDisposable {

readonly openedWorkspace?: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier;

readonly profile?: IUserDataProfile;

readonly backupPath?: string;

readonly remoteAuthority?: string;
Expand Down
5 changes: 5 additions & 0 deletions src/vs/platform/windows/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electro
import { IWindowState, ICodeWindow, ILoadEvent, WindowMode, WindowError, LoadReason, defaultWindowState } from 'vs/platform/window/electron-main/window';
import { Color } from 'vs/base/common/color';
import { IPolicyService } from 'vs/platform/policy/common/policy';
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { revive } from 'vs/base/common/marshalling';

export interface IWindowCreationOptions {
state: IWindowState;
Expand Down Expand Up @@ -112,6 +114,9 @@ export class CodeWindow extends Disposable implements ICodeWindow {

get openedWorkspace(): IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined { return this._config?.workspace; }

private _profile: IUserDataProfile | undefined;
get profile(): IUserDataProfile | undefined { if (!this._profile) { this._profile = revive(this._config?.profiles.current); } return this._profile; }

get remoteAuthority(): string | undefined { return this._config?.remoteAuthority; }

private _config: INativeWindowConfiguration | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const args = parseArgs(process.argv, OPTIONS);
const homeDir = homedir();
const NULL_PROFILE = {
name: '',
id: '',
location: URI.file(homeDir),
settingsResource: joinPath(URI.file(homeDir), 'settings.json'),
globalStorageHome: joinPath(URI.file(homeDir), 'globalStorage'),
Expand Down

0 comments on commit e15ae16

Please sign in to comment.