@sussudio/platform
Version:
Internal APIs for VS Code's service injection the base services.
95 lines (94 loc) • 4.05 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var __decorate =
(this && this.__decorate) ||
function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
d;
if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param =
(this && this.__param) ||
function (paramIndex, decorator) {
return function (target, key) {
decorator(target, key, paramIndex);
};
};
import { URI } from '@sussudio/base/common/uri.mjs';
import { INativeEnvironmentService } from '../../environment/common/environment.mjs';
import { IFileService } from '../../files/common/files.mjs';
import { refineServiceDecorator } from '../../instantiation/common/instantiation.mjs';
import { ILogService } from '../../log/common/log.mjs';
import { IStateMainService } from '../../state/electron-main/state.mjs';
import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.mjs';
import { IUserDataProfilesService } from '../common/userDataProfile.mjs';
import { UserDataProfilesService } from '../node/userDataProfile.mjs';
export const IUserDataProfilesMainService = refineServiceDecorator(IUserDataProfilesService);
let UserDataProfilesMainService = class UserDataProfilesMainService extends UserDataProfilesService {
stateMainService;
constructor(stateMainService, uriIdentityService, environmentService, fileService, logService) {
super(stateMainService, uriIdentityService, environmentService, fileService, logService);
this.stateMainService = stateMainService;
}
setEnablement(enabled) {
super.setEnablement(enabled);
if (!this.enabled) {
// reset
this.saveStoredProfiles([]);
this.saveStoredProfileAssociations({});
}
}
getAssociatedEmptyWindows() {
const emptyWindows = [];
for (const id of this.profilesObject.emptyWindows.keys()) {
emptyWindows.push({ id });
}
return emptyWindows;
}
saveStoredProfiles(storedProfiles) {
if (storedProfiles.length) {
this.stateMainService.setItem(UserDataProfilesMainService.PROFILES_KEY, storedProfiles);
} else {
this.stateMainService.removeItem(UserDataProfilesMainService.PROFILES_KEY);
}
}
saveStoredProfileAssociations(storedProfileAssociations) {
if (storedProfileAssociations.emptyWindows || storedProfileAssociations.workspaces) {
this.stateMainService.setItem(UserDataProfilesMainService.PROFILE_ASSOCIATIONS_KEY, storedProfileAssociations);
} else {
this.stateMainService.removeItem(UserDataProfilesMainService.PROFILE_ASSOCIATIONS_KEY);
}
}
getStoredProfileAssociations() {
const oldKey = 'workspaceAndProfileInfo';
const storedWorkspaceInfos = this.stateMainService.getItem(oldKey, undefined);
if (storedWorkspaceInfos) {
this.stateMainService.removeItem(oldKey);
const workspaces = storedWorkspaceInfos.reduce((result, { workspace, profile }) => {
result[URI.revive(workspace).toString()] = URI.revive(profile).toString();
return result;
}, {});
this.stateMainService.setItem(UserDataProfilesMainService.PROFILE_ASSOCIATIONS_KEY, { workspaces });
}
return super.getStoredProfileAssociations();
}
};
UserDataProfilesMainService = __decorate(
[
__param(0, IStateMainService),
__param(1, IUriIdentityService),
__param(2, INativeEnvironmentService),
__param(3, IFileService),
__param(4, ILogService),
],
UserDataProfilesMainService,
);
export { UserDataProfilesMainService };