Skip to content

Commit 42ecf1f

Browse files
committed
Recreate public API when gitpod host is changed
1 parent 5a52606 commit 42ecf1f

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/publicApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class GitpodPublicApi extends Disposable {
4444
private _onWorkspaceStatusUpdate = this._register(new vscode.EventEmitter<WorkspaceStatus>);
4545
public readonly onWorkspaceStatusUpdate = this._onWorkspaceStatusUpdate.event;
4646

47-
constructor(accessToken: string, gitpodHost: string, private logger: vscode.LogOutputChannel) {
47+
constructor(accessToken: string, readonly gitpodHost: string, private logger: vscode.LogOutputChannel) {
4848
super();
4949

5050
const serviceUrl = new URL(gitpodHost);

src/remoteConnector.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,16 @@ export default class RemoteConnector extends Disposable {
158158
}
159159

160160
private async initPublicApi(session: vscode.AuthenticationSession, gitpodHost: string) {
161-
if (this.publicApi) {
161+
if (this.publicApi?.gitpodHost === gitpodHost) {
162162
return;
163163
}
164164

165+
this.publicApi?.dispose();
166+
this.publicApi = undefined;
167+
165168
const usePublicApi = await this.experiments.getRaw<boolean>('gitpod_experimental_publicApi', session.account.id, { gitpodHost });
166169
this.logger.info(`Going to use ${usePublicApi ? 'public' : 'server'} API`);
167-
if (usePublicApi) {
168-
this.publicApi = this._register(new GitpodPublicApi(session.accessToken, gitpodHost, this.logger));
169-
}
170+
this.publicApi = new GitpodPublicApi(session.accessToken, gitpodHost, this.logger);
170171
}
171172

172173
private releaseStaleLocks(): void {
@@ -1118,8 +1119,9 @@ export default class RemoteConnector extends Disposable {
11181119
}
11191120

11201121
public override async dispose(): Promise<void> {
1121-
await this.heartbeatManager?.dispose();
1122+
this.publicApi?.dispose();
11221123
this.workspaceState?.dispose();
1124+
await this.heartbeatManager?.dispose();
11231125
super.dispose();
11241126
}
11251127
}

src/workspaceState.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,4 @@ export class WorkspaceState extends Disposable {
5757
this._onWorkspaceStatusChanged.fire();
5858
}
5959
}
60-
61-
public override async dispose(): Promise<void> {
62-
super.dispose();
63-
}
64-
6560
}

0 commit comments

Comments
 (0)