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