提交 2e89c2d4 编写于 作者: R Rachel Macfarlane

Add 'key' to onDidChange of secrets API, #112249

上级 c5f0bac2
...@@ -49,7 +49,7 @@ export interface ICommonNativeHostService { ...@@ -49,7 +49,7 @@ export interface ICommonNativeHostService {
readonly onDidChangeColorScheme: Event<IColorScheme>; readonly onDidChangeColorScheme: Event<IColorScheme>;
readonly onDidChangePassword: Event<void>; readonly onDidChangePassword: Event<{ service: string, account: string }>;
// Window // Window
getWindows(): Promise<IOpenedWindow[]>; getWindows(): Promise<IOpenedWindow[]>;
......
...@@ -90,7 +90,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain ...@@ -90,7 +90,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
private readonly _onDidChangeColorScheme = this._register(new Emitter<IColorScheme>()); private readonly _onDidChangeColorScheme = this._register(new Emitter<IColorScheme>());
readonly onDidChangeColorScheme = this._onDidChangeColorScheme.event; readonly onDidChangeColorScheme = this._onDidChangeColorScheme.event;
private readonly _onDidChangePassword = this._register(new Emitter<void>()); private readonly _onDidChangePassword = this._register(new Emitter<{ account: string, service: string }>());
readonly onDidChangePassword = this._onDidChangePassword.event; readonly onDidChangePassword = this._onDidChangePassword.event;
//#endregion //#endregion
...@@ -705,7 +705,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain ...@@ -705,7 +705,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
await keytar.setPassword(service, account, password); await keytar.setPassword(service, account, password);
} }
this._onDidChangePassword.fire(); this._onDidChangePassword.fire({ service, account });
} }
async deletePassword(windowId: number | undefined, service: string, account: string): Promise<boolean> { async deletePassword(windowId: number | undefined, service: string, account: string): Promise<boolean> {
...@@ -713,7 +713,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain ...@@ -713,7 +713,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
const didDelete = await keytar.deletePassword(service, account); const didDelete = await keytar.deletePassword(service, account);
if (didDelete) { if (didDelete) {
this._onDidChangePassword.fire(); this._onDidChangePassword.fire({ service, account });
} }
return didDelete; return didDelete;
......
...@@ -2424,6 +2424,16 @@ declare module 'vscode' { ...@@ -2424,6 +2424,16 @@ declare module 'vscode' {
//#region https://github.com/microsoft/vscode/issues/112249 //#region https://github.com/microsoft/vscode/issues/112249
/**
* The event data that is fired when a secret is added or removed.
*/
export interface SecretStorageChangeEvent {
/**
* The key of the secret that has changed.
*/
key: string;
}
/** /**
* Represents a storage utility for secrets, information that is * Represents a storage utility for secrets, information that is
* sensitive. * sensitive.
...@@ -2453,7 +2463,7 @@ declare module 'vscode' { ...@@ -2453,7 +2463,7 @@ declare module 'vscode' {
/** /**
* Fires when a secret is set or deleted. * Fires when a secret is set or deleted.
*/ */
onDidChange: Event<void>; onDidChange: Event<SecretStorageChangeEvent>;
} }
export interface ExtensionContext { export interface ExtensionContext {
......
...@@ -23,8 +23,9 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre ...@@ -23,8 +23,9 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
super(); super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostSecretState); this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostSecretState);
this._register(this.credentialsService.onDidChangePassword(_ => { this._register(this.credentialsService.onDidChangePassword(e => {
this._proxy.$onDidChangePassword(); const extensionId = e.service.substring(this.productService.urlProtocol.length);
this._proxy.$onDidChangePassword({ extensionId, key: e.account });
})); }));
} }
......
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtHostSecretStateShape, MainContext, MainThreadSecretStateShape } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostSecretStateShape, MainContext, MainThreadSecretStateShape } from 'vs/workbench/api/common/extHost.protocol';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter } from 'vs/base/common/event';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export class ExtHostSecretState implements ExtHostSecretStateShape { export class ExtHostSecretState implements ExtHostSecretStateShape {
private _proxy: MainThreadSecretStateShape; private _proxy: MainThreadSecretStateShape;
private _onDidChangePassword = new Emitter<void>(); private _onDidChangePassword = new Emitter<{ extensionId: string, key: string }>();
readonly onDidChangePassword: Event<void> = this._onDidChangePassword.event; readonly onDidChangePassword = this._onDidChangePassword.event;
constructor(mainContext: IExtHostRpcService) { constructor(mainContext: IExtHostRpcService) {
this._proxy = mainContext.getProxy(MainContext.MainThreadSecretState); this._proxy = mainContext.getProxy(MainContext.MainThreadSecretState);
} }
async $onDidChangePassword(): Promise<void> { async $onDidChangePassword(e: { extensionId: string, key: string }): Promise<void> {
this._onDidChangePassword.fire(); this._onDidChangePassword.fire(e);
} }
get(extensionId: string, key: string): Promise<string | undefined> { get(extensionId: string, key: string): Promise<string | undefined> {
......
...@@ -1130,7 +1130,7 @@ export interface ExtHostAuthenticationShape { ...@@ -1130,7 +1130,7 @@ export interface ExtHostAuthenticationShape {
} }
export interface ExtHostSecretStateShape { export interface ExtHostSecretStateShape {
$onDidChangePassword(): Promise<void>; $onDidChangePassword(e: { extensionId: string, key: string }): Promise<void>;
} }
export interface ExtHostSearchShape { export interface ExtHostSearchShape {
......
...@@ -14,15 +14,19 @@ export class ExtensionSecrets implements vscode.SecretStorage { ...@@ -14,15 +14,19 @@ export class ExtensionSecrets implements vscode.SecretStorage {
protected readonly _id: string; protected readonly _id: string;
protected readonly _secretState: ExtHostSecretState; protected readonly _secretState: ExtHostSecretState;
private _onDidChange = new Emitter<void>(); private _onDidChange = new Emitter<vscode.SecretStorageChangeEvent>();
readonly onDidChange: Event<void> = this._onDidChange.event; readonly onDidChange: Event<vscode.SecretStorageChangeEvent> = this._onDidChange.event;
constructor(extensionDescription: IExtensionDescription, secretState: ExtHostSecretState) { constructor(extensionDescription: IExtensionDescription, secretState: ExtHostSecretState) {
this._id = ExtensionIdentifier.toKey(extensionDescription.identifier); this._id = ExtensionIdentifier.toKey(extensionDescription.identifier);
this._secretState = secretState; this._secretState = secretState;
this._secretState.onDidChangePassword(_ => this._onDidChange.fire()); this._secretState.onDidChangePassword(e => {
if (e.extensionId === this._id) {
this._onDidChange.fire({ key: e.key });
}
});
} }
get(key: string): Promise<string | undefined> { get(key: string): Promise<string | undefined> {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ICredentialsService, ICredentialsProvider } from 'vs/workbench/services/credentials/common/credentials'; import { ICredentialsService, ICredentialsProvider, ICredentialsChangeEvent } from 'vs/workbench/services/credentials/common/credentials';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { Emitter } from 'vs/base/common/event'; import { Emitter } from 'vs/base/common/event';
...@@ -13,7 +13,7 @@ export class BrowserCredentialsService extends Disposable implements ICredential ...@@ -13,7 +13,7 @@ export class BrowserCredentialsService extends Disposable implements ICredential
declare readonly _serviceBrand: undefined; declare readonly _serviceBrand: undefined;
private _onDidChangePassword = this._register(new Emitter<void>()); private _onDidChangePassword = this._register(new Emitter<ICredentialsChangeEvent>());
readonly onDidChangePassword = this._onDidChangePassword.event; readonly onDidChangePassword = this._onDidChangePassword.event;
private credentialsProvider: ICredentialsProvider; private credentialsProvider: ICredentialsProvider;
...@@ -35,13 +35,13 @@ export class BrowserCredentialsService extends Disposable implements ICredential ...@@ -35,13 +35,13 @@ export class BrowserCredentialsService extends Disposable implements ICredential
async setPassword(service: string, account: string, password: string): Promise<void> { async setPassword(service: string, account: string, password: string): Promise<void> {
await this.credentialsProvider.setPassword(service, account, password); await this.credentialsProvider.setPassword(service, account, password);
this._onDidChangePassword.fire(); this._onDidChangePassword.fire({ service, account });
} }
deletePassword(service: string, account: string): Promise<boolean> { deletePassword(service: string, account: string): Promise<boolean> {
const didDelete = this.credentialsProvider.deletePassword(service, account); const didDelete = this.credentialsProvider.deletePassword(service, account);
if (didDelete) { if (didDelete) {
this._onDidChangePassword.fire(); this._onDidChangePassword.fire({ service, account });
} }
return didDelete; return didDelete;
......
...@@ -16,7 +16,12 @@ export interface ICredentialsProvider { ...@@ -16,7 +16,12 @@ export interface ICredentialsProvider {
findCredentials(service: string): Promise<Array<{ account: string, password: string }>>; findCredentials(service: string): Promise<Array<{ account: string, password: string }>>;
} }
export interface ICredentialsChangeEvent {
service: string
account: string;
}
export interface ICredentialsService extends ICredentialsProvider { export interface ICredentialsService extends ICredentialsProvider {
readonly _serviceBrand: undefined; readonly _serviceBrand: undefined;
readonly onDidChangePassword: Event<void>; readonly onDidChangePassword: Event<ICredentialsChangeEvent>;
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ICredentialsService } from 'vs/workbench/services/credentials/common/credentials'; import { ICredentialsChangeEvent, ICredentialsService } from 'vs/workbench/services/credentials/common/credentials';
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Emitter } from 'vs/base/common/event'; import { Emitter } from 'vs/base/common/event';
...@@ -13,7 +13,7 @@ export class KeytarCredentialsService extends Disposable implements ICredentials ...@@ -13,7 +13,7 @@ export class KeytarCredentialsService extends Disposable implements ICredentials
declare readonly _serviceBrand: undefined; declare readonly _serviceBrand: undefined;
private _onDidChangePassword: Emitter<void> = this._register(new Emitter()); private _onDidChangePassword: Emitter<ICredentialsChangeEvent> = this._register(new Emitter());
readonly onDidChangePassword = this._onDidChangePassword.event; readonly onDidChangePassword = this._onDidChangePassword.event;
constructor(@INativeHostService private readonly nativeHostService: INativeHostService) { constructor(@INativeHostService private readonly nativeHostService: INativeHostService) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册