Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0968468978 | ||
|
|
7fbac7c18a | ||
|
|
5c4e3781fd |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "proxmox-spice-client",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.5",
|
||||
"description": "VDI SPICE Client f\u00fcr Proxmox",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
||||
+33
-1
@@ -153,7 +153,30 @@ ipcMain.handle('proxmox:login', async (_e, { host, username, password }) => {
|
||||
return { success: false, error: attempts[0].error };
|
||||
}
|
||||
|
||||
clients = succeeded;
|
||||
// Several hostnames can point at nodes of the SAME real Proxmox cluster
|
||||
// (e.g. Stefan's setup) — in that case /cluster/resources returns the
|
||||
// identical cluster-wide VM list from every one of them, so keeping all
|
||||
// logged-in clients would just show each VM 3x. Detect real cluster
|
||||
// membership and keep only one representative client per cluster.
|
||||
const seenGroups = new Set();
|
||||
const dedupedClients = [];
|
||||
await Promise.all(
|
||||
succeeded.map(async (entry) => {
|
||||
try {
|
||||
entry.clusterId = await entry.client.getClusterId();
|
||||
} catch {
|
||||
entry.clusterId = null;
|
||||
}
|
||||
})
|
||||
);
|
||||
for (const entry of succeeded) {
|
||||
const group = entry.clusterId || `standalone:${entry.host}`;
|
||||
if (seenGroups.has(group)) continue;
|
||||
seenGroups.add(group);
|
||||
dedupedClients.push(entry);
|
||||
}
|
||||
|
||||
clients = dedupedClients;
|
||||
createWindow('vms.html', 680, 520, true);
|
||||
|
||||
if (failed.length > 0) {
|
||||
@@ -229,6 +252,15 @@ ipcMain.handle('settings:browseViewerPath', async () => {
|
||||
return chosen;
|
||||
});
|
||||
|
||||
// Only one VM can be marked for autostart at a time — identified by
|
||||
// host+vmid since the same vmid can exist on several hosts.
|
||||
ipcMain.handle('settings:getAutoConnect', () => store.get('autoConnect', null));
|
||||
|
||||
ipcMain.handle('settings:setAutoConnect', (_e, target) => {
|
||||
if (target) store.set('autoConnect', target);
|
||||
else store.delete('autoConnect');
|
||||
});
|
||||
|
||||
// ---------- SPICE helpers ----------
|
||||
|
||||
function buildVVFile(params, vmid, client) {
|
||||
|
||||
@@ -17,5 +17,7 @@ contextBridge.exposeInMainWorld('api', {
|
||||
getViewerPath: () => ipcRenderer.invoke('settings:getViewerPath'),
|
||||
browseViewerPath: () => ipcRenderer.invoke('settings:browseViewerPath'),
|
||||
clearViewerPath: () => ipcRenderer.invoke('settings:clearViewerPath'),
|
||||
getAutoConnect: () => ipcRenderer.invoke('settings:getAutoConnect'),
|
||||
setAutoConnect: (target) => ipcRenderer.invoke('settings:setAutoConnect', target),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -121,6 +121,16 @@ class ProxmoxClient {
|
||||
return vga.startsWith('qxl') || vga === 'virtio-vga-gl';
|
||||
}
|
||||
|
||||
// Real Proxmox clusters: every member node returns the identical
|
||||
// cluster-wide resource list, so logging into several nodes of the same
|
||||
// cluster would just duplicate every VM. Returns the cluster's name, or
|
||||
// null if this host isn't part of a cluster (standalone).
|
||||
async getClusterId() {
|
||||
const status = await this.request('GET', '/cluster/status');
|
||||
const cluster = (status || []).find((s) => s.type === 'cluster');
|
||||
return cluster ? cluster.name || cluster.id || null : null;
|
||||
}
|
||||
|
||||
async getSpiceTicket(node, vmid) {
|
||||
// proxy = address clients should connect to for SPICE traffic
|
||||
const proxy = this.host.split(':')[0];
|
||||
|
||||
@@ -250,6 +250,20 @@ body.vms-page {
|
||||
|
||||
.vm-info { flex: 1; min-width: 0; }
|
||||
|
||||
.vm-autostart {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.vm-autostart input { cursor: pointer; }
|
||||
|
||||
.vm-name {
|
||||
font-size: 0.97rem;
|
||||
font-weight: 600;
|
||||
|
||||
+49
-6
@@ -83,20 +83,37 @@ async function loadVMs() {
|
||||
return;
|
||||
}
|
||||
|
||||
renderList(vms);
|
||||
// Auto-connect the VM the user marked for autostart (only one at a time)
|
||||
const autoConnect = await api.settings.getAutoConnect();
|
||||
const autoMatch = autoConnect && vms.find(
|
||||
(vm) => vm.host === autoConnect.host && String(vm.vmid) === String(autoConnect.vmid)
|
||||
);
|
||||
|
||||
if (autoMatch) {
|
||||
showNotice(`Autostart-VM „${autoMatch.name}" markiert — verbinde …`);
|
||||
await connectVM(autoMatch);
|
||||
return;
|
||||
}
|
||||
|
||||
renderList(vms, autoConnect);
|
||||
}
|
||||
|
||||
loadVMs();
|
||||
|
||||
// ── Render ────────────────────────────────────────────────
|
||||
|
||||
function renderList(vms) {
|
||||
function renderList(vms, autoConnect) {
|
||||
// Only show the host when there's more than one — single-host setups don't need the noise.
|
||||
const multiHost = new Set(vms.map((vm) => vm.host)).size > 1;
|
||||
|
||||
listEl.innerHTML = vms
|
||||
.map(
|
||||
(vm) => `
|
||||
.map((vm) => {
|
||||
const isAutostart = !!(
|
||||
autoConnect &&
|
||||
autoConnect.host === vm.host &&
|
||||
String(autoConnect.vmid) === String(vm.vmid)
|
||||
);
|
||||
return `
|
||||
<div class="vm-card" data-vmid="${vm.vmid}">
|
||||
<div class="vm-info">
|
||||
<div class="vm-name">${esc(vm.name)}</div>
|
||||
@@ -105,6 +122,17 @@ function renderList(vms) {
|
||||
Läuft · ${multiHost ? `Host: ${esc(vm.host)} · ` : ''}Node: ${esc(vm.node)} · ID: ${vm.vmid}
|
||||
</div>
|
||||
</div>
|
||||
<label class="vm-autostart" title="Beim Start automatisch mit dieser VM verbinden">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="autostart-checkbox"
|
||||
data-vmid="${vm.vmid}"
|
||||
data-host="${esc(vm.host)}"
|
||||
data-name="${esc(vm.name)}"
|
||||
${isAutostart ? 'checked' : ''}
|
||||
>
|
||||
Autostart
|
||||
</label>
|
||||
<button
|
||||
class="btn-connect"
|
||||
data-vmid="${vm.vmid}"
|
||||
@@ -113,8 +141,8 @@ function renderList(vms) {
|
||||
data-name="${esc(vm.name)}"
|
||||
>Verbinden</button>
|
||||
</div>
|
||||
`
|
||||
)
|
||||
`;
|
||||
})
|
||||
.join('');
|
||||
|
||||
listEl.querySelectorAll('.btn-connect').forEach((btn) => {
|
||||
@@ -128,6 +156,21 @@ function renderList(vms) {
|
||||
);
|
||||
});
|
||||
|
||||
listEl.querySelectorAll('.autostart-checkbox').forEach((cb) => {
|
||||
cb.addEventListener('change', async () => {
|
||||
if (cb.checked) {
|
||||
// Only one VM can be the autostart VM — uncheck any other.
|
||||
listEl.querySelectorAll('.autostart-checkbox').forEach((other) => {
|
||||
if (other !== cb) other.checked = false;
|
||||
});
|
||||
await api.settings.setAutoConnect({ host: cb.dataset.host, vmid: cb.dataset.vmid });
|
||||
showNotice(`„${cb.dataset.name}" wird beim nächsten Start automatisch verbunden.`);
|
||||
} else {
|
||||
await api.settings.setAutoConnect(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
listEl.classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user