Make github-authentication a UI extension again

This commit is contained in:
Rachel Macfarlane 2020-08-24 18:43:59 -07:00
parent 6be16f9a16
commit 8871a28963
7 changed files with 35 additions and 11 deletions

View file

@ -11,6 +11,11 @@
"categories": [ "categories": [
"Other" "Other"
], ],
"extensionKind": [
"ui",
"workspace",
"web"
],
"activationEvents": [ "activationEvents": [
"*", "*",
"onAuthenticationRequest:github" "onAuthenticationRequest:github"

View file

@ -249,7 +249,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
} }
$ensureProvider(id: string): Promise<void> { $ensureProvider(id: string): Promise<void> {
return this.extensionService.activateByEvent(getAuthenticationProviderActivationEvent(id)); return this.extensionService.activateByEvent(getAuthenticationProviderActivationEvent(id), true);
} }
$sendDidChangeSessions(id: string, event: modes.AuthenticationSessionsChangeEvent): void { $sendDidChangeSessions(id: string, event: modes.AuthenticationSessionsChangeEvent): void {

View file

@ -1074,7 +1074,7 @@ export type IResolveAuthorityResult = IResolveAuthorityErrorResult | IResolveAut
export interface ExtHostExtensionServiceShape { export interface ExtHostExtensionServiceShape {
$resolveAuthority(remoteAuthority: string, resolveAttempt: number): Promise<IResolveAuthorityResult>; $resolveAuthority(remoteAuthority: string, resolveAttempt: number): Promise<IResolveAuthorityResult>;
$startExtensionHost(enabledExtensionIds: ExtensionIdentifier[]): Promise<void>; $startExtensionHost(enabledExtensionIds: ExtensionIdentifier[]): Promise<void>;
$activateByEvent(activationEvent: string): Promise<void>; $activateByEvent(activationEvent: string, eager?: boolean): Promise<void>;
$activate(extensionId: ExtensionIdentifier, reason: ExtensionActivationReason): Promise<boolean>; $activate(extensionId: ExtensionIdentifier, reason: ExtensionActivationReason): Promise<boolean>;
$setRemoteEnvironment(env: { [key: string]: string | null; }): Promise<void>; $setRemoteEnvironment(env: { [key: string]: string | null; }): Promise<void>;
$updateRemoteConnectionData(connectionData: IRemoteConnectionData): Promise<void>; $updateRemoteConnectionData(connectionData: IRemoteConnectionData): Promise<void>;

View file

@ -686,7 +686,11 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
return this._startExtensionHost(); return this._startExtensionHost();
} }
public $activateByEvent(activationEvent: string): Promise<void> { public $activateByEvent(activationEvent: string, eager: boolean = true): Promise<void> {
if (eager) {
return this._activateByEvent(activationEvent, false);
}
return ( return (
this._readyToRunExtensions.wait() this._readyToRunExtensions.wait()
.then(_ => this._activateByEvent(activationEvent, false)) .then(_ => this._activateByEvent(activationEvent, false))

View file

@ -186,7 +186,7 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
this._startExtensionHosts(false, Array.from(this._allRequestedActivateEvents.keys())); this._startExtensionHosts(false, Array.from(this._allRequestedActivateEvents.keys()));
} }
public activateByEvent(activationEvent: string): Promise<void> { public activateByEvent(activationEvent: string, eager?: boolean): Promise<void> {
if (this._installedExtensionsReady.isOpen()) { if (this._installedExtensionsReady.isOpen()) {
// Extensions have been scanned and interpreted // Extensions have been scanned and interpreted
@ -205,13 +205,17 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
// Record the fact that this activationEvent was requested (in case of a restart) // Record the fact that this activationEvent was requested (in case of a restart)
this._allRequestedActivateEvents.add(activationEvent); this._allRequestedActivateEvents.add(activationEvent);
if (eager) {
return this._activateByEvent(activationEvent, eager);
}
return this._installedExtensionsReady.wait().then(() => this._activateByEvent(activationEvent)); return this._installedExtensionsReady.wait().then(() => this._activateByEvent(activationEvent));
} }
} }
private _activateByEvent(activationEvent: string): Promise<void> { private _activateByEvent(activationEvent: string, eager?: boolean): Promise<void> {
const result = Promise.all( const result = Promise.all(
this._extensionHostManagers.map(extHostManager => extHostManager.activateByEvent(activationEvent)) this._extensionHostManagers.map(extHostManager => extHostManager.activateByEvent(activationEvent, eager))
).then(() => { }); ).then(() => { });
this._onWillActivateByEvent.fire({ this._onWillActivateByEvent.fire({
event: activationEvent, event: activationEvent,

View file

@ -48,6 +48,7 @@ export class ExtensionHostManager extends Disposable {
*/ */
private _proxy: Promise<{ value: ExtHostExtensionServiceShape; } | null> | null; private _proxy: Promise<{ value: ExtHostExtensionServiceShape; } | null> | null;
private _resolveAuthorityAttempt: number; private _resolveAuthorityAttempt: number;
private _hasStarted = false;
constructor( constructor(
extensionHost: IExtensionHost, extensionHost: IExtensionHost,
@ -65,6 +66,7 @@ export class ExtensionHostManager extends Disposable {
this.onDidExit = this._extensionHost.onExit; this.onDidExit = this._extensionHost.onExit;
this._proxy = this._extensionHost.start()!.then( this._proxy = this._extensionHost.start()!.then(
(protocol) => { (protocol) => {
this._hasStarted = true;
return { value: this._createExtensionHostCustomers(protocol) }; return { value: this._createExtensionHostCustomers(protocol) };
}, },
(err) => { (err) => {
@ -217,14 +219,18 @@ export class ExtensionHostManager extends Disposable {
return proxy.$activate(extension, reason); return proxy.$activate(extension, reason);
} }
public activateByEvent(activationEvent: string): Promise<void> { public activateByEvent(activationEvent: string, eager?: boolean): Promise<void> {
if (eager && !this._hasStarted) {
return Promise.resolve();
}
if (!this._cachedActivationEvents.has(activationEvent)) { if (!this._cachedActivationEvents.has(activationEvent)) {
this._cachedActivationEvents.set(activationEvent, this._activateByEvent(activationEvent)); this._cachedActivationEvents.set(activationEvent, this._activateByEvent(activationEvent, eager));
} }
return this._cachedActivationEvents.get(activationEvent)!; return this._cachedActivationEvents.get(activationEvent)!;
} }
private async _activateByEvent(activationEvent: string): Promise<void> { private async _activateByEvent(activationEvent: string, eager?: boolean): Promise<void> {
if (!this._proxy) { if (!this._proxy) {
return; return;
} }
@ -234,7 +240,7 @@ export class ExtensionHostManager extends Disposable {
// i.e. the extension host could not be started // i.e. the extension host could not be started
return; return;
} }
return proxy.value.$activateByEvent(activationEvent); return proxy.value.$activateByEvent(activationEvent, eager);
} }
public async getInspectPort(tryEnableInspector: boolean): Promise<number> { public async getInspectPort(tryEnableInspector: boolean): Promise<number> {

View file

@ -177,8 +177,13 @@ export interface IExtensionService {
/** /**
* Send an activation event and activate interested extensions. * Send an activation event and activate interested extensions.
*
* Normally, this will queue the activation event if the extension hosts are not ready
* and send it to all of them. If the extension needs to be activated before this,
* the eager flag can be used to ignore extension hosts that aren't yet started. Do not
* use this flag unless necessary.
*/ */
activateByEvent(activationEvent: string): Promise<void>; activateByEvent(activationEvent: string, eager?: boolean): Promise<void>;
/** /**
* An promise that resolves when the installed extensions are registered after * An promise that resolves when the installed extensions are registered after