-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxmoxStandaloneConsoleView.tsx
More file actions
148 lines (139 loc) · 4.85 KB
/
Copy pathProxmoxStandaloneConsoleView.tsx
File metadata and controls
148 lines (139 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { Suspense, lazy, useEffect, useState } from "react";
import { InlineSpinner } from "./InlineSpinner";
import { PROXMUX_PLUGIN_ID } from "../features/builtin-plugin-ids";
import type { ProxmoxStandalonePayload } from "../features/proxmox-standalone-payload";
import { connectTimeoutMs } from "../features/connect-timeouts";
import { getAppPreferences, pluginInvoke } from "../tauri-api";
const ProxmoxQemuVncPane = lazy(async () => {
const m = await import("./ProxmoxQemuVncPane");
return { default: m.ProxmoxQemuVncPane };
});
const ProxmoxLxcTermPane = lazy(async () => {
const m = await import("./ProxmoxLxcTermPane");
return { default: m.ProxmoxLxcTermPane };
});
const ProxmoxNodeTermPane = lazy(async () => {
const m = await import("./ProxmoxNodeTermPane");
return { default: m.ProxmoxNodeTermPane };
});
type ClusterTls = {
allowInsecureTls: boolean;
tlsTrustedCertPem: string | undefined;
};
async function fetchClusterTls(clusterId: string): Promise<ClusterTls> {
const raw = await pluginInvoke(PROXMUX_PLUGIN_ID, "listState", {});
const clusters = (raw as { clusters?: Array<{ id: string; allowInsecureTls?: boolean; tlsTrustedCertPem?: string | null }> })
.clusters;
const c = Array.isArray(clusters) ? clusters.find((x) => x.id === clusterId) : undefined;
const pem = typeof c?.tlsTrustedCertPem === "string" ? c.tlsTrustedCertPem.trim() : "";
return {
allowInsecureTls: c?.allowInsecureTls === true,
tlsTrustedCertPem: pem.length > 0 ? pem : undefined,
};
}
type Props = {
payload: ProxmoxStandalonePayload;
};
export function ProxmoxStandaloneConsoleView({ payload }: Props) {
const [tls, setTls] = useState<ClusterTls | null>(null);
const [wsConnectTimeoutMs, setWsConnectTimeoutMs] = useState(() => connectTimeoutMs(null));
const [error, setError] = useState("");
useEffect(() => {
let cancelled = false;
void (async () => {
try {
const [t, prefs] = await Promise.all([fetchClusterTls(payload.clusterId), getAppPreferences().catch(() => null)]);
if (!cancelled) {
setTls(t);
if (prefs) {
setWsConnectTimeoutMs(connectTimeoutMs(prefs));
}
}
} catch (e) {
if (!cancelled) {
setError(String(e));
}
}
})();
return () => {
cancelled = true;
};
}, [payload.clusterId]);
if (error) {
return (
<div className="proxmox-standalone-console terminal-root terminal-host" role="alert">
<p className="error-text">{error}</p>
</div>
);
}
if (!tls) {
return (
<div
className="proxmox-standalone-console terminal-root terminal-host terminal-suspense-fallback"
role="status"
aria-busy="true"
aria-label="Preparing console"
>
<InlineSpinner label="Preparing console" />
<span className="muted-copy">Preparing console…</span>
</div>
);
}
const commonTls = {
allowInsecureTls: tls.allowInsecureTls,
...(tls.tlsTrustedCertPem ? { tlsTrustedCertPem: tls.tlsTrustedCertPem } : {}),
};
return (
<div className="proxmox-standalone-console terminal-root terminal-host" role="region" aria-label={payload.paneTitle}>
<div className="proxmox-standalone-console-chrome">
<span className="proxmox-standalone-console-title">{payload.paneTitle}</span>
</div>
<div className="proxmox-standalone-console-body">
<Suspense
fallback={
<div
className="terminal-root terminal-host terminal-suspense-fallback"
role="status"
aria-busy="true"
aria-label="Loading console"
>
<InlineSpinner label="Loading console" />
<span className="muted-copy">Loading…</span>
</div>
}
>
{payload.kind === "qemu-vnc" ? (
<ProxmoxQemuVncPane
clusterId={payload.clusterId}
node={payload.node}
vmid={payload.vmid}
paneTitle={payload.paneTitle}
reconnectRequestNonce={0}
connectTimeoutMs={wsConnectTimeoutMs}
{...commonTls}
/>
) : payload.kind === "lxc-term" ? (
<ProxmoxLxcTermPane
clusterId={payload.clusterId}
node={payload.node}
vmid={payload.vmid}
paneTitle={payload.paneTitle}
reconnectRequestNonce={0}
connectTimeoutMs={wsConnectTimeoutMs}
{...commonTls}
/>
) : (
<ProxmoxNodeTermPane
clusterId={payload.clusterId}
node={payload.node}
paneTitle={payload.paneTitle}
reconnectRequestNonce={0}
connectTimeoutMs={wsConnectTimeoutMs}
{...commonTls}
/>
)}
</Suspense>
</div>
</div>
);
}