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:
parent
7d430b57ad
commit
09acd0206c
@ -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() {
|
||||
|
||||
@ -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,
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user