Path: blob/main/src/vs/workbench/contrib/encryption/electron-browser/encryption.contribution.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { isLinux } from '../../../../base/common/platform.js';6import { parse } from '../../../../base/common/jsonc.js';7import { IEnvironmentService } from '../../../../platform/environment/common/environment.js';8import { IFileService } from '../../../../platform/files/common/files.js';9import { Registry } from '../../../../platform/registry/common/platform.js';10import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';11import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from '../../../common/contributions.js';12import { IJSONEditingService } from '../../../services/configuration/common/jsonEditing.js';13import { LifecyclePhase } from '../../../services/lifecycle/common/lifecycle.js';1415class EncryptionContribution implements IWorkbenchContribution {16constructor(17@IJSONEditingService private readonly jsonEditingService: IJSONEditingService,18@IEnvironmentService private readonly environmentService: IEnvironmentService,19@IFileService private readonly fileService: IFileService,20@IStorageService private readonly storageService: IStorageService21) {22this.migrateToGnomeLibsecret();23}2425/**26* Migrate the user from using the gnome or gnome-keyring password-store to gnome-libsecret.27* TODO@TylerLeonhardt: This migration can be removed in 3 months or so and then storage28* can be cleaned up.29*/30private async migrateToGnomeLibsecret(): Promise<void> {31if (!isLinux || this.storageService.getBoolean('encryption.migratedToGnomeLibsecret', StorageScope.APPLICATION, false)) {32return;33}34try {35const content = await this.fileService.readFile(this.environmentService.argvResource);36const argv = parse<{ 'password-store'?: string }>(content.value.toString());37if (argv['password-store'] === 'gnome' || argv['password-store'] === 'gnome-keyring') {38this.jsonEditingService.write(this.environmentService.argvResource, [{ path: ['password-store'], value: 'gnome-libsecret' }], true);39}40this.storageService.store('encryption.migratedToGnomeLibsecret', true, StorageScope.APPLICATION, StorageTarget.USER);41} catch (error) {42console.error(error);43}44}45}4647Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(EncryptionContribution, LifecyclePhase.Eventually);484950