blob: 37727ac08a3139fd7d44727701c9c3d687b04552 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Promises } from 'vs/base/common/async';
import { Codicon } from 'vs/base/common/codicons';
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { DidChangeUserDataProfileEvent, IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
const defaultUserDataProfileIcon = registerIcon('defaultProfile-icon', Codicon.settings, localize('defaultProfileIcon', 'Icon for Default Profile.'));
export class UserDataProfileService extends Disposable implements IUserDataProfileService {
readonly _serviceBrand: undefined;
private readonly _onDidChangeCurrentProfile = this._register(new Emitter<DidChangeUserDataProfileEvent>());
readonly onDidChangeCurrentProfile = this._onDidChangeCurrentProfile.event;
private readonly _onDidUpdateCurrentProfile = this._register(new Emitter<void>());
readonly onDidUpdateCurrentProfile = this._onDidUpdateCurrentProfile.event;
private _currentProfile: IUserDataProfile;
get currentProfile(): IUserDataProfile { return this._currentProfile; }
constructor(
currentProfile: IUserDataProfile,
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
) {
super();
this._currentProfile = currentProfile;
this._register(userDataProfilesService.onDidChangeProfiles(e => {
const updatedCurrentProfile = e.updated.find(p => this._currentProfile.id === p.id);
if (updatedCurrentProfile) {
this._currentProfile = updatedCurrentProfile;
this._onDidUpdateCurrentProfile.fire();
}
}));
}
async updateCurrentProfile(userDataProfile: IUserDataProfile, preserveData: boolean): Promise<void> {
if (this._currentProfile.id === userDataProfile.id) {
return;
}
const previous = this._currentProfile;
this._currentProfile = userDataProfile;
const joiners: Promise<void>[] = [];
this._onDidChangeCurrentProfile.fire({
preserveData,
previous,
profile: userDataProfile,
join(promise) {
joiners.push(promise);
}
});
await Promises.settled(joiners);
}
getShortName(profile: IUserDataProfile): string {
if (profile.isDefault) {
return `$(${defaultUserDataProfileIcon.id})`;
}
if (profile.shortName) {
return profile.shortName;
}
if (profile.isTransient) {
return `T${profile.name.charAt(profile.name.length - 1)}`;
}
return profile.name.substring(0, 2).toUpperCase();
}
}
|