提交 31419adc 编写于 作者: R Rachel Macfarlane

Polish onDidChangePassword changes

上级 9910c380
......@@ -84,12 +84,6 @@ export class Keychain {
return Promise.resolve(undefined);
}
}
onDidChangePassword(listener: () => void) {
vscode.authentication.onDidChangePassword(_ => {
listener();
});
}
}
export const keychain = new Keychain();
......@@ -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();
......
......@@ -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() {
......
......@@ -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},`;
......
......@@ -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();
......
......@@ -101,12 +101,6 @@ export class Keychain {
return Promise.resolve(null);
}
}
onDidChangePassword(listener: () => void) {
vscode.authentication.onDidChangePassword(_ => {
listener();
});
}
}
export const keychain = new Keychain();
......@@ -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> {
......
......@@ -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;
......
......@@ -18,5 +18,5 @@ export interface ICredentialsProvider {
export interface ICredentialsService extends ICredentialsProvider {
readonly _serviceBrand: undefined;
onDidChangePassword: Event<void>;
readonly onDidChangePassword: Event<void>;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册