Add per-VM autostart checkbox (single-select, persisted)

Only one VM can be marked for autostart at a time — checking a new
one unchecks the previous. Matched by host+vmid since the same vmid
can exist on multiple standalone Proxmox hosts in a cluster setup.
This commit is contained in:
2026-07-06 13:43:38 +02:00
parent 5c4e3781fd
commit 7fbac7c18a
5 changed files with 75 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "proxmox-spice-client",
"version": "1.0.3",
"version": "1.0.4",
"description": "VDI SPICE Client f\u00fcr Proxmox",
"main": "src/main.js",
"scripts": {
+9
View File
@@ -229,6 +229,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) {
+2
View File
@@ -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),
},
});
+14
View File
@@ -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
View File
@@ -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 &nbsp;·&nbsp; ${multiHost ? `Host: ${esc(vm.host)} &nbsp;·&nbsp; ` : ''}Node: ${esc(vm.node)} &nbsp;·&nbsp; 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');
}