diff --git a/src/vs/platform/secrets/common/secrets.ts b/src/vs/platform/secrets/common/secrets.ts index 815fb358e9e..e2b54212a82 100644 --- a/src/vs/platform/secrets/common/secrets.ts +++ b/src/vs/platform/secrets/common/secrets.ts @@ -5,10 +5,15 @@ import { SequencerByKey } from 'vs/base/common/async'; import { IEncryptionService } from 'vs/platform/encryption/common/encryptionService'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IStorageService, InMemoryStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { Event, PauseableEmitter } from 'vs/base/common/event'; import { ILogService } from 'vs/platform/log/common/log'; +import { isNative } from 'vs/base/common/platform'; +import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; +import { localize } from 'vs/nls'; +import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { once } from 'vs/base/common/functional'; export const ISecretStorageService = createDecorator('secretStorageService'); @@ -40,7 +45,9 @@ export class SecretStorageService implements ISecretStorageService { constructor( @IStorageService private _storageService: IStorageService, @IEncryptionService private _encryptionService: IEncryptionService, - @ILogService private readonly _logService: ILogService, + @IInstantiationService private readonly _instantiationService: IInstantiationService, + @INotificationService private readonly _notificationService: INotificationService, + @ILogService private readonly _logService: ILogService ) { this._storageService.onDidChangeValue(e => this.onDidChangeValue(e.key)); } @@ -89,6 +96,10 @@ export class SecretStorageService implements ISecretStorageService { return this._sequencer.queue(key, async () => { await this.initialized; + if (isNative && this.type !== 'persisted') { + this.notifyNativeUserOnce(); + } + const encrypted = await this._encryptionService.encrypt(value); const fullKey = this.getKey(key); try { @@ -129,4 +140,20 @@ export class SecretStorageService implements ISecretStorageService { private getKey(key: string): string { return `${this._storagePrefix}${key}`; } + + private notifyNativeUserOnce = once(() => this.notifyNativeUser()); + private notifyNativeUser(): void { + this._notificationService.prompt( + Severity.Warning, + localize('notEncrypted', 'Secrets are not being stored on disk because encryption is not available in this environment.'), + [{ + label: localize('openTroubleshooting', "Open Troubleshooting"), + run: () => this._instantiationService.invokeFunction(accessor => { + const openerService = accessor.get(IOpenerService); + // Open troubleshooting docs page + return openerService.open('https://go.microsoft.com/fwlink/?linkid=2239490'); + }) + }] + ); + } } diff --git a/src/vs/workbench/services/secrets/browser/secretStorageService.ts b/src/vs/workbench/services/secrets/browser/secretStorageService.ts index bdc68b1f4a1..e28cec9b7d6 100644 --- a/src/vs/workbench/services/secrets/browser/secretStorageService.ts +++ b/src/vs/workbench/services/secrets/browser/secretStorageService.ts @@ -5,7 +5,9 @@ import { IEncryptionService } from 'vs/platform/encryption/common/encryptionService'; import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ILogService } from 'vs/platform/log/common/log'; +import { INotificationService } from 'vs/platform/notification/common/notification'; import { ISecretStorageProvider, ISecretStorageService, SecretStorageService } from 'vs/platform/secrets/common/secrets'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService'; @@ -18,9 +20,11 @@ export class BrowserSecretStorageService extends SecretStorageService { @IStorageService storageService: IStorageService, @IEncryptionService encryptionService: IEncryptionService, @IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService, + @IInstantiationService instantiationService: IInstantiationService, + @INotificationService notificationService: INotificationService, @ILogService logService: ILogService ) { - super(storageService, encryptionService, logService); + super(storageService, encryptionService, instantiationService, notificationService, logService); if (environmentService.options?.secretStorageProvider) { this._secretStorageProvider = environmentService.options.secretStorageProvider;