Polish onDidChangePassword changes

This commit is contained in:
Rachel Macfarlane 2020-10-12 10:31:00 -07:00
parent 9910c38005
commit 31419adc34
9 changed files with 15 additions and 22 deletions

View file

@ -84,12 +84,6 @@ export class Keychain {
return Promise.resolve(undefined);
}
}
onDidChangePassword(listener: () => void) {
vscode.authentication.onDidChangePassword(_ => {
listener();
});
}
}
export const keychain = new Keychain();

View file

@ -16,7 +16,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
const loginService = new GitHubAuthenticationProvider();
await loginService.initialize();
await loginService.initialize(context);
context.subscriptions.push(vscode.commands.registerCommand('github.provide-token', () => {
return loginService.manuallyProvideToken();

View file

@ -26,14 +26,14 @@ export class GitHubAuthenticationProvider {
private _sessions: vscode.AuthenticationSession[] = [];
private _githubServer = new GitHubServer();
public async initialize(): Promise<void> {
public async initialize(context: vscode.ExtensionContext): Promise<void> {
try {
this._sessions = await this.readSessions();
} catch (e) {
// Ignore, network request failed
}
keychain.onDidChangePassword(() => this.checkForUpdates());
context.subscriptions.push(vscode.authentication.onDidChangePassword(() => this.checkForUpdates()));
}
private async checkForUpdates() {

View file

@ -93,10 +93,11 @@ export class AzureActiveDirectoryService {
private _tokens: IToken[] = [];
private _refreshTimeouts: Map<string, NodeJS.Timeout> = new Map<string, NodeJS.Timeout>();
private _uriHandler: UriEventHandler;
private _disposables: vscode.Disposable[] = [];
constructor() {
this._uriHandler = new UriEventHandler();
vscode.window.registerUriHandler(this._uriHandler);
this._disposables.push(vscode.window.registerUriHandler(this._uriHandler));
}
public async initialize(): Promise<void> {
@ -140,7 +141,7 @@ export class AzureActiveDirectoryService {
}
}
keychain.onDidChangePassword(() => this.checkForUpdates);
this._disposables.push(vscode.authentication.onDidChangePassword(() => this.checkForUpdates));
}
private parseStoredData(data: string): IStoredSession[] {
@ -340,6 +341,11 @@ export class AzureActiveDirectoryService {
});
}
public dispose(): void {
this._disposables.forEach(disposable => disposable.dispose());
this._disposables = [];
}
private getCallbackEnvironment(callbackUri: vscode.Uri): string {
if (callbackUri.authority.endsWith('.workspaces.github.com') || callbackUri.authority.endsWith('.github.dev')) {
return `${callbackUri.authority},`;

View file

@ -14,6 +14,7 @@ export async function activate(context: vscode.ExtensionContext) {
const telemetryReporter = new TelemetryReporter(name, version, aiKey);
const loginService = new AzureActiveDirectoryService();
context.subscriptions.push(loginService);
await loginService.initialize();

View file

@ -101,12 +101,6 @@ export class Keychain {
return Promise.resolve(null);
}
}
onDidChangePassword(listener: () => void) {
vscode.authentication.onDidChangePassword(_ => {
listener();
});
}
}
export const keychain = new Keychain();

View file

@ -24,7 +24,6 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
private _onDidChangeSessions = new Emitter<vscode.AuthenticationSessionsChangeEvent>();
readonly onDidChangeSessions: Event<vscode.AuthenticationSessionsChangeEvent> = this._onDidChangeSessions.event;
private _onDidChangePassword = new Emitter<void>();
readonly onDidChangePassword: Event<void> = this._onDidChangePassword.event;
@ -208,9 +207,8 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return Promise.resolve();
}
$onDidChangePassword(): Promise<void> {
async $onDidChangePassword(): Promise<void> {
this._onDidChangePassword.fire();
return Promise.resolve();
}
getPassword(requestingExtension: IExtensionDescription, key: string): Promise<string | undefined> {

View file

@ -13,7 +13,7 @@ export class BrowserCredentialsService implements ICredentialsService {
declare readonly _serviceBrand: undefined;
private _onDidChangePassword: Emitter<void> = new Emitter();
onDidChangePassword = this._onDidChangePassword.event;
readonly onDidChangePassword = this._onDidChangePassword.event;
private credentialsProvider: ICredentialsProvider;

View file

@ -18,5 +18,5 @@ export interface ICredentialsProvider {
export interface ICredentialsService extends ICredentialsProvider {
readonly _serviceBrand: undefined;
onDidChangePassword: Event<void>;
readonly onDidChangePassword: Event<void>;
}