1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix race condition on tab start

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-11-08 15:49:35 -05:00
parent 7d430b57ad
commit 09acd0206c
2 changed files with 15 additions and 18 deletions

View File

@ -58,15 +58,8 @@ export class TerminalApi extends WebSocketApi {
public onReady = new EventEmitter<[]>();
@observable public isReady = false;
public readonly url: string;
public static async new(options: TerminalApiQuery): Promise<TerminalApi> {
const shellToken = await ipcRenderer.invoke("cluster:shell-api", getHostedClusterId(), options.id);
return new TerminalApi({ ...options, shellToken });
}
private constructor(query: TerminalApiQuery) {
constructor(protected query: TerminalApiQuery) {
super({
logging: isDevelopment,
flushOnOpen: false,
@ -74,26 +67,30 @@ export class TerminalApi extends WebSocketApi {
});
makeObservable(this);
const { hostname, protocol, port } = location;
if (query.node) {
query.type ||= "node";
}
}
this.url = url.format({
async connect() {
this.emitStatus("Connecting ...");
const shellToken = await ipcRenderer.invoke("cluster:shell-api", getHostedClusterId(), this.query.id);
const { hostname, protocol, port } = location;
const socketUrl = url.format({
protocol: protocol.includes("https") ? "wss" : "ws",
hostname,
port,
pathname: "/api",
query,
query: {
...this.query,
shellToken,
},
slashes: true,
});
}
connect() {
this.emitStatus("Connecting ...");
this.onData.addListener(this._onReady, { prepend: true });
super.connect(this.url);
super.connect(socketUrl);
}
destroy() {

View File

@ -65,12 +65,12 @@ export class TerminalStore extends Singleton {
});
}
async connect(tabId: TabId) {
connect(tabId: TabId) {
if (this.isConnected(tabId)) {
return;
}
const tab: ITerminalTab = dockStore.getTabById(tabId);
const api = await TerminalApi.new({
const api = new TerminalApi({
id: tabId,
node: tab.node,
});